Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control compiler flag invoked when specifing CMAKE_CXX_STANDARD?

Tags:

c++11

cmake

c++14

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"?

like image 665
doc07b5 Avatar asked Jun 30 '16 20:06

doc07b5


1 Answers

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

like image 200
Finn Avatar answered Nov 15 '22 12:11

Finn