6

I would like to have cmake manage the inclusion of the "-std=c++14" compiler flag. This is easy to do using the CMAKE_CXX_STANDARD as described here. This boils down to including the following:

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)

However, when using gcc, this results in the inclusion of "-std=gnu++14" which includes some non-standard features. Is there a way to have cmake invoke the "-std=c++14" compiler flag when using CMAKE_CXX_STANDARD instead of "-std=gnu++14"?

Community
  • 1
  • 1
doc07b5
  • 600
  • 1
  • 7
  • 18

1 Answers1

7

You can use the property CXX_EXTENSIONS or the global variable CMAKE_CXX_EXTENSIONS to switch between -std=c++1n and -std=gnu++1n.

https://cmake.org/cmake/help/v3.1/prop_tgt/CXX_EXTENSIONS.html

Finn
  • 1,018
  • 6
  • 6
  • 1
    That does it...and wow...it is on the cmake documentation page right before CMAKE_CXX_STANDARD. I would have thought that one of the many searches I did would have uncovered that these flags are related. Anyways, thanks for the right answer! – doc07b5 Jul 01 '16 at 06:30