[CMake] -D constants

Eric NOULARD eric.noulard at gmail.com
Mon Mar 31 16:14:21 EDT 2008


Le Mon, 31 Mar 2008 21:36:33 +0200,
"stephan ripke" <flappinski at web.de> a écrit :

> Hello,
> I am a cmake-beginner and I want to "translate" my old project for
> use with cmake:

You should usually tell us which version of CMake you are using
on which platforms.

> 1) I brought some constants with the preprocessor from the Makefile
> into my sourcecode (e.g.: g++ -Dconstant=10 main.cpp). How do I do
> something like this with cmake?

ADD_DEFINITIONS(-Dconstant=10)

An alternative method would be to use 
CONFIGURE_FILE in order to generate
a header file which contains #define constant value.

Read the doc for those 2 macros and try them out:
http://www.cmake.org/HTML/CMake-2.4.html


> 2) Are there constants like "Windows" "Unix" "Linux", so
> the compiling of my project could react depending on the system?

In CMakeLists.txt WIN32 is defined on Windows and UNIX is defined on
Unices.

You compiler may define builtin macros which are not specific to
CMake see for example:
http://predef.sourceforge.net/



More information about the CMake mailing list