CMake command line for C++ #define

后端 未结 3 602
逝去的感伤
逝去的感伤 2021-02-11 14:52

I need to compile different versions of a certain project by adding compiler switches. Usually I would do this by using add_definitions or something like

set_p         


        
3条回答
  •  感动是毒
    2021-02-11 15:57

    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 )
    ENDIF()
    ADD_DEFINITIONS(-D_MYDEFINE=${_MYDEFINE})
    

    (No it is not really called "MYDEFINE", and 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= 
    

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

提交回复
热议问题