[CMake] Delay Cache File Reading

Kawicki, Ryan H Ryan.H.Kawicki at boeing.com
Fri May 9 14:21:01 EDT 2014


I wonder if anyone else has come into this kind of situation.

We are restructuring how some of our libraries are structured on disk to be more modular.

Previously, we had all of the project names defined in a CMakeList.txt that then would call to add the subdirectories that are needed.  This works fine, but with the new structure, we would like to eliminate the need for this master file and just have the subdirectories define the name itself.

The thing I was thinking of doing was just adding them to the cache file, but order may be important here.

Here is a very simple example:

Master CMakeList:
cmake_minimum_required(VERSION 2.8)
project(test)
add_subdirectory(lib2)
add_subdirectory(lib)
add_subdirectory(exe)

lib2 CMakeList:
cmake_minimum_required(VERSION 2.8)
SET(PROJECT_LIB2              lib2                   CACHE INTERNAL "lib2 project name")
add_library(${PROJECT_LIB2} SHARED file.cpp)
target_link_libraries(${PROJECT_LIB2} ${PROJECT_LIB})

lib CMakeList:
cmake_minimum_required(VERSION 2.8)
SET(PROJECT_LIB              lib                   CACHE INTERNAL "lib project name")
add_library(${PROJECT_LIB} STATIC file.cpp)

exe CMakeList:
cmake_minimum_required(VERSION 2.8)
SET(PROJECT_EXE              exe                   CACHE INTERNAL "exe project name")
add_executable(${PROJECT_EXE} file.cpp)
target_link_libraries(${PROJECT_EXE} ${PROJECT_LIB2})

In this simple example, lib is never seen by lib2 and added as a dependant because the cache entry has not yet been evaluated.

I thought that there was first a configuration step to acquire all variables of and stuff them into the cache file and then the generation step would use these values to generate the file output, but that is not happening as can be seen in the example above.  I am using CMake 2.8.11.1 when conducting this test and generating a VS2010 project.

During our restructuring efforts, we are making a full attempt at trying to not have these kind of situations come up, but we live in the real world and not an ideal world.  Outside of using the -C option or restructuring again, is there anything I can do to accomplish what I am trying to do?  Is there a mechanism to delay reading from the cache until the configuration step has finished?

Thanks.

Ryan H. Kawicki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140509/b8f984a6/attachment.html>


More information about the CMake mailing list