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