Skip to content

Commit ff59b61

Browse files
committed
CMake: automatically handle C++11 settings if possible
1 parent 4c9a28a commit ff59b61

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ option(RAPIDJSON_BUILD_THIRDPARTY_GTEST
3131
"Use gtest installation in `thirdparty/gtest` by default if available" OFF)
3232

3333
option(RAPIDJSON_BUILD_CXX11 "Build rapidjson with C++11 (gcc/clang)" ON)
34+
if(RAPIDJSON_BUILD_CXX11)
35+
set(CMAKE_CXX_STANDARD 11)
36+
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
37+
endif()
3438

3539
option(RAPIDJSON_BUILD_ASAN "Build rapidjson with address sanitizer (gcc/clang)" OFF)
3640
option(RAPIDJSON_BUILD_UBSAN "Build rapidjson with undefined behavior sanitizer (gcc/clang)" OFF)
@@ -62,7 +66,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
6266
endif()
6367
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
6468
set(EXTRA_CXX_FLAGS -Weffc++ -Wswitch-default -Wfloat-equal -Wconversion -Wsign-conversion)
65-
if (RAPIDJSON_BUILD_CXX11)
69+
if (RAPIDJSON_BUILD_CXX11 AND CMAKE_VERSION VERSION_LESS 3.1)
6670
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7.0")
6771
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
6872
else()
@@ -94,7 +98,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9498
endif()
9599
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-missing-field-initializers")
96100
set(EXTRA_CXX_FLAGS -Weffc++ -Wswitch-default -Wfloat-equal -Wconversion -Wimplicit-fallthrough)
97-
if (RAPIDJSON_BUILD_CXX11)
101+
if (RAPIDJSON_BUILD_CXX11 AND CMAKE_VERSION VERSION_LESS 3.1)
98102
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
99103
endif()
100104
if (RAPIDJSON_BUILD_ASAN)

0 commit comments

Comments
 (0)