1# vim: et ts=4 sts=4 sw=4 tw=0 2 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# 15set(JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION "3.8.0") 16set(JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION "3.13.2") 17cmake_minimum_required(VERSION ${JSONCPP_OLDEST_VALIDATED_POLICIES_VERSION}) 18if("${CMAKE_VERSION}" VERSION_LESS "${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}") 21else() 22 set(JSONCPP_CMAKE_POLICY_VERSION "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}") 23endif() 24cmake_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# 29foreach(pnew "") # Currently Empty 30 if(POLICY ${pnew}) 31 cmake_policy(SET ${pnew} NEW) 32 endif() 33endforeach() 34foreach(pold "") # Currently Empty 35 if(POLICY ${pold}) 36 cmake_policy(SET ${pold} OLD) 37 endif() 38endforeach() 39 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. 42set(CMAKE_CXX_STANDARD 11) 43set(CMAKE_CXX_EXTENSIONS OFF) 44set(CMAKE_CXX_STANDARD_REQUIRED ON) 45 46# Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators. 47if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES) 48 set(CMAKE_BUILD_TYPE Release CACHE STRING 49 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.") 50endif() 51 52set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 53 54# --------------------------------------------------------------------------- 55# use ccache if found, has to be done before project() 56# --------------------------------------------------------------------------- 57find_program(CCACHE_EXECUTABLE "ccache" HINTS /usr/local/bin /opt/local/bin) 58if(CCACHE_EXECUTABLE) 59 message(STATUS "use ccache") 60 set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" CACHE PATH "ccache" FORCE) 61 set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" CACHE PATH "ccache" FORCE) 62endif() 63 64project(jsoncpp 65 # Note: version must be updated in three places when doing a release. This 66 # annoying process ensures that amalgamate, CMake, and meson all report the 67 # correct version. 68 # 1. ./meson.build 69 # 2. ./include/json/version.h 70 # 3. ./CMakeLists.txt 71 # IMPORTANT: also update the PROJECT_SOVERSION!! 72 VERSION 1.9.4 # <major>[.<minor>[.<patch>[.<tweak>]]] 73 LANGUAGES CXX) 74 75message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") 76set(PROJECT_SOVERSION 24) 77 78configure_file( ${jsoncpp_SOURCE_DIR}/config.h.cts ${jsoncpp_SOURCE_DIR}/src/include/json/config.h COPYONLY ) 79configure_file( ${jsoncpp_SOURCE_DIR}/json_valueiterator.inl.cts ${jsoncpp_SOURCE_DIR}/src/src/lib_json/json_valueiterator.inl COPYONLY ) 80 81option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" OFF) 82option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" OFF) 83option(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF) 84option(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C and ISO C++" ON) 85option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" OFF) 86option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF) 87option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF) 88option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF) 89option(BUILD_STATIC_LIBS "Build jsoncpp_lib as a static library." ON) 90option(BUILD_OBJECT_LIBS "Build jsoncpp_lib as a object library." OFF) 91 92# Adhere to GNU filesystem layout conventions 93include(GNUInstallDirs) 94 95#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Archive output dir.") 96#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Library output dir.") 97#set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "PDB (MSVC debug symbol)output dir.") 98#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Executable/dll output dir.") 99 100set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL") 101 102configure_file("${PROJECT_SOURCE_DIR}/src/version.in" 103 "${PROJECT_BINARY_DIR}/version" 104 NEWLINE_STYLE UNIX) 105 106macro(use_compilation_warning_as_error) 107 if(MSVC) 108 # Only enabled in debug because some old versions of VS STL generate 109 # warnings when compiled in release configuration. 110 add_compile_options($<$<CONFIG:Debug>:/WX>) 111 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 112 add_compile_options(-Werror) 113 if(JSONCPP_WITH_STRICT_ISO) 114 add_compile_options(-pedantic-errors) 115 endif() 116 endif() 117endmacro() 118 119# Include our configuration header 120include_directories(${jsoncpp_SOURCE_DIR}/include) 121include_directories(${jsoncpp_SOURCE_DIR}/src/include) 122 123if(MSVC) 124 # Only enabled in debug because some old versions of VS STL generate 125 # unreachable code warning when compiled in release configuration. 126 add_compile_options($<$<CONFIG:Debug>:/W4>) 127endif() 128 129if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 130 # using regular Clang or AppleClang 131 add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare) 132elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 133 # using GCC 134 add_compile_options(-Wall -Wconversion -Wshadow -Wextra) 135 # not yet ready for -Wsign-conversion 136 137 if(JSONCPP_WITH_STRICT_ISO) 138 add_compile_options(-Wpedantic) 139 endif() 140 if(JSONCPP_WITH_WARNING_AS_ERROR) 141 add_compile_options(-Werror=conversion) 142 endif() 143elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") 144 # using Intel compiler 145 add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion) 146 147 if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR) 148 add_compile_options(-Wpedantic) 149 endif() 150endif() 151 152if(JSONCPP_WITH_WARNING_AS_ERROR) 153 use_compilation_warning_as_error() 154endif() 155 156if(JSONCPP_WITH_PKGCONFIG_SUPPORT) 157 include(JoinPaths) 158 159 join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") 160 join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") 161 162 configure_file( 163 "pkg-config/jsoncpp.pc.in" 164 "pkg-config/jsoncpp.pc" 165 @ONLY) 166 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkg-config/jsoncpp.pc" 167 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 168endif() 169 170if(JSONCPP_WITH_CMAKE_PACKAGE) 171 include(CMakePackageConfigHelpers) 172 install(EXPORT jsoncpp 173 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp 174 FILE jsoncppConfig.cmake) 175 write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake" 176 VERSION ${PROJECT_VERSION} 177 COMPATIBILITY SameMajorVersion) 178 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake 179 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp) 180endif() 181 182if(JSONCPP_WITH_TESTS) 183 enable_testing() 184 include(CTest) 185endif() 186 187# Build the different applications 188add_subdirectory(src/src) 189 190#install the includes 191add_subdirectory(src/include) 192 193#install the example 194if(JSONCPP_WITH_EXAMPLE) 195 add_subdirectory(src/example) 196endif() 197 198