diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f2bab5..8a7d3ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,11 +104,23 @@ macro(UseCompilationWarningAsError) if(MSVC) # Only enabled in debug because some old versions of VS STL generate # warnings when compiled in release configuration. - add_compile_options($<$:/WX>) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_options($<$:/WX>) + else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") + endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_compile_options(-Werror) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_options(-Werror) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + endif() if(JSONCPP_WITH_STRICT_ISO) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) add_compile_options(-pedantic-errors) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors") + endif() endif() endif() endmacro() @@ -119,29 +131,57 @@ include_directories( ${jsoncpp_SOURCE_DIR}/include ) if(MSVC) # Only enabled in debug because some old versions of VS STL generate # unreachable code warning when compiled in release configuration. - add_compile_options($<$:/W4>) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_options($<$:/W4>) + else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ") + endif() endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare") + endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC - add_compile_options(-Wall -Wconversion -Wshadow -Wextra) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_options(-Wall -Wconversion -Wshadow -Wextra) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra") + endif() # not yet ready for -Wsign-conversion if(JSONCPP_WITH_STRICT_ISO) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) add_compile_options(-pedantic) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") + endif() endif() if(JSONCPP_WITH_WARNING_AS_ERROR) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) add_compile_options(-Werror=conversion) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion") + endif() endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") # using Intel compiler - add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra -Werror=conversion") + endif() if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) add_compile_options(-pedantic) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") + endif() endif() endif() diff --git a/src/jsontestrunner/CMakeLists.txt b/src/jsontestrunner/CMakeLists.txt index 023a44e..39c6f48 100644 --- a/src/jsontestrunner/CMakeLists.txt +++ b/src/jsontestrunner/CMakeLists.txt @@ -5,7 +5,11 @@ add_executable(jsontestrunner_exe ) if(BUILD_SHARED_LIBS) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) add_compile_definitions( JSON_DLL ) + else() + add_definitions( -DJSON_DLL ) + endif() endif() target_link_libraries(jsontestrunner_exe jsoncpp_lib) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index a9bf786..b56788e 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -34,7 +34,11 @@ endif() if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV)) message(WARNING "Locale functionality is not supported") - add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT) + else() + add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT) + endif() endif() set( JSONCPP_INCLUDE_DIR ../../include ) @@ -66,8 +70,13 @@ else(JSONCPP_WITH_CMAKE_PACKAGE) set(INSTALL_EXPORT) endif() + if(BUILD_SHARED_LIBS) - add_compile_definitions( JSON_DLL_BUILD ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) + add_compile_definitions( JSON_DLL_BUILD ) + else() + add_definitions( -DJSON_DLL_BUILD ) + endif() endif() diff --git a/src/test_lib_json/CMakeLists.txt b/src/test_lib_json/CMakeLists.txt index abb1813..6e301ec 100644 --- a/src/test_lib_json/CMakeLists.txt +++ b/src/test_lib_json/CMakeLists.txt @@ -10,7 +10,11 @@ add_executable( jsoncpp_test if(BUILD_SHARED_LIBS) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) add_compile_definitions( JSON_DLL ) + else() + add_definitions( -DJSON_DLL ) + endif() endif() target_link_libraries(jsoncpp_test jsoncpp_lib)