[CMake] Variable scope question

Alexander Neundorf a.neundorf-work at gmx.net
Wed Mar 11 15:48:45 EDT 2009


On Wednesday 11 March 2009, Marcel Loose wrote:
> 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?

You could also use 
set/get_property(GLOBAL ...)

Alex


More information about the CMake mailing list