Re: [CMake] CMakeLists.txt in different place than source
On Wed, Jun 13, 2018 at 9:46 PM Andrew White wrote: > J Decker wrote: > > You can define a variable to define the base of the sources > > set( SOURCE_ROOT /some/path ) > > > > could be set relative to the current cmake path per cmake that uses those > > souces... and then just prefix it > > > > add_library(my_lib > > ${SOURCE_ROOT}/src/a.c > > ${SOURCE_ROOT}/include/a.h > > ) > > > > Thanks, but that’s approximately exactly what I’m trying to avoid doing. > I cheat a little, in that I have a macro that will prepend a prefix to > every element of a list. My motivation is avoiding situations where I add > the prefix to the files but forget to add the prefix when I call > target_include_directories or suchlike. > > > > I’m not sure anything trickier is workable in the CMake model, however. > For example, hacking CMAKE_CURRENT_SOURCE_DIR might make sense for file > paths, but if I then call add_subdirectory should it be rooted at the > CMakeList directory or the source root directory. > > > CMAKE_CURRENT_LIST_DIR https://stackoverflow.com/questions/15662497/difference-between-cmake-current-source-dir-and-cmake-current-list-dir yes that's an option also. It will be pretty clear there's an error if something is omitted later; and/or referenced from a different place. and then it's not just a matter of > -- > > Andrew > > > -- > > 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: > https://cmake.org/mailman/listinfo/cmake > -- 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: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] CMakeLists.txt in different place than source
J Decker wrote: You can define a variable to define the base of the sources set( SOURCE_ROOT /some/path ) could be set relative to the current cmake path per cmake that uses those souces... and then just prefix it add_library(my_lib ${SOURCE_ROOT}/src/a.c ${SOURCE_ROOT}/include/a.h ) Thanks, but that’s approximately exactly what I’m trying to avoid doing. I cheat a little, in that I have a macro that will prepend a prefix to every element of a list. My motivation is avoiding situations where I add the prefix to the files but forget to add the prefix when I call target_include_directories or suchlike. I’m not sure anything trickier is workable in the CMake model, however. For example, hacking CMAKE_CURRENT_SOURCE_DIR might make sense for file paths, but if I then call add_subdirectory should it be rooted at the CMakeList directory or the source root directory. -- Andrew -- 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: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] CMakeLists.txt in different place than source
On Tue, Jun 12, 2018 at 7:22 PM Andrew White wrote: > I have a situation where I want my CMakeLists.txt in a different place > than my source. > > e.g.: > > /some/path/project/CMakeLists.txt > /other/path/source/src/a.c > /other/path/source/include/a.h > > Is there an easy way to say "process this CMakeLists.txt as if it were in > /other/path/source" (at least as far as file paths are concerned)? > > e.g.: > > add_library(my_lib > src/a.c > include/a.h > ) > > target_include_directories(my_lib PUBLIC include) > > I know I can add a full path prefix to every file, but there are a lot of > them. I'm hoping for a shortcut. > You can define a variable to define the base of the sources set( SOURCE_ROOT /some/path ) could be set relative to the current cmake path per cmake that uses those souces... and then just prefix it add_library(my_lib ${SOURCE_ROOT}/src/a.c ${SOURCE_ROOT}/include/a.h ) > > -- > Andrew > > > -- > > 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: > https://cmake.org/mailman/listinfo/cmake > -- 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: https://cmake.org/mailman/listinfo/cmake
[CMake] CMakeLists.txt in different place than source
I have a situation where I want my CMakeLists.txt in a different place than my source. e.g.: /some/path/project/CMakeLists.txt /other/path/source/src/a.c /other/path/source/include/a.h Is there an easy way to say "process this CMakeLists.txt as if it were in /other/path/source" (at least as far as file paths are concerned)? e.g.: add_library(my_lib src/a.c include/a.h ) target_include_directories(my_lib PUBLIC include) I know I can add a full path prefix to every file, but there are a lot of them. I'm hoping for a shortcut. -- Andrew -- 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: https://cmake.org/mailman/listinfo/cmake