[CMake] Optionally selecting projects
Mike Talbot
mtalbot at abingdon.oilfield.slb.com
Wed Jul 11 09:40:15 EDT 2007
Alexander Neundorf wrote:
> 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).
>
Tried that but it makes no difference (as described in the manual,
INTERNAL variables are always written to the cache). After a bit more
poking, it seems the problem is that I reset the variables in the
top-level CMakeLists.txt, which means the lower-level CMakeLists.txt
files' changes are not visible in the other CMakeLists.txt files. I
thought cache variables were global, but there seems to be some scoping
going on, f.e.
Top-level CMakeLists.txt:
SET(FOO OFF CACHE INTERNAL "")
ADD_SUBDIRECTORY(DirA)
ADD_SUBDIRECTORY(DirB)
In both DirA & DirB:
MESSAGE("FOO = ${FOO}")
SET(FOO ON CACHE INTERNAL "")
When I run cmake on this I get:
FOO = OFF (from DirA)
FOO = OFF (from DirB)
but the CMakeCache.txt after this has FOO=ON.
If I remove the top-level SET(FOO OFF...) command, then I get the
(expected) output:
FOO = ON (from DirA)
FOO = ON (from DirB)
this is irrespective of what FOO is set to in the cache at the start.
--
Mike Talbot
Core Petrel Architect (Abingdon)
Schlumberger
Lambourn Court, Wyndyke Furlong,
Abingdon Business Park, Abingdon,
Oxfordshire, OX14 1UJ, UK
Office: +44 (0)1235 543 488
Mobile: +44 (0)7790 382 746
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070711/9f80dd2d/attachment.html
More information about the CMake
mailing list