How to build a program with 2 different values of a variable in CMake

后端 未结 2 1343
挽巷
挽巷 2021-02-06 05:03

I\'ve recently ported my Qt project from qmake to CMake. My main program contains a value which depends on a #define directiv

相关标签:
2条回答
  • 2021-02-06 06:01

    Are you sure that set_target_properties does not work? How about this one:

    set_target_properties(myAppV1 PROPERTIES COMPILE_FLAGS "-DBUILDTYPE=1")
    

    or:

    set_target_properties(myAppV1 PROPERTIES COMPILE_DEFINITIONS "BUILDTYPE=1")
    

    On my machine it works:

    add_executable(myAppV1 main.cpp)
    add_executable(myAppV2 main.cpp)
    set_target_properties(myAppV1 PROPERTIES COMPILE_DEFINITIONS "BUILDTYPE=1")
    set_target_properties(myAppV2 PROPERTIES COMPILE_DEFINITIONS "BUILDTYPE=2")
    
    0 讨论(0)
  • 2021-02-06 06:02

    Another way could be:

    mkdir two directory
    buildflavor1
    buildflavor2
    

    In the first sub directory run:

    cmake -DFLAVOR=OPTION1 ..
    

    in the second run:

    run cmake -DFLAVOR=OPTION2 ..
    

    So two executable with same name with different compilation flag with is own feature .o and so on.

    0 讨论(0)
提交回复
热议问题