2015-03-05 18:14:58 -06:00
|
|
|
|
# vim: et ts=4 sts=4 sw=4 tw=0
|
|
|
|
|
|
2018-12-12 10:02:42 -06: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)
|
2021-12-14 21:04:47 -05:00
|
|
|
|
# are set to their NEW behavior, thereby suppressing policy warnings related to policies
|
2018-12-12 10:02:42 -06:00
|
|
|
|
# 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 10:11:58 -07:00
|
|
|
|
set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.8.0")
|
2019-01-17 19:25:06 -06:00
|
|
|
|
set(JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION "3.13.2")
|
2019-01-17 19:21:12 -06:00
|
|
|
|
cmake_minimum_required(VERSION ${JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION})
|
2019-01-17 19:25:06 -06:00
|
|
|
|
if("${CMAKE_VERSION}" VERSION_LESS "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}")
|
2018-12-12 10:02:42 -06: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})
|
2021-01-17 18:57:28 -08:00
|
|
|
|
if(POLICY CMP0091)
|
|
|
|
|
cmake_policy(SET CMP0091 NEW)
|
|
|
|
|
endif()
|
2018-12-12 10:02:42 -06:00
|
|
|
|
#
|
|
|
|
|
# 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()
|
|
|
|
|
|
2019-12-31 16:07:22 -07:00
|
|
|
|
# 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)
|
2018-10-03 09:37:12 +02:00
|
|
|
|
|
2019-12-31 15:42:19 -07:00
|
|
|
|
# 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)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
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 09:40:05 -06:00
|
|
|
|
endif()
|
2018-10-03 09:37:12 +02:00
|
|
|
|
|
2020-07-20 08:36:30 -04:00
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
|
|
2020-07-13 20:33:58 +08:00
|
|
|
|
project(jsoncpp
|
2019-08-13 22:41:43 -07: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.
|
2020-02-13 22:20:46 +01:00
|
|
|
|
# 1. ./meson.build
|
|
|
|
|
# 2. ./include/json/version.h
|
|
|
|
|
# 3. ./CMakeLists.txt
|
2020-07-13 20:33:58 +08:00
|
|
|
|
# IMPORTANT: also update the PROJECT_SOVERSION!!
|
2024-09-11 17:01:27 -07:00
|
|
|
|
VERSION 1.9.7 # <major>[.<minor>[.<patch>[.<tweak>]]]
|
2018-12-12 09:56:19 -06:00
|
|
|
|
LANGUAGES CXX)
|
|
|
|
|
|
2020-07-13 20:33:58 +08:00
|
|
|
|
message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
2024-09-11 17:01:27 -07:00
|
|
|
|
set(PROJECT_SOVERSION 27)
|
2018-12-12 09:56:19 -06:00
|
|
|
|
|
2020-11-06 15:35:51 -06:00
|
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake)
|
|
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake)
|
|
|
|
|
|
2018-12-12 09:40:05 -06: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 06:04:44 +03:00
|
|
|
|
option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF)
|
2021-01-17 18:57:28 -08:00
|
|
|
|
option(JSONCPP_STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" OFF)
|
2020-07-13 20:33:58 +08:00
|
|
|
|
option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." ON)
|
|
|
|
|
option(BUILD_STATIC_LIBS "Build jsoncpp_lib as a static library." ON)
|
|
|
|
|
option(BUILD_OBJECT_LIBS "Build jsoncpp_lib as a object library." ON)
|
2013-05-08 20:21:11 +00:00
|
|
|
|
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# Adhere to GNU filesystem layout conventions
|
2018-12-12 09:40:05 -06:00
|
|
|
|
include(GNUInstallDirs)
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2023-06-27 16:42:38 +02:00
|
|
|
|
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Archive output dir.")
|
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Library output dir.")
|
|
|
|
|
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "PDB (MSVC debug symbol)output dir.")
|
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir.")
|
|
|
|
|
endif()
|
2020-04-30 10:31:54 +08:00
|
|
|
|
|
2024-09-12 07:43:25 +07:00
|
|
|
|
include(CheckFunctionExists)
|
|
|
|
|
check_function_exists(memset_s HAVE_MEMSET_S)
|
|
|
|
|
if(HAVE_MEMSET_S)
|
|
|
|
|
add_definitions("-DHAVE_MEMSET_S=1")
|
|
|
|
|
endif()
|
|
|
|
|
|
2024-09-10 08:51:11 +07:00
|
|
|
|
if(JSONCPP_USE_SECURE_MEMORY)
|
|
|
|
|
add_definitions("-DJSONCPP_USE_SECURE_MEMORY=1")
|
|
|
|
|
endif()
|
2014-09-16 12:26:50 -07:00
|
|
|
|
|
2020-02-13 22:20:46 +01:00
|
|
|
|
configure_file("${PROJECT_SOURCE_DIR}/version.in"
|
|
|
|
|
"${PROJECT_BINARY_DIR}/version"
|
|
|
|
|
NEWLINE_STYLE UNIX)
|
2014-09-16 12:26:50 -07:00
|
|
|
|
|
2020-02-13 22:20:46 +01:00
|
|
|
|
macro(use_compilation_warning_as_error)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(MSVC)
|
2013-05-09 18:42:33 +00:00
|
|
|
|
# Only enabled in debug because some old versions of VS STL generate
|
|
|
|
|
# warnings when compiled in release configuration.
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options($<$<CONFIG:Debug>:/WX>)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options(-Werror)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(JSONCPP_WITH_STRICT_ISO)
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options(-pedantic-errors)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endmacro()
|
2013-05-09 18:42:33 +00:00
|
|
|
|
|
2013-05-08 20:21:11 +00:00
|
|
|
|
# Include our configuration header
|
2020-02-13 22:20:46 +01:00
|
|
|
|
include_directories(${jsoncpp_SOURCE_DIR}/include)
|
2013-05-08 20:21:11 +00:00
|
|
|
|
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(MSVC)
|
2013-05-09 18:42:33 +00:00
|
|
|
|
# Only enabled in debug because some old versions of VS STL generate
|
|
|
|
|
# unreachable code warning when compiled in release configuration.
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options($<$<CONFIG:Debug>:/W4>)
|
2021-01-17 18:57:28 -08:00
|
|
|
|
if (JSONCPP_STATIC_WINDOWS_RUNTIME)
|
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
|
endif()
|
2018-12-12 09:40:05 -06:00
|
|
|
|
endif()
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# using regular Clang or AppleClang
|
2021-05-06 03:55:25 +02:00
|
|
|
|
add_compile_options(-Wall -Wconversion -Wshadow)
|
|
|
|
|
|
|
|
|
|
if(JSONCPP_WITH_WARNING_AS_ERROR)
|
|
|
|
|
add_compile_options(-Werror=conversion -Werror=sign-compare)
|
|
|
|
|
endif()
|
2018-12-12 09:40:05 -06:00
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# using GCC
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# not yet ready for -Wsign-conversion
|
|
|
|
|
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(JSONCPP_WITH_STRICT_ISO)
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options(-Wpedantic)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
endif()
|
|
|
|
|
if(JSONCPP_WITH_WARNING_AS_ERROR)
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options(-Werror=conversion)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
endif()
|
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# using Intel compiler
|
2021-05-06 03:55:25 +02:00
|
|
|
|
add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2021-05-06 03:55:25 +02:00
|
|
|
|
if(JSONCPP_WITH_WARNING_AS_ERROR)
|
|
|
|
|
add_compile_options(-Werror=conversion)
|
|
|
|
|
elseif(JSONCPP_WITH_STRICT_ISO)
|
2020-01-20 13:21:14 -07:00
|
|
|
|
add_compile_options(-Wpedantic)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2016-12-14 17:53:10 +01:00
|
|
|
|
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(JSONCPP_WITH_WARNING_AS_ERROR)
|
2020-02-13 22:20:46 +01:00
|
|
|
|
use_compilation_warning_as_error()
|
2018-12-12 09:40:05 -06:00
|
|
|
|
endif()
|
2013-05-09 18:42:33 +00:00
|
|
|
|
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(JSONCPP_WITH_PKGCONFIG_SUPPORT)
|
2020-07-20 08:36:30 -04:00
|
|
|
|
include(JoinPaths)
|
|
|
|
|
|
|
|
|
|
join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
|
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
|
|
2018-12-12 09:40:05 -06:00
|
|
|
|
configure_file(
|
2016-12-14 17:53:10 +01:00
|
|
|
|
"pkg-config/jsoncpp.pc.in"
|
|
|
|
|
"pkg-config/jsoncpp.pc"
|
|
|
|
|
@ONLY)
|
2018-12-12 09:40:05 -06: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 09:40:05 -06:00
|
|
|
|
endif()
|
2014-09-14 15:45:07 +02:00
|
|
|
|
|
2018-12-12 09:40:05 -06:00
|
|
|
|
if(JSONCPP_WITH_CMAKE_PACKAGE)
|
2020-02-13 22:20:46 +01:00
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
install(EXPORT jsoncpp
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp
|
2021-02-27 18:25:11 +01:00
|
|
|
|
FILE jsoncpp-targets.cmake)
|
2021-03-06 13:49:53 +01:00
|
|
|
|
configure_package_config_file(jsoncppConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake
|
|
|
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
|
2021-02-27 18:25:11 +01:00
|
|
|
|
|
2020-02-13 22:20:46 +01:00
|
|
|
|
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake"
|
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
|
COMPATIBILITY SameMajorVersion)
|
2021-03-06 13:49:53 +01:00
|
|
|
|
install(FILES
|
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake
|
2021-04-14 20:50:43 +02:00
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp-namespaced-targets.cmake
|
2020-02-13 22:20:46 +01:00
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
|
2018-12-12 09:40:05 -06:00
|
|
|
|
endif()
|
2014-11-04 16:33:25 +08:00
|
|
|
|
|
2019-01-12 12:32:15 -06:00
|
|
|
|
if(JSONCPP_WITH_TESTS)
|
2020-02-13 22:20:46 +01:00
|
|
|
|
enable_testing()
|
|
|
|
|
include(CTest)
|
2019-01-12 12:32:15 -06:00
|
|
|
|
endif()
|
|
|
|
|
|
2013-05-08 20:21:11 +00:00
|
|
|
|
# Build the different applications
|
2020-02-13 22:20:46 +01:00
|
|
|
|
add_subdirectory(src)
|
2013-05-08 20:21:11 +00:00
|
|
|
|
|
|
|
|
|
#install the includes
|
2020-02-13 22:20:46 +01:00
|
|
|
|
add_subdirectory(include)
|
2019-01-12 12:32:15 -06:00
|
|
|
|
|
2019-09-18 04:30:00 +08:00
|
|
|
|
#install the example
|
2019-12-23 06:04:44 +03:00
|
|
|
|
if(JSONCPP_WITH_EXAMPLE)
|
2020-02-13 22:20:46 +01:00
|
|
|
|
add_subdirectory(example)
|
2019-12-23 06:04:44 +03:00
|
|
|
|
endif()
|