diff --git a/CMakeLists.txt b/CMakeLists.txt index 189a8c8..6a6e8dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,60 @@ # vim: et ts=4 sts=4 sw=4 tw=0 -cmake_minimum_required(VERSION 3.1) +# ==== Define cmake build policies that affect compilation and linkage default behaviors +# +# Set the JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION string to the newest cmake version +# policies that provide successful builds. By setting JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION +# to a value greater than the oldest policies, all policies between +# JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION and CMAKE_VERSION (used for this build) +# are set to their NEW behaivor, thereby suppressing policy warnings related to policies +# between the JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION and CMAKE_VERSION. +# +# CMake versions greater than the JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION policies will +# continue to generate policy warnings "CMake Warning (dev)...Policy CMP0XXX is not set:" +# +set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.1.0") +set(JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION "3.13.1") +cmake_minimum_required(VERSION ${JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION} FATAL_ERROR) +if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}") + #Set and use the newest available cmake policies that are validated to work + set(JSONCPP_CMAKE_POLICY_VERSION "${CMAKE_VERSION}") +else() + set(JSONCPP_CMAKE_POLICY_VERSION "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}") +endif() +cmake_policy(VERSION ${JSONCPP_CMAKE_POLICY_VERSION}) +# +# Now enumerate specific policies newer than JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION +# that may need to be individually set to NEW/OLD +# +foreach(pnew "") # Currently Empty + if(POLICY ${pnew}) + cmake_policy(SET ${pnew} NEW) + endif() +endforeach() +foreach(pold "") # Currently Empty + if(POLICY ${pold}) + cmake_policy(SET ${pold} OLD) + 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() + +# ==== # Ensures that CMAKE_BUILD_TYPE has a default value if(NOT DEFINED CMAKE_BUILD_TYPE) @@ -73,12 +127,6 @@ if(MSVC) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ") endif() -# Require C++11 support, prefer ISO C++ over GNU variants, -# as relying solely on ISO C++ is more portable. -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare")