blob: 806e726e4d226c733793a45624966ff269fcc4db [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
5OPTION(JSONCPP_WITH_TESTS "Compile and run JsonCpp test executables" ON)
6OPTION(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)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +00009
10# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
11IF(NOT WIN32)
12 IF(NOT CMAKE_BUILD_TYPE)
13 SET(CMAKE_BUILD_TYPE Release CACHE STRING
14 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
15 FORCE)
16 ENDIF(NOT CMAKE_BUILD_TYPE)
Jonas Platte69c324e2014-09-17 20:37:59 +020017ENDIF(NOT WIN32)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000018
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080019SET(RUNTIME_INSTALL_DIR lib
20 CACHE PATH "Install dir for executables and dlls")
21SET(ARCHIVE_INSTALL_DIR lib
22 CACHE PATH "Install dir for static libraries")
23SET(LIBRARY_INSTALL_DIR lib
24 CACHE PATH "Install dir for shared libraries")
25SET(INCLUDE_INSTALL_DIR include
26 CACHE PATH "Install dir for headers")
27MARK_AS_ADVANCED( RUNTIME_INSTALL_DIR ARCHIVE_INSTALL_DIR INCLUDE_INSTALL_DIR )
28
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000029# This ensures shared DLL are in the same dir as executable on Windows.
30# Put all executables / libraries are in a project global directory.
31SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
32 CACHE PATH "Single directory for all static libraries.")
33SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
34 CACHE PATH "Single directory for all dynamic libraries on Unix.")
35SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
36 CACHE PATH "Single directory for all executable and dynamic libraries on Windows.")
37MARK_AS_ADVANCED( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY )
38
39# Set variable named ${VAR_NAME} to value ${VALUE}
40FUNCTION(set_using_dynamic_name VAR_NAME VALUE)
41 SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
Jonas Platte69c324e2014-09-17 20:37:59 +020042ENDFUNCTION(set_using_dynamic_name)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000043
Christopher Dunn0375af22014-09-18 10:06:14 -070044# Extract major, minor, patch from version text
45# Parse a version string "X.Y.Z" and outputs
46# version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH.
Jonas Platte69c324e2014-09-17 20:37:59 +020047# If parse succeeds then ${OUPUT_PREFIX}_FOUND is TRUE.
Christopher Dunn9aa46812014-09-16 12:26:50 -070048MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
49 SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
50 IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
51 STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
Christopher Dunn9aa46812014-09-16 12:26:50 -070052 LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
53 LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
54 LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
Jonas Platte69c324e2014-09-17 20:37:59 +020055 set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE )
Christopher Dunn9aa46812014-09-16 12:26:50 -070056 ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
Jonas Platte69c324e2014-09-17 20:37:59 +020057 set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE )
Christopher Dunn9aa46812014-09-16 12:26:50 -070058 ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
59ENDMACRO(jsoncpp_parse_version)
60
61# Read out version from "version" file
62FILE(STRINGS "version" JSONCPP_VERSION)
63
64jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
65IF(NOT JSONCPP_VERSION_FOUND)
Christopher Dunn0375af22014-09-18 10:06:14 -070066 MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
Christopher Dunn9aa46812014-09-16 12:26:50 -070067ENDIF(NOT JSONCPP_VERSION_FOUND)
68
Christopher Dunn0375af22014-09-18 10:06:14 -070069MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
Christopher Dunn9aa46812014-09-16 12:26:50 -070070# File version.h is only regenerated on CMake configure step
71CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
72 "${PROJECT_SOURCE_DIR}/include/json/version.h" )
73
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000074macro(UseCompilationWarningAsError)
75 if ( MSVC )
76 # Only enabled in debug because some old versions of VS STL generate
77 # warnings when compiled in release configuration.
78 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
79 endif( MSVC )
Jonas Platte69c324e2014-09-17 20:37:59 +020080endmacro()
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000081
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000082# Include our configuration header
Aleksandr Derbenevb3deb612014-08-09 22:21:33 +040083INCLUDE_DIRECTORIES( ${jsoncpp_SOURCE_DIR}/include )
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000084
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000085if ( MSVC )
86 # Only enabled in debug because some old versions of VS STL generate
87 # unreachable code warning when compiled in release configuration.
88 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
89endif( MSVC )
90
91IF(JSONCPP_WITH_WARNING_AS_ERROR)
92 UseCompilationWarningAsError()
93ENDIF(JSONCPP_WITH_WARNING_AS_ERROR)
94
Jonas Platte62708582014-09-14 15:45:07 +020095IF(JSONCPP_WITH_PKGCONFIG_SUPPORT)
96 CONFIGURE_FILE(
97 "pkg-config/jsoncpp.pc.in"
98 "pkg-config/jsoncpp.pc"
99 @ONLY)
100 INSTALL(FILES "${CMAKE_BINARY_DIR}/pkg-config/jsoncpp.pc"
101 DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
102ENDIF(JSONCPP_WITH_PKGCONFIG_SUPPORT)
103
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000104# Build the different applications
105ADD_SUBDIRECTORY( src )
106
107#install the includes
108ADD_SUBDIRECTORY( include )