Changing CMAKE_CXX_FLAGS in project

后端 未结 10 723
一个人的身影
一个人的身影 2020-12-08 10:05

I have the following content in my CMakeLists.txt:

project( Matfile )

SET ( CMAKE_CXX_FLAGS \"-std=c++0x\" )

set ( SOURCES
      \"foo.cpp\"
      \"bar.cp         


        
10条回答
  •  温柔的废话
    2020-12-08 10:13

    The correct way to set the C++ standard in CMake 3.1 and later is:

    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED on)
    

    It is possible to specify the standard for one individual target also:

    set_property(TARGET mylib PROPERTY CXX_STANDARD 11)
    

    Since CMake 3.8 there is a new option to the target_compile_features command that allows to set the required standard for a target:

    target_compile_features(mylib PUBLIC cxx_std_11)
    

    The advantage would be that it propagates the requirement to dependent targets. If you compile a library with the cxx_std_11 required feature, any binary that links to it will automatically have this requirement set.

提交回复
热议问题