• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# ==== Define language standard configurations requiring at least c++11 standard
41if(CMAKE_CXX_STANDARD EQUAL "98" )
42    message(FATAL_ERROR "CMAKE_CXX_STANDARD:STRING=98 is not supported.")
43endif()
44
45#####
46##  Set the default target properties
47if(NOT CMAKE_CXX_STANDARD)
48    set(CMAKE_CXX_STANDARD 11) # Supported values are ``11``, ``14``, and ``17``.
49endif()
50if(NOT CMAKE_CXX_STANDARD_REQUIRED)
51    set(CMAKE_CXX_STANDARD_REQUIRED ON)
52endif()
53if(NOT CMAKE_CXX_EXTENSIONS)
54    set(CMAKE_CXX_EXTENSIONS OFF)
55endif()
56
57# ====
58
59# Ensures that CMAKE_BUILD_TYPE has a default value
60if(NOT DEFINED CMAKE_BUILD_TYPE)
61    set(CMAKE_BUILD_TYPE Release CACHE STRING
62        "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
63endif()
64
65project(JSONCPP
66        VERSION 1.9.0 # <major>[.<minor>[.<patch>[.<tweak>]]]
67        LANGUAGES CXX)
68
69message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
70set( JSONCPP_SOVERSION 21 )
71
72option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
73option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
74option(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
75option(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C and ISO C++" ON)
76option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
77option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON)
78option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
79
80# Enable runtime search path support for dynamic libraries on OSX
81if(APPLE)
82    set(CMAKE_MACOSX_RPATH 1)
83endif()
84
85# Adhere to GNU filesystem layout conventions
86include(GNUInstallDirs)
87
88set(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build")
89
90set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
91
92# File version.h is only regenerated on CMake configure step
93configure_file( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
94                "${PROJECT_BINARY_DIR}/include/json/version.h"
95                NEWLINE_STYLE UNIX )
96configure_file( "${PROJECT_SOURCE_DIR}/version.in"
97                "${PROJECT_BINARY_DIR}/version"
98                NEWLINE_STYLE UNIX )
99
100macro(UseCompilationWarningAsError)
101    if(MSVC)
102        # Only enabled in debug because some old versions of VS STL generate
103        # warnings when compiled in release configuration.
104        add_compile_options($<$<CONFIG:Debug>:/WX>)
105    elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
106        add_compile_options(-Werror)
107        if(JSONCPP_WITH_STRICT_ISO)
108            add_compile_options(-pedantic-errors)
109        endif()
110    endif()
111endmacro()
112
113# Include our configuration header
114include_directories( ${jsoncpp_SOURCE_DIR}/include )
115
116if(MSVC)
117    # Only enabled in debug because some old versions of VS STL generate
118    # unreachable code warning when compiled in release configuration.
119    add_compile_options($<$<CONFIG:Debug>:/W4>)
120endif()
121
122if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
123    # using regular Clang or AppleClang
124    add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
125elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
126    # using GCC
127    add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
128    # not yet ready for -Wsign-conversion
129
130    if(JSONCPP_WITH_STRICT_ISO)
131        add_compile_options(-pedantic)
132    endif()
133    if(JSONCPP_WITH_WARNING_AS_ERROR)
134        add_compile_options(-Werror=conversion)
135    endif()
136elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
137    # using Intel compiler
138    add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
139
140    if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
141        add_compile_options(-pedantic)
142    endif()
143endif()
144
145find_program(CCACHE_FOUND ccache)
146if(CCACHE_FOUND)
147    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
148    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
149endif(CCACHE_FOUND)
150
151if(JSONCPP_WITH_WARNING_AS_ERROR)
152    UseCompilationWarningAsError()
153endif()
154
155if(JSONCPP_WITH_PKGCONFIG_SUPPORT)
156    configure_file(
157        "pkg-config/jsoncpp.pc.in"
158        "pkg-config/jsoncpp.pc"
159        @ONLY)
160    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkg-config/jsoncpp.pc"
161        DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
162endif()
163
164if(JSONCPP_WITH_CMAKE_PACKAGE)
165        include (CMakePackageConfigHelpers)
166        install(EXPORT jsoncpp
167                DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp
168                FILE        jsoncppConfig.cmake)
169        write_basic_package_version_file ("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake"
170                VERSION ${PROJECT_VERSION}
171                COMPATIBILITY SameMajorVersion)
172        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake
173                DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
174endif()
175
176if(JSONCPP_WITH_TESTS)
177  enable_testing()
178  include(CTest)
179endif()
180
181# Build the different applications
182add_subdirectory( src )
183
184#install the includes
185add_subdirectory( include )
186
187