blob: 8d812da28045230a4b0e56e424f5ce927a377369 [file] [log] [blame]
sergzubae5a56f2014-10-03 16:40:58 +04001CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +00002PROJECT(jsoncpp)
3ENABLE_TESTING()
4
Christopher Dunn99980942015-02-26 09:39:40 -06005OPTION(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +00006OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
Baptiste Lepilleur700b3802013-05-09 18:42:33 +00007OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
Jonas Platte62708582014-09-14 15:45:07 +02008OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
Yu Xiaoleidc84d962014-11-04 16:33:25 +08009OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000010
11# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
12IF(NOT WIN32)
13 IF(NOT CMAKE_BUILD_TYPE)
14 SET(CMAKE_BUILD_TYPE Release CACHE STRING
15 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
16 FORCE)
17 ENDIF(NOT CMAKE_BUILD_TYPE)
Jonas Platte69c324e2014-09-17 20:37:59 +020018ENDIF(NOT WIN32)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000019
Rémi Verscheldef8a3a592014-12-01 23:44:08 +010020SET(LIB_SUFFIX "" CACHE STRING "Optional arch-dependent suffix for the library installation directory")
21
Yu Xiaolei72e52232014-11-05 13:18:16 +080022SET(RUNTIME_INSTALL_DIR bin
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080023 CACHE PATH "Install dir for executables and dlls")
Rémi Verscheldef8a3a592014-12-01 23:44:08 +010024SET(ARCHIVE_INSTALL_DIR lib${LIB_SUFFIX}
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080025 CACHE PATH "Install dir for static libraries")
Rémi Verscheldef8a3a592014-12-01 23:44:08 +010026SET(LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080027 CACHE PATH "Install dir for shared libraries")
28SET(INCLUDE_INSTALL_DIR include
29 CACHE PATH "Install dir for headers")
Rémi Verscheldef8a3a592014-12-01 23:44:08 +010030SET(PACKAGE_INSTALL_DIR lib${LIB_SUFFIX}/cmake
Yu Xiaoleidc84d962014-11-04 16:33:25 +080031 CACHE PATH "Install dir for cmake package config files")
32MARK_AS_ADVANCED( RUNTIME_INSTALL_DIR ARCHIVE_INSTALL_DIR INCLUDE_INSTALL_DIR PACKAGE_INSTALL_DIR )
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080033
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000034# Set variable named ${VAR_NAME} to value ${VALUE}
35FUNCTION(set_using_dynamic_name VAR_NAME VALUE)
36 SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
Jonas Platte69c324e2014-09-17 20:37:59 +020037ENDFUNCTION(set_using_dynamic_name)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000038
Christopher Dunn0375af22014-09-18 10:06:14 -070039# Extract major, minor, patch from version text
40# Parse a version string "X.Y.Z" and outputs
41# version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH.
Jonas Platte69c324e2014-09-17 20:37:59 +020042# If parse succeeds then ${OUPUT_PREFIX}_FOUND is TRUE.
Christopher Dunn9aa46812014-09-16 12:26:50 -070043MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
44 SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
45 IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
46 STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
Christopher Dunn9aa46812014-09-16 12:26:50 -070047 LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
48 LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
49 LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
Jonas Platte69c324e2014-09-17 20:37:59 +020050 set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE )
Christopher Dunn9aa46812014-09-16 12:26:50 -070051 ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
Jonas Platte69c324e2014-09-17 20:37:59 +020052 set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE )
Christopher Dunn9aa46812014-09-16 12:26:50 -070053 ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
54ENDMACRO(jsoncpp_parse_version)
55
56# Read out version from "version" file
57FILE(STRINGS "version" JSONCPP_VERSION)
58
59jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
60IF(NOT JSONCPP_VERSION_FOUND)
Christopher Dunn0375af22014-09-18 10:06:14 -070061 MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
Christopher Dunn9aa46812014-09-16 12:26:50 -070062ENDIF(NOT JSONCPP_VERSION_FOUND)
63
Christopher Dunn0375af22014-09-18 10:06:14 -070064MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
Christopher Dunn9aa46812014-09-16 12:26:50 -070065# File version.h is only regenerated on CMake configure step
66CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
67 "${PROJECT_SOURCE_DIR}/include/json/version.h" )
68
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000069macro(UseCompilationWarningAsError)
70 if ( MSVC )
71 # Only enabled in debug because some old versions of VS STL generate
72 # warnings when compiled in release configuration.
73 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
74 endif( MSVC )
Jonas Platte69c324e2014-09-17 20:37:59 +020075endmacro()
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000076
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000077# Include our configuration header
Aleksandr Derbenevb3deb612014-08-09 22:21:33 +040078INCLUDE_DIRECTORIES( ${jsoncpp_SOURCE_DIR}/include )
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000079
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000080if ( MSVC )
81 # Only enabled in debug because some old versions of VS STL generate
82 # unreachable code warning when compiled in release configuration.
83 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
84endif( MSVC )
85
Christopher Dunnec727e22015-01-20 13:32:38 -060086if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
87 # using regular Clang or AppleClang
Christopher Dunn2bc61372015-01-24 13:42:37 -060088 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
Christopher Dunnec727e22015-01-20 13:32:38 -060089elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
90 # using GCC
Christopher Dunndd919142015-01-25 10:34:49 -060091 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -pedantic")
Christopher Dunnec727e22015-01-20 13:32:38 -060092endif()
93
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000094IF(JSONCPP_WITH_WARNING_AS_ERROR)
95 UseCompilationWarningAsError()
96ENDIF(JSONCPP_WITH_WARNING_AS_ERROR)
97
Jonas Platte62708582014-09-14 15:45:07 +020098IF(JSONCPP_WITH_PKGCONFIG_SUPPORT)
99 CONFIGURE_FILE(
100 "pkg-config/jsoncpp.pc.in"
101 "pkg-config/jsoncpp.pc"
102 @ONLY)
103 INSTALL(FILES "${CMAKE_BINARY_DIR}/pkg-config/jsoncpp.pc"
Rémi Verscheldef8a3a592014-12-01 23:44:08 +0100104 DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig")
Jonas Platte62708582014-09-14 15:45:07 +0200105ENDIF(JSONCPP_WITH_PKGCONFIG_SUPPORT)
106
Yu Xiaoleidc84d962014-11-04 16:33:25 +0800107IF(JSONCPP_WITH_CMAKE_PACKAGE)
108 INSTALL(EXPORT jsoncpp
109 DESTINATION ${PACKAGE_INSTALL_DIR}/jsoncpp
110 FILE jsoncppConfig.cmake)
111ENDIF(JSONCPP_WITH_CMAKE_PACKAGE)
112
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000113# Build the different applications
114ADD_SUBDIRECTORY( src )
115
116#install the includes
117ADD_SUBDIRECTORY( include )