2015-03-05 18:14:58 -06:00
|
|
|
|
# vim: et ts=4 sts=4 sw=4 tw=0
|
|
|
|
|
|
2016-12-14 17:53:10 +01:00
|
|
|
|
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
|
2018-10-03 09:37:12 +02:00
|
|
|
|
|
|
|
|
|
# Ensures that CMAKE_BUILD_TYPE has a default value
|
|
|
|
|
IF(NOT DEFINED CMAKE_BUILD_TYPE)
|
|
|
|
|
SET(CMAKE_BUILD_TYPE Release CACHE STRING
|
|
|
|
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
|
|
|
|
|
ENDIF()
|
|
|
|
|
|
2013-05-08 20:21:11 +00:00
|
|
|
|
PROJECT(jsoncpp)
|
|
|
|
|
ENABLE_TESTING()
|
|
|
|
|
|
2015-02-26 09:39:40 -06:00
|
|
|
|
OPTION(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
|
2013-05-08 20:21:11 +00:00
|
|
|
|
OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
|
2013-05-09 18:42:33 +00:00
|
|
|
|
OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
|
2015-10-27 22:45:17 +01:00
|
|
|
|
OPTION(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C and ISO C++" ON)
|
2014-09-14 15:45:07 +02:00
|
|
|
|
OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
|
2018-04-05 16:37:58 -07:00
|
|
|
|
OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON)
|
2015-04-23 18:39:00 +05:30
|
|
|
|
OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
|
2013-05-08 20:21:11 +00:00
|
|
|
|
|
2016-09-22 22:05:13 -07:00
|
|
|
|
# Enable runtime search path support for dynamic libraries on OSX
|
|
|
|
|
IF(APPLE)
|
|
|
|
|
SET(CMAKE_MACOSX_RPATH 1)
|
|
|
|
|
ENDIF()
|
|
|
|
|
|
2016-12-14 17:53:10 +01:00
|
|
|
|
# Adhere to GNU filesystem layout conventions
|
|
|
|
|
INCLUDE(GNUInstallDirs)
|
|
|
|
|
|
2015-06-29 19:20:08 +01:00
|
|
|
|
SET(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build")
|
2014-11-04 12:44:48 +08:00
|
|
|
|
|
2013-05-08 20:21:11 +00:00
|
|
|
|
# Set variable named ${VAR_NAME} to value ${VALUE}
|
|
|
|
|
FUNCTION(set_using_dynamic_name VAR_NAME VALUE)
|
|
|
|
|
SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
|
2015-08-06 10:17:09 -05:00
|
|
|
|
ENDFUNCTION()
|
2013-05-08 20:21:11 +00:00
|
|
|
|
|
2014-09-18 10:06:14 -07:00
|
|
|
|
# Extract major, minor, patch from version text
|
|
|
|
|
# Parse a version string "X.Y.Z" and outputs
|
|
|
|
|
# version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH.
|
2014-09-17 20:37:59 +02:00
|
|
|
|
# If parse succeeds then ${OUPUT_PREFIX}_FOUND is TRUE.
|
2014-09-16 12:26:50 -07:00
|
|
|
|
MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
|
|
|
|
|
SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
|
|
|
|
|
IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
|
|
|
|
|
STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
|
|
|
|
|
LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
|
|
|
|
|
LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
|
|
|
|
|
LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
|
2014-09-17 20:37:59 +02:00
|
|
|
|
set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE )
|
2014-09-16 12:26:50 -07:00
|
|
|
|
ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
|
2014-09-17 20:37:59 +02:00
|
|
|
|
set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE )
|
2015-08-06 10:17:09 -05:00
|
|
|
|
ENDIF()
|
|
|
|
|
ENDMACRO()
|
2014-09-16 12:26:50 -07:00
|
|
|
|
|
|
|
|
|
# Read out version from "version" file
|
2015-03-05 18:14:58 -06:00
|
|
|
|
#FILE(STRINGS "version" JSONCPP_VERSION)
|
|
|
|
|
#SET( JSONCPP_VERSION_MAJOR X )
|
|
|
|
|
#SET( JSONCPP_VERSION_MINOR Y )
|
|
|
|
|
#SET( JSONCPP_VERSION_PATCH Z )
|
2017-12-20 14:52:26 -06:00
|
|
|
|
SET( JSONCPP_VERSION 1.8.4 )
|
2014-09-16 12:26:50 -07:00
|
|
|
|
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
|
2015-03-05 18:14:58 -06:00
|
|
|
|
#IF(NOT JSONCPP_VERSION_FOUND)
|
|
|
|
|
# MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
|
|
|
|
|
#ENDIF(NOT JSONCPP_VERSION_FOUND)
|
2017-08-28 08:45:17 -05:00
|
|
|
|
SET( JSONCPP_SOVERSION 19 )
|
2016-03-14 19:11:02 -05:00
|
|
|
|
SET( JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
|
2014-09-16 12:26:50 -07:00
|
|
|
|
|
2014-09-18 10:06:14 -07:00
|
|
|
|
MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
|
2014-09-16 12:26:50 -07:00
|
|
|
|
# File version.h is only regenerated on CMake configure step
|
|
|
|
|
CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
|
2018-04-17 16:16:54 +02:00
|
|
|
|
"${PROJECT_BINARY_DIR}/include/json/version.h"
|
2015-03-05 18:14:58 -06:00
|
|
|
|
NEWLINE_STYLE UNIX )
|
|
|
|
|
CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/version.in"
|
2018-04-17 16:16:54 +02:00
|
|
|
|
"${PROJECT_BINARY_DIR}/version"
|
2015-03-05 18:14:58 -06:00
|
|
|
|
NEWLINE_STYLE UNIX )
|
2014-09-16 12:26:50 -07:00
|
|
|
|
|
2016-12-14 17:53:10 +01:00
|
|
|
|
MACRO(UseCompilationWarningAsError)
|
|
|
|
|
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.
|
2016-12-14 17:53:10 +01:00
|
|
|
|
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
|
|
|
|
|
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
|
|
|
|
IF(JSONCPP_WITH_STRICT_ISO)
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
|
|
|
|
|
ENDIF()
|
|
|
|
|
ENDIF()
|
|
|
|
|
ENDMACRO()
|
2013-05-09 18:42:33 +00:00
|
|
|
|
|
2013-05-08 20:21:11 +00:00
|
|
|
|
# Include our configuration header
|
2014-08-09 22:21:33 +04:00
|
|
|
|
INCLUDE_DIRECTORIES( ${jsoncpp_SOURCE_DIR}/include )
|
2013-05-08 20:21:11 +00:00
|
|
|
|
|
2016-12-14 17:53:10 +01: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.
|
2016-12-14 17:53:10 +01:00
|
|
|
|
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
|
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
|
|
# Require C++11 support, prefer ISO C++ over GNU variants,
|
|
|
|
|
# as relying solely on ISO C++ is more portable.
|
|
|
|
|
SET(CMAKE_CXX_STANDARD 11)
|
|
|
|
|
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
SET(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
|
|
|
|
|
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
|
# using regular Clang or AppleClang
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare")
|
|
|
|
|
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
|
# using GCC
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra")
|
|
|
|
|
# not yet ready for -Wsign-conversion
|
|
|
|
|
|
2017-03-10 10:22:33 +05:30
|
|
|
|
IF(JSONCPP_WITH_STRICT_ISO)
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
2017-03-10 10:33:03 +05:30
|
|
|
|
ENDIF()
|
2017-03-10 10:22:33 +05:30
|
|
|
|
IF(JSONCPP_WITH_WARNING_AS_ERROR)
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion")
|
2016-12-14 17:53:10 +01:00
|
|
|
|
ENDIF()
|
|
|
|
|
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
|
|
|
|
# using Intel compiler
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra -Werror=conversion")
|
|
|
|
|
|
|
|
|
|
IF(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
|
|
|
|
ENDIF()
|
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
|
|
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 12:10:58 -05:00
|
|
|
|
|
2013-05-09 18:42:33 +00:00
|
|
|
|
IF(JSONCPP_WITH_WARNING_AS_ERROR)
|
|
|
|
|
UseCompilationWarningAsError()
|
2015-08-06 10:17:09 -05:00
|
|
|
|
ENDIF()
|
2013-05-09 18:42:33 +00:00
|
|
|
|
|
2014-09-14 15:45:07 +02:00
|
|
|
|
IF(JSONCPP_WITH_PKGCONFIG_SUPPORT)
|
2016-12-14 17:53:10 +01:00
|
|
|
|
CONFIGURE_FILE(
|
|
|
|
|
"pkg-config/jsoncpp.pc.in"
|
|
|
|
|
"pkg-config/jsoncpp.pc"
|
|
|
|
|
@ONLY)
|
|
|
|
|
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkg-config/jsoncpp.pc"
|
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
2015-08-06 10:17:09 -05:00
|
|
|
|
ENDIF()
|
2014-09-14 15:45:07 +02:00
|
|
|
|
|
2014-11-04 16:33:25 +08:00
|
|
|
|
IF(JSONCPP_WITH_CMAKE_PACKAGE)
|
|
|
|
|
INSTALL(EXPORT jsoncpp
|
2016-12-14 17:53:10 +01:00
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp
|
2014-11-04 16:33:25 +08:00
|
|
|
|
FILE jsoncppConfig.cmake)
|
2015-08-06 10:17:09 -05:00
|
|
|
|
ENDIF()
|
2014-11-04 16:33:25 +08:00
|
|
|
|
|
2013-05-08 20:21:11 +00:00
|
|
|
|
# Build the different applications
|
|
|
|
|
ADD_SUBDIRECTORY( src )
|
|
|
|
|
|
|
|
|
|
#install the includes
|
|
|
|
|
ADD_SUBDIRECTORY( include )
|