CMake command line for C++ #define

I managed to do it this way now:

I was able to convince everybody to add the following lines to the common CMakeLists.txt:

IF (NOT DEFINED _MYDEFINE)
    SET(_MYDEFINE <default value>)
ENDIF()
ADD_DEFINITIONS(-D_MYDEFINE=${_MYDEFINE})

(No it is not really called “MYDEFINE”, and <default value> is just a placeholder, I just replaced all that for this example)

This does not change the current behaviour of compiling with no additional compiler flags and is thus a valid change.

And it allows you to do

cmake -D_MYDEFINE=<my value> <path to sources>

where this cmake definition will be mapped to a C++ precompiler definition when cmake creates the project file.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)