From: Alan W. Irwin <irwin@be...> - 2006-07-13 02:16:07
Here is a CMake issue I just ran into. Scope of variables flows down from
higher-level to lower-level directories (I think) that are processed with
the add_subdirectory command. In any case, every variable set in the
top-level CMakeLists.txt file (NOTE that also means every variable set by
"include(plplot)") is available in project subdirectories, but you cannot
communicate variable values between subdirectories or back to the top-level
directory. The one exception is if you use the CACHE property in set
commands, but let's immediately set a code standard now that we don't do
that! The problem with such an approach is that CACHEd results are not
available until the next cmake run, and that is bound to drive everybody
crazy with "now you see it, now you don't" variable results.
The specific problem I was trying to address was to communicate to
pkgcfg/CMakeLists.txt the results of library linking flag and compile flag
information, but it just cannot be done. Instead, you have to configure the
pkgcfg/plplot*.pc files right from the subdirectory where the library was
created. That's not a bad alternative, and in fact that locality of
reference where the configuration of the appropriate *.pc file occurs right
at the creation of the library makes the CMake code easier to understand.
Anyhow, this scope issue is something you should be aware of if you were
incorrectly assuming all CMake variables have global scope (like I was).
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project