[ACCEPTED]-CMake disable -std=c++11 flag for C files-cmake

Accepted answer
Score: 13

Use CMAKE_CXX_FLAGS to set c++ specific flags:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

0

Score: 0

This type of thing can be done explicitly 11 without any dependence on the specific format 10 of a compiler's flags:

target_compile_features(someTargetName PUBLIC cxx_std_14)

target_compile_features can also do this 9 more implicitly I think, by requesting particular 8 language features that are only found in 7 the desired version of the language.

Another 6 way is to set a target property:

set_property(TARGET server PROPERTY CXX_STANDARD 14)

Or one may 5 set CMAKE_CXX_STANDARD, whose value is used as the default 4 value for CXX_STANDARD on targets, and then allow targets 3 to inherit that value implicitly.

(Here I'm 2 using the 2014 standard, but of course one 1 may specify 11 or some other value.)

More Related questions