Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) |
| 2 | PROJECT(jsoncpp) |
| 3 | ENABLE_TESTING() |
| 4 | |
| 5 | OPTION(JSONCPP_WITH_TESTS "Compile and run JsonCpp test executables" ON) |
| 6 | OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON) |
Baptiste Lepilleur | 700b380 | 2013-05-09 18:42:33 +0000 | [diff] [blame] | 7 | OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF) |
Jonas Platte | 6270858 | 2014-09-14 15:45:07 +0200 | [diff] [blame] | 8 | OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON) |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 9 | |
| 10 | # Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix |
| 11 | IF(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 Platte | 69c324e | 2014-09-17 20:37:59 +0200 | [diff] [blame] | 17 | ENDIF(NOT WIN32) |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 18 | |
| 19 | # This ensures shared DLL are in the same dir as executable on Windows. |
| 20 | # Put all executables / libraries are in a project global directory. |
| 21 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib |
| 22 | CACHE PATH "Single directory for all static libraries.") |
| 23 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib |
| 24 | CACHE PATH "Single directory for all dynamic libraries on Unix.") |
| 25 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin |
| 26 | CACHE PATH "Single directory for all executable and dynamic libraries on Windows.") |
| 27 | MARK_AS_ADVANCED( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY ) |
| 28 | |
| 29 | # Set variable named ${VAR_NAME} to value ${VALUE} |
| 30 | FUNCTION(set_using_dynamic_name VAR_NAME VALUE) |
| 31 | SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE) |
Jonas Platte | 69c324e | 2014-09-17 20:37:59 +0200 | [diff] [blame] | 32 | ENDFUNCTION(set_using_dynamic_name) |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 33 | |
Christopher Dunn | 9aa4681 | 2014-09-16 12:26:50 -0700 | [diff] [blame] | 34 | # Extract major, minor, patch and qualifier from version text |
| 35 | # Parse a version string "X.Y.Z[-qualifier]" and outputs |
| 36 | # version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH, _QUALIFIER. |
Jonas Platte | 69c324e | 2014-09-17 20:37:59 +0200 | [diff] [blame] | 37 | # If parse succeeds then ${OUPUT_PREFIX}_FOUND is TRUE. |
Christopher Dunn | 9aa4681 | 2014-09-16 12:26:50 -0700 | [diff] [blame] | 38 | MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX) |
| 39 | SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?") |
| 40 | IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) |
| 41 | STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT}) |
| 42 | list(APPEND VERSION_PARTS "") # empty qualifier to handle no qualifier case |
| 43 | LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR) |
| 44 | LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR) |
| 45 | LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH) |
| 46 | LIST(GET VERSION_PARTS 3 ${OUPUT_PREFIX}_QUALIFIER) |
Jonas Platte | 69c324e | 2014-09-17 20:37:59 +0200 | [diff] [blame] | 47 | set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE ) |
Christopher Dunn | 9aa4681 | 2014-09-16 12:26:50 -0700 | [diff] [blame] | 48 | ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) |
Jonas Platte | 69c324e | 2014-09-17 20:37:59 +0200 | [diff] [blame] | 49 | set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE ) |
Christopher Dunn | 9aa4681 | 2014-09-16 12:26:50 -0700 | [diff] [blame] | 50 | ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) |
| 51 | ENDMACRO(jsoncpp_parse_version) |
| 52 | |
| 53 | # Read out version from "version" file |
| 54 | FILE(STRINGS "version" JSONCPP_VERSION) |
| 55 | |
| 56 | jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) |
| 57 | IF(NOT JSONCPP_VERSION_FOUND) |
| 58 | MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z[-qualifier]") |
| 59 | ENDIF(NOT JSONCPP_VERSION_FOUND) |
| 60 | |
| 61 | MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}${JSONCPP_VERSION_QUALIFIER}") |
| 62 | # File version.h is only regenerated on CMake configure step |
| 63 | CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in" |
| 64 | "${PROJECT_SOURCE_DIR}/include/json/version.h" ) |
| 65 | |
Baptiste Lepilleur | 700b380 | 2013-05-09 18:42:33 +0000 | [diff] [blame] | 66 | macro(UseCompilationWarningAsError) |
| 67 | if ( MSVC ) |
| 68 | # Only enabled in debug because some old versions of VS STL generate |
| 69 | # warnings when compiled in release configuration. |
| 70 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") |
| 71 | endif( MSVC ) |
Jonas Platte | 69c324e | 2014-09-17 20:37:59 +0200 | [diff] [blame] | 72 | endmacro() |
Baptiste Lepilleur | 700b380 | 2013-05-09 18:42:33 +0000 | [diff] [blame] | 73 | |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 74 | # Include our configuration header |
Aleksandr Derbenev | b3deb61 | 2014-08-09 22:21:33 +0400 | [diff] [blame] | 75 | INCLUDE_DIRECTORIES( ${jsoncpp_SOURCE_DIR}/include ) |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 76 | |
Baptiste Lepilleur | 700b380 | 2013-05-09 18:42:33 +0000 | [diff] [blame] | 77 | if ( MSVC ) |
| 78 | # Only enabled in debug because some old versions of VS STL generate |
| 79 | # unreachable code warning when compiled in release configuration. |
| 80 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ") |
| 81 | endif( MSVC ) |
| 82 | |
| 83 | IF(JSONCPP_WITH_WARNING_AS_ERROR) |
| 84 | UseCompilationWarningAsError() |
| 85 | ENDIF(JSONCPP_WITH_WARNING_AS_ERROR) |
| 86 | |
Jonas Platte | 6270858 | 2014-09-14 15:45:07 +0200 | [diff] [blame] | 87 | IF(JSONCPP_WITH_PKGCONFIG_SUPPORT) |
| 88 | CONFIGURE_FILE( |
| 89 | "pkg-config/jsoncpp.pc.in" |
| 90 | "pkg-config/jsoncpp.pc" |
| 91 | @ONLY) |
| 92 | INSTALL(FILES "${CMAKE_BINARY_DIR}/pkg-config/jsoncpp.pc" |
| 93 | DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") |
| 94 | ENDIF(JSONCPP_WITH_PKGCONFIG_SUPPORT) |
| 95 | |
Baptiste Lepilleur | eafd702 | 2013-05-08 20:21:11 +0000 | [diff] [blame] | 96 | # Build the different applications |
| 97 | ADD_SUBDIRECTORY( src ) |
| 98 | |
| 99 | #install the includes |
| 100 | ADD_SUBDIRECTORY( include ) |