[CMake] Fwd: Add definitions question

Brad King brad.king at kitware.com
Mon Jan 30 14:18:00 EST 2006


Rupert Brooks wrote:
> I have a source file which can be compiled into two possible
> executables depending on a compiler definition (Specifically, i get a
> 3D image processing executable if i set IMAGE_DIMENSION=3, and a 2D
> executable if IMAGE_DIMENSION=2)
> 
> I'm having some problems getting this in CMAKE.  ADD_DEFINITIONS does
> not seem to do what i want at all, and if i set the source file
> properties with SET_SOURCE_FILES_PROPERTIES, then only the final
> setting takes effect.  I'd prefer not to make two copies of the same
> file which only differ by a single define statement.  Is there a way
> to do what i want in CMAKE?

This feature was just added in the CMake development version recently:

http://www.cmake.org/Bug/bug.php?op=show&bugid=2749

You can get things working now like this though:

// foo.c
... implement code ...
-------------------------------
// foo2d.c
#define IMAGE_DIMENSION 2
#include "foo.c"
-------------------------------
// foo3d.c
#define IMAGE_DIMENSION 3
#include "foo.c"

Then just add one executable with foo2d.c and the other with foo3d.c.

-Brad


More information about the CMake mailing list