@@ -31,6 +31,10 @@ option(RAPIDJSON_BUILD_THIRDPARTY_GTEST
31
31
"Use gtest installation in `thirdparty/gtest` by default if available" OFF )
32
32
33
33
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 ()
34
38
35
39
option (RAPIDJSON_BUILD_ASAN "Build rapidjson with address sanitizer (gcc/clang)" OFF )
36
40
option (RAPIDJSON_BUILD_UBSAN "Build rapidjson with undefined behavior sanitizer (gcc/clang)" OFF )
@@ -51,9 +55,9 @@ if(CCACHE_FOUND)
51
55
endif ()
52
56
endif (CCACHE_FOUND )
53
57
54
- if (" ${ CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
55
- if (${ RAPIDJSON_ENABLE_INSTRUMENTATION_OPT} )
56
- if (" ${ CMAKE_SYSTEM_PROCESSOR} " STREQUAL "powerpc" OR " ${ CMAKE_SYSTEM_PROCESSOR} " STREQUAL "ppc64" OR " ${ CMAKE_SYSTEM_PROCESSOR} " STREQUAL "ppc64le" )
58
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
59
+ if (RAPIDJSON_ENABLE_INSTRUMENTATION_OPT AND NOT CMAKE_CROSSCOMPILING )
60
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "powerpc" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le" )
57
61
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native" )
58
62
else ()
59
63
#FIXME: x86 is -march=native, but doesn't mean every arch is this option. To keep original project's compatibility, I leave this except POWER.
@@ -62,7 +66,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
62
66
endif ()
63
67
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror" )
64
68
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 )
66
70
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7.0" )
67
71
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x" )
68
72
else ()
@@ -84,15 +88,17 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
84
88
endif ()
85
89
endif ()
86
90
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
87
- if ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "powerpc" OR "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "ppc64" OR "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "ppc64le" )
88
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native" )
89
- else ()
90
- #FIXME: x86 is -march=native, but doesn't mean every arch is this option. To keep original project's compatibility, I leave this except POWER.
91
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native" )
91
+ if (NOT CMAKE_CROSSCOMPILING )
92
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "powerpc" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le" )
93
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native" )
94
+ else ()
95
+ #FIXME: x86 is -march=native, but doesn't mean every arch is this option. To keep original project's compatibility, I leave this except POWER.
96
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native" )
97
+ endif ()
92
98
endif ()
93
99
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-missing-field-initializers" )
94
100
set (EXTRA_CXX_FLAGS -Weffc++ -Wswitch-default -Wfloat-equal -Wconversion -Wimplicit-fallthrough )
95
- if (RAPIDJSON_BUILD_CXX11 )
101
+ if (RAPIDJSON_BUILD_CXX11 AND CMAKE_VERSION VERSION_LESS 3.1 )
96
102
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
97
103
endif ()
98
104
if (RAPIDJSON_BUILD_ASAN )
@@ -105,7 +111,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
105
111
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined" )
106
112
endif ()
107
113
endif ()
108
- elseif (" ${ CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" )
114
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
109
115
add_definitions (-D_CRT_SECURE_NO_WARNINGS=1 )
110
116
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" )
111
117
elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL" )
0 commit comments