2015-03-06 01:14:58 +01:00
|
|
|
|
# vim: et ts=4 sts=4 sw=4 tw=0
|
|
|
|
|
|
2018-12-12 17:02:42 +01:00
|
|
|
|
# ==== 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:"
|
|
|
|
|
#
|
2019-06-28 19:11:58 +02:00
|
|
|
|
set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.8.0")
|
2019-01-18 02:25:06 +01:00
|
|
|
|
set(JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION "3.13.2")
|
2019-01-18 02:21:12 +01:00
|
|
|
|
cmake_minimum_required(VERSION ${JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION})
|
2019-01-18 02:25:06 +01:00
|
|
|
|
if("${CMAKE_VERSION}" VERSION_LESS "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}")
|
2018-12-12 17:02:42 +01:00
|
|
|
|
#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()
|
|
|
|
|
|
|
|
|
|
# ====
|
2018-10-03 09:37:12 +02:00
|
|
|
|
|
|
|
|
|
# Ensures that CMAKE_BUILD_TYPE has a default value
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(NOT DEFINED CMAKE_BUILD_TYPE)
|
|
|
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING
|
2018-10-03 09:37:12 +02:00
|
|
|
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
2018-10-03 09:37:12 +02:00
|
|
|
|
|
2018-12-12 16:56:19 +01:00
|
|
|
|
project(JSONCPP
|
2019-08-14 07:41:43 +02:00
|
|
|
|
# Note: version must be updated in three places when doing a release. This
|
|
|
|
|
# annoying process ensures that amalgamate, CMake, and meson all report the
|
|
|
|
|
# correct version.
|
|
|
|
|
# 1. /meson.build
|
|
|
|
|
# 2. /include/json/version.h
|
|
|
|
|
# 3. /CMakeLists.txt
|
|
|
|
|
# IMPORTANT: also update the SOVERSION!!
|
2020-01-07 02:23:50 +01:00
|
|
|
|
VERSION 1.9.3 # <major>[.<minor>[.<patch>[.<tweak>]]]
|
2018-12-12 16:56:19 +01:00
|
|
|
|
LANGUAGES CXX)
|
|
|
|
|
|
|
|
|
|
message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
|
2019-08-14 07:41:43 +02:00
|
|
|
|
set( JSONCPP_SOVERSION 22 )
|
2018-12-12 16:56:19 +01:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
|
|
|
|
|
option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
|
|
|
|
|
option(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
|
|
|
|
|
option(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C and ISO C++" ON)
|
|
|
|
|
option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
|
|
|
|
|
option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON)
|
2019-12-23 04:04:44 +01:00
|
|
|
|
option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF)
|
2018-12-12 16:40:05 +01:00
|
|
|
|
option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
|
2013-05-08 22:21:11 +02:00
|
|
|
|
|
2016-09-23 07:05:13 +02:00
|
|
|
|
# Enable runtime search path support for dynamic libraries on OSX
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(APPLE)
|
|
|
|
|
set(CMAKE_MACOSX_RPATH 1)
|
|
|
|
|
endif()
|
2016-09-23 07:05:13 +02:00
|
|
|
|
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# Adhere to GNU filesystem layout conventions
|
2018-12-12 16:40:05 +01:00
|
|
|
|
include(GNUInstallDirs)
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
set(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build")
|
2014-11-04 05:44:48 +01:00
|
|
|
|
|
2019-06-03 12:35:14 +02:00
|
|
|
|
set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
|
2014-09-16 21:26:50 +02:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
configure_file( "${PROJECT_SOURCE_DIR}/version.in"
|
2018-04-17 16:16:54 +02:00
|
|
|
|
"${PROJECT_BINARY_DIR}/version"
|
2015-03-06 01:14:58 +01:00
|
|
|
|
NEWLINE_STYLE UNIX )
|
2014-09-16 21:26:50 +02:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
macro(UseCompilationWarningAsError)
|
|
|
|
|
if(MSVC)
|
2013-05-09 20:42:33 +02:00
|
|
|
|
# Only enabled in debug because some old versions of VS STL generate
|
|
|
|
|
# warnings when compiled in release configuration.
|
2019-10-16 16:38:05 +02:00
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
|
|
|
|
|
add_compile_options($<$<CONFIG:Debug>:/WX>)
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
|
|
|
|
|
endif()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2019-10-16 16:38:05 +02:00
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
|
|
|
|
|
add_compile_options(-Werror)
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
|
|
|
|
endif()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(JSONCPP_WITH_STRICT_ISO)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
|
2019-06-03 12:35:14 +02:00
|
|
|
|
add_compile_options(-pedantic-errors)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
|
|
|
|
|
endif()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endmacro()
|
2013-05-09 20:42:33 +02:00
|
|
|
|
|
2013-05-08 22:21:11 +02:00
|
|
|
|
# Include our configuration header
|
2018-12-12 16:40:05 +01:00
|
|
|
|
include_directories( ${jsoncpp_SOURCE_DIR}/include )
|
2013-05-08 22:21:11 +02:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(MSVC)
|
2013-05-09 20:42:33 +02:00
|
|
|
|
# Only enabled in debug because some old versions of VS STL generate
|
|
|
|
|
# unreachable code warning when compiled in release configuration.
|
2019-10-16 16:38:05 +02:00
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
|
|
|
|
|
add_compile_options($<$<CONFIG:Debug>:/W4>)
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
|
|
|
|
|
endif()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# using regular Clang or AppleClang
|
2019-10-16 16:38:05 +02:00
|
|
|
|
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()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# using GCC
|
2019-10-16 16:38:05 +02:00
|
|
|
|
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()
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# not yet ready for -Wsign-conversion
|
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(JSONCPP_WITH_STRICT_ISO)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
|
2019-06-03 12:35:14 +02:00
|
|
|
|
add_compile_options(-pedantic)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
|
|
|
|
endif()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
|
|
|
|
if(JSONCPP_WITH_WARNING_AS_ERROR)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
|
2019-06-03 12:35:14 +02:00
|
|
|
|
add_compile_options(-Werror=conversion)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion")
|
|
|
|
|
endif()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# using Intel compiler
|
2019-10-16 16:38:05 +02:00
|
|
|
|
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()
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
|
2019-06-03 12:35:14 +02:00
|
|
|
|
add_compile_options(-pedantic)
|
2019-10-16 16:38:05 +02:00
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
|
|
|
|
endif()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
find_program(CCACHE_FOUND ccache)
|
|
|
|
|
if(CCACHE_FOUND)
|
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
|
|
|
|
endif(CCACHE_FOUND)
|
2015-10-19 19:10:58 +02:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(JSONCPP_WITH_WARNING_AS_ERROR)
|
2013-05-09 20:42:33 +02:00
|
|
|
|
UseCompilationWarningAsError()
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
2013-05-09 20:42:33 +02:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(JSONCPP_WITH_PKGCONFIG_SUPPORT)
|
|
|
|
|
configure_file(
|
2016-12-14 17:53:10 +01:00
|
|
|
|
"pkg-config/jsoncpp.pc.in"
|
|
|
|
|
"pkg-config/jsoncpp.pc"
|
|
|
|
|
@ONLY)
|
2018-12-12 16:40:05 +01:00
|
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkg-config/jsoncpp.pc"
|
2016-12-14 17:53:10 +01:00
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
2014-09-14 15:45:07 +02:00
|
|
|
|
|
2018-12-12 16:40:05 +01:00
|
|
|
|
if(JSONCPP_WITH_CMAKE_PACKAGE)
|
2019-06-03 12:39:50 +02:00
|
|
|
|
include (CMakePackageConfigHelpers)
|
2018-12-12 16:40:05 +01:00
|
|
|
|
install(EXPORT jsoncpp
|
2016-12-14 17:53:10 +01:00
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp
|
2014-11-04 09:33:25 +01:00
|
|
|
|
FILE jsoncppConfig.cmake)
|
2019-06-03 12:39:50 +02:00
|
|
|
|
write_basic_package_version_file ("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake"
|
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
|
COMPATIBILITY SameMajorVersion)
|
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
|
2018-12-12 16:40:05 +01:00
|
|
|
|
endif()
|
2014-11-04 09:33:25 +01:00
|
|
|
|
|
2019-01-12 19:32:15 +01:00
|
|
|
|
if(JSONCPP_WITH_TESTS)
|
|
|
|
|
enable_testing()
|
|
|
|
|
include(CTest)
|
|
|
|
|
endif()
|
|
|
|
|
|
2013-05-08 22:21:11 +02:00
|
|
|
|
# Build the different applications
|
2018-12-12 16:40:05 +01:00
|
|
|
|
add_subdirectory( src )
|
2013-05-08 22:21:11 +02:00
|
|
|
|
|
|
|
|
|
#install the includes
|
2018-12-12 16:40:05 +01:00
|
|
|
|
add_subdirectory( include )
|
2019-01-12 19:32:15 +01:00
|
|
|
|
|
2019-09-17 22:30:00 +02:00
|
|
|
|
#install the example
|
2019-12-23 04:04:44 +01:00
|
|
|
|
if(JSONCPP_WITH_EXAMPLE)
|
|
|
|
|
add_subdirectory( example )
|
|
|
|
|
endif()
|