如何控制在指定CMAKE_CXX_STANDARD时调用的编译器标志? [英] How to control compiler flag invoked when specifing CMAKE_CXX_STANDARD?
问题描述
我想让cmake管理包含-std = c ++ 14编译器标志。使用CMAKE_CXX_STANDARD很容易做到,如此处所述。这包括以下内容:
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)
但是,当使用gcc时,会导致包含-std = gnu ++ 14 - 标准功能。有没有办法让cmake在使用CMAKE_CXX_STANDARD而不是-std = gnu ++ 14时调用-std = c ++ 14编译器标志?
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"?
推荐答案
您可以使用属性CXX_EXTENSIONS或全局变量CMAKE_CXX_EXTENSIONS在-std = c ++ 1n和-std = gnu ++ 1n之间切换。
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
这篇关于如何控制在指定CMAKE_CXX_STANDARD时调用的编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!