[CMake] Delay Cache File Reading
Petr Kmoch
petr.kmoch at gmail.com
Mon May 12 02:55:28 EDT 2014
Hi Ryan.
If the only thing you need delay-loaded in this are the target names, you
should just get rid of the variables and use the target names directly. The
decision whether an argument of `target_link_libraries()` is a target or a
library path is done at generate time, when all CMakeLists have been parsed
and all target names are known.
However, if your example is just simplified and you need more than the name
itself for linking (e.g. if you need to dereference a differnt variable set
in the target's CMakeList, or get/set that tartget's properties), then I'm
afraid you're out of luck in the general case. I was facing a similar setup
at work: hundreds of projects randomly referencing each other, where trying
to find an ordering of subdirectory inclusion just wasn't practically
possible. In the end, I did something similar to your "master file"
approach, but a bit more modular. I require each project to have a
"project.cmake" file alongside its "CMakeLists.txt". The "project.cmake"
file sets all the variables required by other projects. My master CMakeList
then include()-s all these "project.cmake" files before executing any
`add_subdirectory()` calls, so that all the variables are already set
correctly when subprojects are processed.
If someone has a better way to do it, I'd love to hear it as well.
Petr
On Fri, May 9, 2014 at 8:21 PM, Kawicki, Ryan H
<Ryan.H.Kawicki at boeing.com>wrote:
> 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
>
> --
>
> 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://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140512/e75067dc/attachment.html>
More information about the CMake
mailing list