[Cmake] Defining a variable for the compiler in one directory only

Karr, David David . Karr at titan . com
Mon, 22 Sep 2003 10:59:59 -0400


> From: Andy Cedilnik [mailto:andy . cedilnik at kitware . com]
>=20
> First of all, you can do what you want by setting source file property
> for each source file:
>=20
> SET(foo_sources foo1.c ...)
> SET_SOURCE_FILES_PROPERTIES(${foo_sources} PROPERTIES COMPILE_FLAGS
> -DFOO)
>=20
> and then the same in bar.

Hmm, no luck.  But it could be I didn't define foo_sources correctly =
when
I tried this.

> That said, using -Dsomething is bad. Here is why:
> [...] The result is that everybody that uses your library will have to
> specify this flag.

I should perhaps have been more specific.  The directories I was working =
with
had existing source code (written by people who weren't using CMake), =
and
this source code used a preprocessor macro definition to indicate that =
certain
classes should be exported from foo.dll.  It's an error to export these =
classes=20
from any other project.  In other words, whoever uses the library must =
_not_=20
specify that flag.

Fortunately, I noticed that when CMake 1.6.7 creates the foo.dsp =
project, it=20
automatically defines a preprocessor macro, foo_EXPORTS.  This =
definition has
exactly the features I want (namely, by default CMake makes this =
definition=20
_only_ in the project where I want it), except that the macro is spelled =

differently than the macro that was used in the non-CMake-generated =
project. =20
To take advantage of foo_EXPORTS, then, I had to rewrite source code to =
use=20
the macro foo_EXPORTS instead of the old macro.

So the answer seems to be that the feature I want is in CMake, I just =
don't
have any control over how the defined macro will be spelled.  It would =
be nice
to have that extra bit of control, but at least I can compile and run my =
code.

David
=20