Skip to content

Commit b3b92df

Browse files
hjmjohnsoncdunn2001
authored andcommitted
ENH: Provide range for non-warned cmake versions
Allow configuring without cmake policy developer warnings for a range of cmake versions. This prevents the need to explicitly enumerate every new policy for each new cmake version. === Moved setting of the CMAKE_CXX_STANDARD to before the project() directive.
1 parent 892a386 commit b3b92df

File tree

1 file changed

+55
-7
lines changed

1 file changed

+55
-7
lines changed

CMakeLists.txt

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
11
# vim: et ts=4 sts=4 sw=4 tw=0
22

3-
cmake_minimum_required(VERSION 3.1)
3+
# ==== Define cmake build policies that affect compilation and linkage default behaviors
4+
#
5+
# Set the JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION string to the newest cmake version
6+
# policies that provide successful builds. By setting JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION
7+
# to a value greater than the oldest policies, all policies between
8+
# JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION and CMAKE_VERSION (used for this build)
9+
# are set to their NEW behaivor, thereby suppressing policy warnings related to policies
10+
# between the JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION and CMAKE_VERSION.
11+
#
12+
# CMake versions greater than the JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION policies will
13+
# continue to generate policy warnings "CMake Warning (dev)...Policy CMP0XXX is not set:"
14+
#
15+
set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.1.0")
16+
set(JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION "3.13.1")
17+
cmake_minimum_required(VERSION ${JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION} FATAL_ERROR)
18+
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}")
19+
#Set and use the newest available cmake policies that are validated to work
20+
set(JSONCPP_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
21+
else()
22+
set(JSONCPP_CMAKE_POLICY_VERSION "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}")
23+
endif()
24+
cmake_policy(VERSION ${JSONCPP_CMAKE_POLICY_VERSION})
25+
#
26+
# Now enumerate specific policies newer than JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION
27+
# that may need to be individually set to NEW/OLD
28+
#
29+
foreach(pnew "") # Currently Empty
30+
if(POLICY ${pnew})
31+
cmake_policy(SET ${pnew} NEW)
32+
endif()
33+
endforeach()
34+
foreach(pold "") # Currently Empty
35+
if(POLICY ${pold})
36+
cmake_policy(SET ${pold} OLD)
37+
endif()
38+
endforeach()
39+
40+
# ==== Define language standard configurations requiring at least c++11 standard
41+
if(CMAKE_CXX_STANDARD EQUAL "98" )
42+
message(FATAL_ERROR "CMAKE_CXX_STANDARD:STRING=98 is not supported.")
43+
endif()
44+
45+
#####
46+
## Set the default target properties
47+
if(NOT CMAKE_CXX_STANDARD)
48+
set(CMAKE_CXX_STANDARD 11) # Supported values are ``11``, ``14``, and ``17``.
49+
endif()
50+
if(NOT CMAKE_CXX_STANDARD_REQUIRED)
51+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
52+
endif()
53+
if(NOT CMAKE_CXX_EXTENSIONS)
54+
set(CMAKE_CXX_EXTENSIONS OFF)
55+
endif()
56+
57+
# ====
458

559
# Ensures that CMAKE_BUILD_TYPE has a default value
660
if(NOT DEFINED CMAKE_BUILD_TYPE)
@@ -73,12 +127,6 @@ if(MSVC)
73127
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
74128
endif()
75129

76-
# Require C++11 support, prefer ISO C++ over GNU variants,
77-
# as relying solely on ISO C++ is more portable.
78-
set(CMAKE_CXX_STANDARD 11)
79-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
80-
set(CMAKE_CXX_EXTENSIONS OFF)
81-
82130
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
83131
# using regular Clang or AppleClang
84132
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare")

0 commit comments

Comments
 (0)