[Cmake] Defining a variable for the compiler in one directory only
Karr, David
David . Karr at titan . com
Fri, 19 Sep 2003 18:42:54 -0400
I want to generate projects in two directories like this:
foo/foo.dsp
foo/bar/bar.dsp
I want all files compiled by foo.dsp to be compiled with
the FOO variable defined, but *not* the BAR variable. =20
I want bar.dsp to compile files with the BAR variable=20
defined, but *not* the FOO variable.=20
What I did naively at first was to put the following
in foo/CMakeLists.txt:
ADD_DEFINITIONS(-DFOO)
And I put this in foo/bar/CMakeLists.txt:
ADD_DEFINITIONS(-DBAR)
This does exactly what I want in foo.dsp, but unfortunately
bar.dsp is compiling all its files with both FOO and BAR
defined, which causes runtime errors in my program.
I know that some CMake commands are "inherited" so that
if it appears in a CMakeLists.txt anywhere in the path
between the project root and your current directory, that
command executes; others execute only if they appear in
CMakeLists.txt in the current directory. Unsurprisingly
(and quite properly, thinking about how it would most
typically be used), ADD_DEFINITIONS seems to be "inherited."
My first request is for the CMake documentation to indicate
for each command whether it is inherited by subdirectories
or not.
The second, more urgent request is, what command(s) should
I best put in my CMakeLists.txt file(s) so that FOO will
be defined for the files compiled by foo.dsp and NOT
defined for the files compiled by bar.dsp?
-- David Karr