[CMake] Optionally selecting projects

Mike Talbot mtalbot at abingdon.oilfield.slb.com
Wed Jul 11 06:01:30 EDT 2007


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).

Any ideas on how to solve this or a better approach?

Thanks
Mike

-- 
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



More information about the CMake mailing list