@@ -104,11 +104,23 @@ macro(UseCompilationWarningAsError)
104104 if (MSVC )
105105 # Only enabled in debug because some old versions of VS STL generate
106106 # 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 ()
108112 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 ()
110118 if (JSONCPP_WITH_STRICT_ISO)
119+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
111120 add_compile_options (-pedantic-errors)
121+ else ()
122+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors" )
123+ endif ()
112124 endif ()
113125 endif ()
114126endmacro ()
@@ -119,29 +131,57 @@ include_directories( ${jsoncpp_SOURCE_DIR}/include )
119131if (MSVC )
120132 # Only enabled in debug because some old versions of VS STL generate
121133 # 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 ()
123139endif ()
124140
125141if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
126142 # 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 ()
128148elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
129149 # 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 ()
131155 # not yet ready for -Wsign-conversion
132156
133157 if (JSONCPP_WITH_STRICT_ISO)
158+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
134159 add_compile_options (-pedantic)
160+ else ()
161+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic" )
162+ endif ()
135163 endif ()
136164 if (JSONCPP_WITH_WARNING_AS_ERROR)
165+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
137166 add_compile_options (-Werror=conversion)
167+ else ()
168+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion" )
169+ endif ()
138170 endif ()
139171elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
140172 # 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 ()
142178
143179 if (JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
180+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
144181 add_compile_options (-pedantic)
182+ else ()
183+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic" )
184+ endif ()
145185 endif ()
146186endif ()
147187
0 commit comments