From a3afd74b80715a0a1f2d7b5c47b90385b7e1b136 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 18 Feb 2020 18:04:04 -0700 Subject: [PATCH 01/11] Don't use unique variable for postfix The more general CMake way to handle library suffixing is to set CMAKE__POSTFIX, so setting the Debug output suffix name should be more correctly done by the caller or CMake configurer by setting the desired value in CMAKE_DEBUG_POSTFIX. --- CMakeLists.txt | 2 -- src/lib_json/CMakeLists.txt | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7e2e09..da6b51e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,8 +103,6 @@ endif() # Adhere to GNU filesystem layout conventions include(GNUInstallDirs) -set(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build") - set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL") configure_file("${PROJECT_SOURCE_DIR}/version.in" diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 401e1f7..1128381 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -84,8 +84,7 @@ endif() add_library(jsoncpp_lib ${PUBLIC_HEADERS} ${jsoncpp_sources}) set_target_properties(jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_SOVERSION}) -set_target_properties(jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp - DEBUG_OUTPUT_NAME jsoncpp${DEBUG_LIBNAME_SUFFIX}) +set_target_properties(jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp) set_target_properties(jsoncpp_lib PROPERTIES POSITION_INDEPENDENT_CODE ON) # Set library's runtime search path on OSX From c648b0378addd7834c1c530ea20853303c1de535 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 18 Feb 2020 18:04:59 -0700 Subject: [PATCH 02/11] Consolidate setting of jsoncpp target properties --- src/lib_json/CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 1128381..e22fb1c 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -81,11 +81,13 @@ if(BUILD_SHARED_LIBS) endif() endif() - add_library(jsoncpp_lib ${PUBLIC_HEADERS} ${jsoncpp_sources}) -set_target_properties(jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_SOVERSION}) -set_target_properties(jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp) -set_target_properties(jsoncpp_lib PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties( jsoncpp_lib PROPERTIES + OUTPUT_NAME jsoncpp + VERSION ${JSONCPP_VERSION} + SOVERSION ${JSONCPP_SOVERSION} + POSITION_INDEPENDENT_CODE ON +) # Set library's runtime search path on OSX if(APPLE) From 5a0152ae1b0b6a683365e56306dcac613f0859a1 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 31 Dec 2019 15:42:19 -0700 Subject: [PATCH 03/11] Only set CMAKE_BUILD_TYPE for single config generators --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da6b51e..714960b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,8 +56,8 @@ endif() # ==== -# Ensures that CMAKE_BUILD_TYPE has a default value -if(NOT DEFINED CMAKE_BUILD_TYPE) +# Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators. +if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.") endif() From edc6239f3934d39ce635d2127790f464ca08a125 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 31 Dec 2019 16:03:32 -0700 Subject: [PATCH 04/11] Not needed to specify CMAKE_MACOSX_RPATH As of CMake 3.0 with CMP0042, MACOSX_RPATH is enabled by default. Since the validated version used by jsoncpp is later than 3.0, this is already covered. --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 714960b..4f3b601 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,11 +95,6 @@ option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON) option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF) option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF) -# Enable runtime search path support for dynamic libraries on OSX -if(APPLE) - set(CMAKE_MACOSX_RPATH 1) -endif() - # Adhere to GNU filesystem layout conventions include(GNUInstallDirs) From 12ceb014850d2a7bbaf7f23cd4a1ab8f6571b17f Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 31 Dec 2019 16:07:22 -0700 Subject: [PATCH 05/11] Always use consistent CXX_STANDARD Since CMake has subdirectory variable scope, unilaterally set the CMAKE_CXX_STANDARD variable to use C++11. This covers cases with the library being included externally, both in cases of only C++98 being specified, as well as later versions being specified (since the CXX_STANDARD itself isn't a library dependency, only the PUBLIC target_compile_features on jsoncpp_lib). The previous direct check for C++98 is handled by requiring C++11 on this library; should the compiler being used not support C++11 then CMake will issue an error. --- CMakeLists.txt | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f3b601..e636eeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,24 +37,11 @@ foreach(pold "") # Currently Empty endif() endforeach() -# ==== Define language standard configurations requiring at least c++11 standard -if(CMAKE_CXX_STANDARD EQUAL "98") - message(FATAL_ERROR "CMAKE_CXX_STANDARD:STRING=98 is not supported.") -endif() - -##### -## Set the default target properties -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) # Supported values are ``11``, ``14``, and ``17``. -endif() -if(NOT CMAKE_CXX_STANDARD_REQUIRED) - set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() -if(NOT CMAKE_CXX_EXTENSIONS) - set(CMAKE_CXX_EXTENSIONS OFF) -endif() - -# ==== +# Build the library with C++11 standard support, independent from other including +# software which may use a different CXX_STANDARD or CMAKE_CXX_STANDARD. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) # Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators. if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES) From 30eb5ce128d4880febbb82c71c62952380be542a Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 31 Dec 2019 20:23:08 -0700 Subject: [PATCH 06/11] Check compiler using CMAKE_CXX_COMPILER_ID Since the introduction of CMAKE_COMPILER_IS_GNUCXX CMake has suggested using CMAKE_CXX_COMPILER_ID for more general checks. --- src/lib_json/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index e22fb1c..f237720 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -1,4 +1,4 @@ -if(CMAKE_COMPILER_IS_GNUCXX) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") #Get compiler version. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GNUCXX_VERSION From 8a5e792f206626a102d8e08d8b3a0db68b9876c2 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 31 Dec 2019 20:38:39 -0700 Subject: [PATCH 07/11] Add Clang support, be explicit about MSVC flags --- example/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 51c3218..017f560 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -10,9 +10,9 @@ set(EXAMPLES add_definitions(-D_GLIBCXX_USE_CXX11_ABI) set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS}) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ") -else() +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_definitions( -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS From 9abf11935c02543f6f7481a4aa09305feb1bbb05 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 18 Feb 2020 16:55:45 -0700 Subject: [PATCH 08/11] Remove unused CMake variable EXTRA_CXX_FLAGS is never defined, making this a noop. Further, COMPILE_OPTIONS is invalid to set as a DIRECTORY property. --- example/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 017f560..2636e88 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -8,7 +8,6 @@ set(EXAMPLES streamWrite ) add_definitions(-D_GLIBCXX_USE_CXX11_ABI) -set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS}) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ") From 524234e479daf2eb406521dcf9eb30d94554c21b Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Mon, 20 Jan 2020 13:21:14 -0700 Subject: [PATCH 09/11] 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. --- CMakeLists.txt | 60 +++++++------------------------------ example/CMakeLists.txt | 2 +- src/lib_json/CMakeLists.txt | 2 +- 3 files changed, 12 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e636eeb..bc7553a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,23 +95,11 @@ macro(use_compilation_warning_as_error) if(MSVC) # Only enabled in debug because some old versions of VS STL generate # warnings when compiled in release configuration. - 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() + add_compile_options($<$:/WX>) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) - add_compile_options(-Werror) - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - endif() + add_compile_options(-Werror) 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() + add_compile_options(-pedantic-errors) endif() endif() endmacro() @@ -122,57 +110,29 @@ 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. - 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() + add_compile_options($<$:/W4>) endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - 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() + add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC - 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() + add_compile_options(-Wall -Wconversion -Wshadow -Wextra) # not yet ready for -Wsign-conversion if(JSONCPP_WITH_STRICT_ISO) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) - add_compile_options(-Wpedantic) - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") - endif() + add_compile_options(-Wpedantic) 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() + add_compile_options(-Werror=conversion) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") # using Intel compiler - 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() + add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion) if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) - add_compile_options(-Wpedantic) - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") - endif() + add_compile_options(-Wpedantic) endif() endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 2636e88..d252a50 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -10,7 +10,7 @@ set(EXAMPLES add_definitions(-D_GLIBCXX_USE_CXX11_ABI) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ") + add_compile_options(-Wall -Wextra) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_definitions( -D_SCL_SECURE_NO_WARNINGS diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index f237720..caa9cc0 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -6,7 +6,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") #-Werror=* was introduced -after- GCC 4.1.2 if(GNUCXX_VERSION VERSION_GREATER 4.1.2) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=strict-aliasing") + add_compile_options("-Werror=strict-aliasing") endif() endif() From 3f0d63b5a9487feb2b75f13b05c4930a668da08d Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 18 Feb 2020 13:56:26 -0700 Subject: [PATCH 10/11] Use internal CMake compiler version directly --- src/lib_json/CMakeLists.txt | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index caa9cc0..b330665 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -1,13 +1,6 @@ -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - #Get compiler version. - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion - OUTPUT_VARIABLE GNUCXX_VERSION - ) - +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.1.2) #-Werror=* was introduced -after- GCC 4.1.2 - if(GNUCXX_VERSION VERSION_GREATER 4.1.2) - add_compile_options("-Werror=strict-aliasing") - endif() + add_compile_options("-Werror=strict-aliasing") endif() include(CheckIncludeFileCXX) From e9b0b96be677f011d0e9e3d153b25f3274bdb2e0 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Wed, 19 Feb 2020 09:14:08 -0700 Subject: [PATCH 11/11] Remove redundant cmake_minimum_required from example This is already covered by the toplevel CMake, which also serves to provide a consistent minimum version. --- example/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index d252a50..230d1bd 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,6 +1,4 @@ #vim: et ts =4 sts = 4 sw = 4 tw = 0 -cmake_minimum_required(VERSION 3.1) - set(EXAMPLES readFromString readFromStream