On Sat, Jul 18, 2015 at 1:49 PM, Clifford Yapp <cliffy...@gmail.com> wrote: > On Sat, Jul 18, 2015 at 5:30 AM, Florent Castelli > <florent.caste...@gmail.com> wrote: >> I've used that once and you end up with the relative path to the sources >> from the CMakeLists.txt. >> If you're in another CMakeLists.txt, then you can't use the paths directly. >> I tried a few properties but I couldn't find any property to get the folder >> where the target was defined. >> >> How do you get the full path? > > That's a very good point - using the command override approach, the > CMAKE_CURRENT_SOURCE_DIR is always the directory of the target in > question, and looking at our current code I see we do make use of that > assumption. We would need a way to find out what > CMAKE_CURRENT_SOURCE_DIR was when the target was defined if we're > going to build up a list after the fact - maybe something like > get_target_property(TDIR <targetname> SOURCE_DIR) to get the source > directory in which the target was defined. In combination with the > SOURCES property it would allow for full path reconstruction. > > CY
A quick experiment suggests that this will work for associating and exposing a source directory with each target - not sure if this dots all the i's an crosses all the t's though: diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 2b73e6f..c9281b7 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2945,6 +2945,7 @@ const char *cmTarget::GetProperty(const std::string& prop, MAKE_STATIC_PROP(COMPILE_DEFINITIONS); MAKE_STATIC_PROP(IMPORTED); MAKE_STATIC_PROP(NAME); + MAKE_STATIC_PROP(SOURCE_DIR); MAKE_STATIC_PROP(SOURCES); #undef MAKE_STATIC_PROP if(specialProps.empty()) @@ -2957,6 +2958,7 @@ const char *cmTarget::GetProperty(const std::string& prop, specialProps.insert(propCOMPILE_DEFINITIONS); specialProps.insert(propIMPORTED); specialProps.insert(propNAME); + specialProps.insert(propSOURCE_DIR); specialProps.insert(propSOURCES); } if(specialProps.count(prop)) @@ -3039,6 +3041,10 @@ const char *cmTarget::GetProperty(const std::string& prop, { return this->GetName().c_str(); } + else if (prop == propSOURCE_DIR) + { + return this->GetMakefile()->GetCurrentSourceDirectory(); + } else if(prop == propSOURCES) { if (this->Internal->SourceEntries.empty()) -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers