# 相关链接:
https://cmake.org/cmake/help/v3.0/module/CheckCXXCompilerFlag.html
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
add_definitions("-std=c++11")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
add_definitions("-std=c++11")
endif()
C++代码中则可以如下判断:
#if __cplusplus >= 201103L
#include <random>
#endif // __cplusplus >= 201103L

本文介绍如何使用CMake检查编译器是否支持C++11特性,并据此设置编译选项。此外,还提供了在C++代码中判断C++11支持的方法。
2068

被折叠的 条评论
为什么被折叠?



