[Cmake] Compiling the same source file with different Compiler flags

Brad King brad.king at kitware.com
Fri Jun 4 08:59:21 EDT 2004


Karelitz, David B wrote:

> Hi,
> 
> I'm trying to write a CMakeLists.txt file that compiles the same source 
> file twice with different compiler flags and then makes 2 libraries, 
> each with a different version of the compiled source.
> 
> So if the source is foo.c, I would like to compile foo.c using -DBAR in 
> one library and using -DNOBAR in another library.

You can create two extra source files:

//foo_bar.c
#define BAR
#include "foo.c"

//foo_nobar.c
#define NOBAR
#include "foo.c"

Then add these two files to the two different libraries.

-Brad



More information about the Cmake mailing list