Skip to content

Commit 524234e

Browse files
committed
Use non-version checked add_compile_options
Commit aebc7fa added version checks for CMake compatibility. In reality, only the add_compile_definitions need the check - add_compile_options itself has been supported since 3.0. Tested and confirmed built successfully with CMake 3.8.0.
1 parent 9abf119 commit 524234e

File tree

3 files changed

+12
-52
lines changed

3 files changed

+12
-52
lines changed

CMakeLists.txt

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,11 @@ macro(use_compilation_warning_as_error)
9595
if(MSVC)
9696
# Only enabled in debug because some old versions of VS STL generate
9797
# warnings when compiled in release configuration.
98-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
99-
add_compile_options($<$<CONFIG:Debug>:/WX>)
100-
else()
101-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
102-
endif()
98+
add_compile_options($<$<CONFIG:Debug>:/WX>)
10399
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
104-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
105-
add_compile_options(-Werror)
106-
else()
107-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
108-
endif()
100+
add_compile_options(-Werror)
109101
if(JSONCPP_WITH_STRICT_ISO)
110-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
111-
add_compile_options(-pedantic-errors)
112-
else()
113-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
114-
endif()
102+
add_compile_options(-pedantic-errors)
115103
endif()
116104
endif()
117105
endmacro()
@@ -122,57 +110,29 @@ include_directories(${jsoncpp_SOURCE_DIR}/include)
122110
if(MSVC)
123111
# Only enabled in debug because some old versions of VS STL generate
124112
# unreachable code warning when compiled in release configuration.
125-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
126-
add_compile_options($<$<CONFIG:Debug>:/W4>)
127-
else()
128-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
129-
endif()
113+
add_compile_options($<$<CONFIG:Debug>:/W4>)
130114
endif()
131115

132116
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
133117
# using regular Clang or AppleClang
134-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
135-
add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
136-
else()
137-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare")
138-
endif()
118+
add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
139119
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
140120
# using GCC
141-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
142-
add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
143-
else()
144-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra")
145-
endif()
121+
add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
146122
# not yet ready for -Wsign-conversion
147123

148124
if(JSONCPP_WITH_STRICT_ISO)
149-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
150-
add_compile_options(-Wpedantic)
151-
else()
152-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")
153-
endif()
125+
add_compile_options(-Wpedantic)
154126
endif()
155127
if(JSONCPP_WITH_WARNING_AS_ERROR)
156-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
157-
add_compile_options(-Werror=conversion)
158-
else()
159-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion")
160-
endif()
128+
add_compile_options(-Werror=conversion)
161129
endif()
162130
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
163131
# using Intel compiler
164-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
165-
add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
166-
else()
167-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra -Werror=conversion")
168-
endif()
132+
add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
169133

170134
if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
171-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
172-
add_compile_options(-Wpedantic)
173-
else()
174-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")
175-
endif()
135+
add_compile_options(-Wpedantic)
176136
endif()
177137
endif()
178138

example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(EXAMPLES
1010
add_definitions(-D_GLIBCXX_USE_CXX11_ABI)
1111

1212
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
13-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ")
13+
add_compile_options(-Wall -Wextra)
1414
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
1515
add_definitions(
1616
-D_SCL_SECURE_NO_WARNINGS

src/lib_json/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
66

77
#-Werror=* was introduced -after- GCC 4.1.2
88
if(GNUCXX_VERSION VERSION_GREATER 4.1.2)
9-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=strict-aliasing")
9+
add_compile_options("-Werror=strict-aliasing")
1010
endif()
1111
endif()
1212

0 commit comments

Comments
 (0)