[CMake] Variable scope question

Marcel Loose loose at astron.nl
Wed Mar 11 12:34:42 EDT 2009


Hi all,

I'm struggling with the following. While processing the CMakeLists.txt
files of my project, I want to keep track of include directories and
libraries of "external" packages in say MYPROJECT_INCLUDE_DIRS and
MYPROJECT_LIBRARIES. These variables need to be augmented with new
values  while processing subdirectories of myproject (that were added
with add_subdirectory()). I wrote a small wrapper macro around
find_package() that updates these variables, which can be used in my
CMakeLists.txt files.

However, I noticed that in a subdirectory I can read the variable, but
changes don't get passed back, unless I use PARENT_SCOPE. This is a bit
cumbersome and error-prone, because you must set the variable with
PARENT_SCOPE at each level, even if you don't intend to modify its
contents! Is there a way to define "real" global variables, without
using the cache? 

Best regards,
Marcel Loose.




More information about the CMake mailing list