[CMake] Optionally selecting projects

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jul 11 09:01:40 EDT 2007


On Wednesday 11 July 2007 06:01, Mike Talbot wrote:
> Hi,
>
> I'm working on quite a large baseline (>100 projects) that uses cmake
> and am trying to find a way to allow users to select only a subset of
> projects to include in the generated solution/makefile.  I'd like users
> to be able to specify one or more projects that they are working on and
> for these projects and all dependent projects to be included in the
> solution.
>
> Assuming the user has set the cmake variable MY_PROJECT to the project
> they are interested in, each project (called ${project}) has a
> CMakeLists.txt with something like this in:
>
> IF(MY_PROJECT STREQUAL ${project})
>   SET(${project}_SELECTED ON CACHE INTERNAL "Project selected")
> ENDIF(MY_PROJECT STREQUAL ${project})
>
> # ${project}_DEPENDS is a list of projects that ${project} depends on
> # ${project}_SOURCES is a list of source files for ${project}
>
> IF(${project}_SELECTED)
>   FOREACH(depend ${${project}_DEPENDS})
>     SET(${depend}_SELECTED ON CACHE INTERNAL "Dependent project selected")
>   ENDFOREACH(depend)
>
>   ADD_LIBRARY(${project} ${${project}_SOURCES})
>   TARGET_LINK_LIBRARIES(${project} ${${project}_DEPENDS})
> ENDIF(${project}_SELECTED)
>
> This assumes the project CMakeLists.txt are traversed topologically and
> works fine the first time cmake is run.  However on subsequent runs
> (even if I reset all the ${project}_SELECTED variables to false at the
> top-level CMakeLists.txt) the value of the ${project}_SELECTED variables
> are no longer visible outside the CMakeLists.txt file where they are set
> (but they were the first time).

I think SET(... CACHE) has no effect if the variable is already in the cache. 
Then you have to use SET(... CACHE FORCE).

Alex


More information about the CMake mailing list