[CMake] Variable setting as a stack rather than as a blackboard?

Christian Convey christian.convey at gmail.com
Fri Mar 7 16:19:33 EST 2008


I have a problem:  In my multi-level source tree, I have some
subprojects.  All subprojects are built by CMake.

My problem is that sometimes a subproject (over which I have little
control) sets a variable for its own use, such as LIBRARY_OUTPUT_PATH.
 The problem is that the value gets cached, and then it hoses up other
subprojects that are descended into later in the cmake processing.

Has anyone considered extending CMake to permit variables to be
treated as if on a stack, similar to what OpenGL does with
transformation matrices?

I'm envisioning something like this:

subprojectA/CMakeLists.txt:
    push_var(EXECUTABLE_OUTPUT_PATH, "subprojectA-bin-directory")

    // popping vars is automatic when cmake leaves this cmakelists.txt file

subprojectB/CMakeLists.txt:
    push_var(EXECUTABLE_OUTPUT_PATH, "subprojectB-bin-directory")

subprojectC/CMakeLists.txt:
    // doesn't explicitly set EXECUTABLE_OUTPUT_PATH


toplevel/CMakeLists.txt
   set(EXECUTABLE_OUTPUT_PATH, project-default-bin-dir)
   add_subdirectory(subprojectA)
   add_subdirectory(subprojectB)
   add_subdirectory(subprojectC)

The idea here is that when CMake gets around to processing
subprojectC, subprojectC will start out with EXECUTABLE_OUTPUT_PATH
having a value of "project-default-bin-dir", rather than
"subprojectB-bin-directory".


More information about the CMake mailing list