I have the following content in my CMakeLists.txt:
project( Matfile )
SET ( CMAKE_CXX_FLAGS \"-std=c++0x\" )
set ( SOURCES
\"foo.cpp\"
\"bar.cp
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.