Skip to content

Commit cdc899a

Browse files
authored
Merge pull request Tencent#1124 from DerDakon/CMake-cleanup
CMake cleanups
2 parents fc7cda7 + ff59b61 commit cdc899a

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

CMakeLists.txt

Lines changed: 17 additions & 11 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)
@@ -51,9 +55,9 @@ if(CCACHE_FOUND)
5155
endif()
5256
endif(CCACHE_FOUND)
5357

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")
5761
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native")
5862
else()
5963
#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")
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()
@@ -84,15 +88,17 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
8488
endif()
8589
endif()
8690
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()
9298
endif()
9399
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-missing-field-initializers")
94100
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)
96102
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
97103
endif()
98104
if (RAPIDJSON_BUILD_ASAN)
@@ -105,7 +111,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
105111
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
106112
endif()
107113
endif()
108-
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
114+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
109115
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
110116
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
111117
elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")

0 commit comments

Comments
 (0)