I have a cmake project in which I have several modules and I use Find - *. cmake to include common modules in the application. In order to ignore every module that is added, I have defined global LIB variables for the linker:
so in one of the final applications, which uses some modules, I can simply do:
target_link_libraries(${APP_NAME} ${LIB})
Then I would like to have compiled modules in /project_path/modules/foo/build , so if the module is really big to compile, it can be compiled once for all applications that use it. The way I achieve this is to load the CMakeLists.txt module from Find - *. Cmake as follows:
# Inside FindFoo.cmake, for loading /project_path/modules/foo/CMakeLists.txt # and compile it in /project_path/modules/foo/build add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../modules/${PACKAGE_NAME} ${CMAKE_CURRENT_LIST_DIR}/../modules/${PACKAGE_NAME}/build ) include_directories(${CMAKE_CURRENT_LIST_DIR}/../modules/${PACKAGE_NAME}/include)
But sometimes it happened that for some module other modules are required, so add_subdirectory creates new add_subdirectory and can load the LIB correctly, but cannot write it (when I use set , it is in a deeper region and does not change the upper region). To work around this I have to add PARENT_SCOPE to set ). Therefore, I tried to add it to some module, which, I think, may be nested and hidden in some dependencies, but I suddenly ran into compiling the entire application:
CMake Warning (dev) at /path_to_repo/cmake/FindFooX.cmake:6 (set): Cannot set "LIB": current scope has no parent. Call Stack (most recent call first): CMakeLists.txt:14 (find_package) This warning is for project developers. Use -Wno-dev to suppress it.
I am afraid that this may change from application to application in terms of which module I need, or in relation to the dependency tree in the modules themselves, so I am looking for a cleaner solution.
scope global-variables dependencies cmake
nkint Oct 13 '13 at 13:46 on 2013-10-13 13:46
source share