@@ -104,11 +104,23 @@ macro(UseCompilationWarningAsError)
104
104
if (MSVC )
105
105
# Only enabled in debug because some old versions of VS STL generate
106
106
# warnings when compiled in release configuration.
107
- add_compile_options ($<$<CONFIG:Debug>:/WX>)
107
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
108
+ add_compile_options ($<$<CONFIG:Debug>:/WX>)
109
+ else ()
110
+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX " )
111
+ endif ()
108
112
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
109
- add_compile_options (-Werror)
113
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
114
+ add_compile_options (-Werror)
115
+ else ()
116
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" )
117
+ endif ()
110
118
if (JSONCPP_WITH_STRICT_ISO)
119
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
111
120
add_compile_options (-pedantic-errors)
121
+ else ()
122
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors" )
123
+ endif ()
112
124
endif ()
113
125
endif ()
114
126
endmacro ()
@@ -119,29 +131,57 @@ include_directories( ${jsoncpp_SOURCE_DIR}/include )
119
131
if (MSVC )
120
132
# Only enabled in debug because some old versions of VS STL generate
121
133
# unreachable code warning when compiled in release configuration.
122
- add_compile_options ($<$<CONFIG:Debug>:/W4>)
134
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
135
+ add_compile_options ($<$<CONFIG:Debug>:/W4>)
136
+ else ()
137
+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 " )
138
+ endif ()
123
139
endif ()
124
140
125
141
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
126
142
# using regular Clang or AppleClang
127
- add_compile_options (-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
143
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
144
+ add_compile_options (-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
145
+ else ()
146
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare" )
147
+ endif ()
128
148
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
129
149
# using GCC
130
- add_compile_options (-Wall -Wconversion -Wshadow -Wextra)
150
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
151
+ add_compile_options (-Wall -Wconversion -Wshadow -Wextra)
152
+ else ()
153
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra" )
154
+ endif ()
131
155
# not yet ready for -Wsign-conversion
132
156
133
157
if (JSONCPP_WITH_STRICT_ISO)
158
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
134
159
add_compile_options (-pedantic)
160
+ else ()
161
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic" )
162
+ endif ()
135
163
endif ()
136
164
if (JSONCPP_WITH_WARNING_AS_ERROR)
165
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
137
166
add_compile_options (-Werror=conversion)
167
+ else ()
168
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion" )
169
+ endif ()
138
170
endif ()
139
171
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
140
172
# using Intel compiler
141
- add_compile_options (-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
173
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
174
+ add_compile_options (-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
175
+ else ()
176
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra -Werror=conversion" )
177
+ endif ()
142
178
143
179
if (JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
180
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
144
181
add_compile_options (-pedantic)
182
+ else ()
183
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic" )
184
+ endif ()
145
185
endif ()
146
186
endif ()
147
187
0 commit comments