Does set_target_properties in CMake override CMAKE_CXX_FLAGS?

前端 未结 2 955
执笔经年
执笔经年 2020-12-23 11:00

At the beginning of my CMake project, I\'m setting general compilation flags in the variable CMAKE_CXX_FLAGS, like

set(CMAKE_CXX_FLAGS \"-W -Wall ${CMAKE_CXX         


        
2条回答
  •  抹茶落季
    2020-12-23 11:55

    Use the first one:

    set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS ${BUILD_FLAGS})
    

    The flags stored in BUILD_FLAGS are appended after CMAKE_CXX_FLAGS when compiling the sources of TARGET. The documentation hints at this, but I've just tried it to make sure.

    COMPILE_FLAGS

       Additional flags to use when compiling this target's sources. 
       
       The COMPILE_FLAGS property sets additional compiler flags used to
       build sources within the target.  Use COMPILE_DEFINITIONS to
       pass additional preprocessor definitions.
    

    The full command line will be the equivalent of:

    ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS} -o foo.o -c foo.cc
    

    And as Ramon said, you can always check with make VERBOSE=1.

提交回复
热议问题