blob: 2f880805079f0d0680ec7633f81e34badf49e7ce [file] [log] [blame]
Baptiste Lepilleureafd7022013-05-08 20:21:11 +00001CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
2PROJECT(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)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +00008
9# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
10IF(NOT WIN32)
11 IF(NOT CMAKE_BUILD_TYPE)
12 SET(CMAKE_BUILD_TYPE Release CACHE STRING
13 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
14 FORCE)
15 ENDIF(NOT CMAKE_BUILD_TYPE)
16ENDIF(NOT WIN32)
17
18# This ensures shared DLL are in the same dir as executable on Windows.
19# Put all executables / libraries are in a project global directory.
20SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
21 CACHE PATH "Single directory for all static libraries.")
22SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
23 CACHE PATH "Single directory for all dynamic libraries on Unix.")
24SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
25 CACHE PATH "Single directory for all executable and dynamic libraries on Windows.")
26MARK_AS_ADVANCED( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY )
27
28# Set variable named ${VAR_NAME} to value ${VALUE}
29FUNCTION(set_using_dynamic_name VAR_NAME VALUE)
30 SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
31ENDFUNCTION(set_using_dynamic_name)
32
33# Extract major, minor, patch and qualifier from version text
34# Parse a version string "X.Y.Z[-qualifier]" and outputs
35# version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH, _QUALIFIER.
36# If parse succed then ${OUPUT_PREFIX}_FOUND is TRUE.
37MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
38 SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
39 IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
40 STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
41 list(APPEND VERSION_PARTS "") # empty qualifier to handle no qualifier case
42 LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
43 LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
44 LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
45 LIST(GET VERSION_PARTS 3 ${OUPUT_PREFIX}_QUALIFIER)
46 set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE )
47 ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
48 set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE )
49 ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
50ENDMACRO(jsoncpp_parse_version)
51
52# Read out version from "version" file
53FILE(STRINGS "version" JSONCPP_VERSION)
54
55jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
56IF(NOT JSONCPP_VERSION_FOUND)
57 MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z[-qualifier]")
58ENDIF(NOT JSONCPP_VERSION_FOUND)
59
60MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}${JSONCPP_VERSION_QUALIFIER}")
61# File version.h is only regenerated on CMake configure step
62CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
63 "${PROJECT_SOURCE_DIR}/include/json/version.h" )
64
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000065macro(UseCompilationWarningAsError)
66 if ( MSVC )
67 # Only enabled in debug because some old versions of VS STL generate
68 # warnings when compiled in release configuration.
69 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
70 endif( MSVC )
71endmacro()
72
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000073# Include our configuration header
74INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include )
75
Baptiste Lepilleur700b3802013-05-09 18:42:33 +000076if ( MSVC )
77 # Only enabled in debug because some old versions of VS STL generate
78 # unreachable code warning when compiled in release configuration.
79 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
80endif( MSVC )
81
82IF(JSONCPP_WITH_WARNING_AS_ERROR)
83 UseCompilationWarningAsError()
84ENDIF(JSONCPP_WITH_WARNING_AS_ERROR)
85
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000086# Build the different applications
87ADD_SUBDIRECTORY( src )
88
89#install the includes
90ADD_SUBDIRECTORY( include )