@@ -37,27 +37,14 @@ foreach(pold "") # Currently Empty
3737 endif ()
3838endforeach ()
3939
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- # ====
58-
59- # Ensures that CMAKE_BUILD_TYPE has a default value
60- if (NOT DEFINED CMAKE_BUILD_TYPE )
40+ # Build the library with C++11 standard support, independent from other including
41+ # software which may use a different CXX_STANDARD or CMAKE_CXX_STANDARD.
42+ set (CMAKE_CXX_STANDARD 11)
43+ set (CMAKE_CXX_EXTENSIONS OFF )
44+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
45+
46+ # Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators.
47+ if (NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES )
6148 set (CMAKE_BUILD_TYPE Release CACHE STRING
6249 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage." )
6350endif ()
@@ -95,16 +82,9 @@ option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON)
9582option (JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF )
9683option (BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF )
9784
98- # Enable runtime search path support for dynamic libraries on OSX
99- if (APPLE )
100- set (CMAKE_MACOSX_RPATH 1)
101- endif ()
102-
10385# Adhere to GNU filesystem layout conventions
10486include (GNUInstallDirs)
10587
106- set (DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build" )
107-
10888set (JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
10989
11090configure_file ("${PROJECT_SOURCE_DIR} /version.in"
@@ -115,23 +95,11 @@ macro(use_compilation_warning_as_error)
11595 if (MSVC )
11696 # Only enabled in debug because some old versions of VS STL generate
11797 # warnings when compiled in release configuration.
118- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
119- add_compile_options ($<$<CONFIG:Debug>:/WX>)
120- else ()
121- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX " )
122- endif ()
98+ add_compile_options ($<$<CONFIG:Debug>:/WX>)
12399 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
124- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
125- add_compile_options (-Werror)
126- else ()
127- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" )
128- endif ()
100+ add_compile_options (-Werror)
129101 if (JSONCPP_WITH_STRICT_ISO)
130- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
131- add_compile_options (-pedantic-errors)
132- else ()
133- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors" )
134- endif ()
102+ add_compile_options (-pedantic-errors)
135103 endif ()
136104 endif ()
137105endmacro ()
@@ -142,57 +110,29 @@ include_directories(${jsoncpp_SOURCE_DIR}/include)
142110if (MSVC )
143111 # Only enabled in debug because some old versions of VS STL generate
144112 # unreachable code warning when compiled in release configuration.
145- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
146- add_compile_options ($<$<CONFIG:Debug>:/W4>)
147- else ()
148- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 " )
149- endif ()
113+ add_compile_options ($<$<CONFIG:Debug>:/W4>)
150114endif ()
151115
152116if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
153117 # using regular Clang or AppleClang
154- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
155- add_compile_options (-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
156- else ()
157- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare" )
158- endif ()
118+ add_compile_options (-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
159119elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
160120 # using GCC
161- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
162- add_compile_options (-Wall -Wconversion -Wshadow -Wextra)
163- else ()
164- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra" )
165- endif ()
121+ add_compile_options (-Wall -Wconversion -Wshadow -Wextra)
166122 # not yet ready for -Wsign-conversion
167123
168124 if (JSONCPP_WITH_STRICT_ISO)
169- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
170- add_compile_options (-Wpedantic)
171- else ()
172- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic" )
173- endif ()
125+ add_compile_options (-Wpedantic)
174126 endif ()
175127 if (JSONCPP_WITH_WARNING_AS_ERROR)
176- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
177- add_compile_options (-Werror=conversion)
178- else ()
179- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion" )
180- endif ()
128+ add_compile_options (-Werror=conversion)
181129 endif ()
182130elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
183131 # using Intel compiler
184- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
185- add_compile_options (-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
186- else ()
187- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra -Werror=conversion" )
188- endif ()
132+ add_compile_options (-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
189133
190134 if (JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
191- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
192- add_compile_options (-Wpedantic)
193- else ()
194- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic" )
195- endif ()
135+ add_compile_options (-Wpedantic)
196136 endif ()
197137endif ()
198138
0 commit comments