blob: 62bf20396fa9c10f616a4c70f92f94936b59ad36 [file] [log] [blame]
Christopher Dunn295e73f2015-03-05 18:14:58 -06001# vim: et ts=4 sts=4 sw=4 tw=0
2
sergzubae5a56f2014-10-03 16:40:58 +04003CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +00004PROJECT(jsoncpp)
5ENABLE_TESTING()
6
Christopher Dunn99980942015-02-26 09:39:40 -06007OPTION(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +00008OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
Baptiste Lepilleur700b3802013-05-09 18:42:33 +00009OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
Jonas Platte62708582014-09-14 15:45:07 +020010OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
Yu Xiaoleidc84d962014-11-04 16:33:25 +080011OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF)
Gaurav30bb4cc2015-04-23 18:39:00 +053012OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
13OPTION(BUILD_STATIC_LIBS "Build jsoncpp_lib static library." ON)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000014
15# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
16IF(NOT WIN32)
17 IF(NOT CMAKE_BUILD_TYPE)
18 SET(CMAKE_BUILD_TYPE Release CACHE STRING
19 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
20 FORCE)
21 ENDIF(NOT CMAKE_BUILD_TYPE)
Jonas Platte69c324e2014-09-17 20:37:59 +020022ENDIF(NOT WIN32)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000023
Martyn Gigg717c7912015-06-29 19:20:08 +010024SET(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build")
Rémi Verscheldef8a3a592014-12-01 23:44:08 +010025SET(LIB_SUFFIX "" CACHE STRING "Optional arch-dependent suffix for the library installation directory")
26
Yu Xiaolei72e52232014-11-05 13:18:16 +080027SET(RUNTIME_INSTALL_DIR bin
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080028 CACHE PATH "Install dir for executables and dlls")
Michał Górnye6f1cff2015-05-19 17:32:31 +020029SET(ARCHIVE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080030 CACHE PATH "Install dir for static libraries")
Michał Górnye6f1cff2015-05-19 17:32:31 +020031SET(LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080032 CACHE PATH "Install dir for shared libraries")
Michał Górnye6f1cff2015-05-19 17:32:31 +020033SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080034 CACHE PATH "Install dir for headers")
Rémi Verscheldef8a3a592014-12-01 23:44:08 +010035SET(PACKAGE_INSTALL_DIR lib${LIB_SUFFIX}/cmake
Yu Xiaoleidc84d962014-11-04 16:33:25 +080036 CACHE PATH "Install dir for cmake package config files")
37MARK_AS_ADVANCED( RUNTIME_INSTALL_DIR ARCHIVE_INSTALL_DIR INCLUDE_INSTALL_DIR PACKAGE_INSTALL_DIR )
Yu Xiaolei1c3a20d2014-11-04 12:44:48 +080038
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000039# 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
Christopher Dunn295e73f2015-03-05 18:14:58 -060062#FILE(STRINGS "version" JSONCPP_VERSION)
63#SET( JSONCPP_VERSION_MAJOR X )
64#SET( JSONCPP_VERSION_MINOR Y )
65#SET( JSONCPP_VERSION_PATCH Z )
Christopher Dunnd84702c2015-07-23 00:20:35 -050066SET( JSONCPP_VERSION 1.6.5 )
Christopher Dunn9aa46812014-09-16 12:26:50 -070067jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
Christopher Dunn295e73f2015-03-05 18:14:58 -060068#IF(NOT JSONCPP_VERSION_FOUND)
69# MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
70#ENDIF(NOT JSONCPP_VERSION_FOUND)
Christopher Dunn9aa46812014-09-16 12:26:50 -070071
Christopher Dunn0375af22014-09-18 10:06:14 -070072MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
Christopher Dunn9aa46812014-09-16 12:26:50 -070073# File version.h is only regenerated on CMake configure step
74CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
Christopher Dunn295e73f2015-03-05 18:14:58 -060075 "${PROJECT_SOURCE_DIR}/include/json/version.h"
76 NEWLINE_STYLE UNIX )
77CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/version.in"
78 "${PROJECT_SOURCE_DIR}/version"
79 NEWLINE_STYLE UNIX )
Christopher Dunn9aa46812014-09-16 12:26:50 -070080
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000081macro(UseCompilationWarningAsError)
82 if ( MSVC )
83 # Only enabled in debug because some old versions of VS STL generate
84 # warnings when compiled in release configuration.
85 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
86 endif( MSVC )
Jonas Platte69c324e2014-09-17 20:37:59 +020087endmacro()
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000088
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000089# Include our configuration header
Aleksandr Derbenevb3deb612014-08-09 22:21:33 +040090INCLUDE_DIRECTORIES( ${jsoncpp_SOURCE_DIR}/include )
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000091
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000092if ( MSVC )
93 # Only enabled in debug because some old versions of VS STL generate
94 # unreachable code warning when compiled in release configuration.
95 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
96endif( MSVC )
97
Christopher Dunnec727e22015-01-20 13:32:38 -060098if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
99 # using regular Clang or AppleClang
Jörg Kraused7b84f62015-07-30 23:47:05 +0200100 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion")
Christopher Dunnec727e22015-01-20 13:32:38 -0600101elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
102 # using GCC
Jörg Kraused7b84f62015-07-30 23:47:05 +0200103 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -pedantic")
Christopher Dunn7275e3c2015-07-12 12:49:57 -0500104 # not yet ready for -Wsign-conversion
Christopher Dunnec727e22015-01-20 13:32:38 -0600105endif()
106
Baptiste Lepilleur700b3802013-05-09 18:42:33 +0000107IF(JSONCPP_WITH_WARNING_AS_ERROR)
108 UseCompilationWarningAsError()
109ENDIF(JSONCPP_WITH_WARNING_AS_ERROR)
110
Jonas Platte62708582014-09-14 15:45:07 +0200111IF(JSONCPP_WITH_PKGCONFIG_SUPPORT)
112 CONFIGURE_FILE(
113 "pkg-config/jsoncpp.pc.in"
114 "pkg-config/jsoncpp.pc"
115 @ONLY)
116 INSTALL(FILES "${CMAKE_BINARY_DIR}/pkg-config/jsoncpp.pc"
Rémi Verscheldef8a3a592014-12-01 23:44:08 +0100117 DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig")
Jonas Platte62708582014-09-14 15:45:07 +0200118ENDIF(JSONCPP_WITH_PKGCONFIG_SUPPORT)
119
Yu Xiaoleidc84d962014-11-04 16:33:25 +0800120IF(JSONCPP_WITH_CMAKE_PACKAGE)
121 INSTALL(EXPORT jsoncpp
122 DESTINATION ${PACKAGE_INSTALL_DIR}/jsoncpp
123 FILE jsoncppConfig.cmake)
124ENDIF(JSONCPP_WITH_CMAKE_PACKAGE)
125
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000126# Build the different applications
127ADD_SUBDIRECTORY( src )
128
129#install the includes
130ADD_SUBDIRECTORY( include )