Skip to content

Commit aebc7fa

Browse files
committed
BUG: New CMake features used that break backward compatibility
We desire for jsoncpp to compile and be readily available with older versions of cmake. The use of newer cmake commands requires conditional statements so that older strategies can be used with older versions of cmake. Resolves: open-source-parsers#1018
1 parent bdacfd7 commit aebc7fa

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

CMakeLists.txt

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
114126
endmacro()
@@ -119,29 +131,57 @@ include_directories( ${jsoncpp_SOURCE_DIR}/include )
119131
if(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()
123139
endif()
124140

125141
if(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()
128148
elseif(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()
139171
elseif(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()
146186
endif()
147187

src/jsontestrunner/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ add_executable(jsontestrunner_exe
55
)
66

77
if(BUILD_SHARED_LIBS)
8+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
89
add_compile_definitions( JSON_DLL )
10+
else()
11+
add_definitions( -DJSON_DLL )
12+
endif()
913
endif()
1014
target_link_libraries(jsontestrunner_exe jsoncpp_lib)
1115

src/lib_json/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ endif()
3434

3535
if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV))
3636
message(WARNING "Locale functionality is not supported")
37-
add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT)
37+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
38+
add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT)
39+
else()
40+
add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT)
41+
endif()
3842
endif()
3943

4044
set( JSONCPP_INCLUDE_DIR ../../include )
@@ -66,8 +70,13 @@ else(JSONCPP_WITH_CMAKE_PACKAGE)
6670
set(INSTALL_EXPORT)
6771
endif()
6872

73+
6974
if(BUILD_SHARED_LIBS)
70-
add_compile_definitions( JSON_DLL_BUILD )
75+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
76+
add_compile_definitions( JSON_DLL_BUILD )
77+
else()
78+
add_definitions( -DJSON_DLL_BUILD )
79+
endif()
7180
endif()
7281

7382

src/test_lib_json/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ add_executable( jsoncpp_test
1010

1111

1212
if(BUILD_SHARED_LIBS)
13+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
1314
add_compile_definitions( JSON_DLL )
15+
else()
16+
add_definitions( -DJSON_DLL )
17+
endif()
1418
endif()
1519
target_link_libraries(jsoncpp_test jsoncpp_lib)
1620

0 commit comments

Comments
 (0)