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) |
| 7 | |
| 8 | # Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix |
| 9 | IF(NOT WIN32) |
| 10 | IF(NOT CMAKE_BUILD_TYPE) |
| 11 | SET(CMAKE_BUILD_TYPE Release CACHE STRING |
| 12 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage." |
| 13 | FORCE) |
| 14 | ENDIF(NOT CMAKE_BUILD_TYPE) |
| 15 | ENDIF(NOT WIN32) |
| 16 | |
| 17 | # This ensures shared DLL are in the same dir as executable on Windows. |
| 18 | # Put all executables / libraries are in a project global directory. |
| 19 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib |
| 20 | CACHE PATH "Single directory for all static libraries.") |
| 21 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib |
| 22 | CACHE PATH "Single directory for all dynamic libraries on Unix.") |
| 23 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin |
| 24 | CACHE PATH "Single directory for all executable and dynamic libraries on Windows.") |
| 25 | MARK_AS_ADVANCED( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY ) |
| 26 | |
| 27 | # Set variable named ${VAR_NAME} to value ${VALUE} |
| 28 | FUNCTION(set_using_dynamic_name VAR_NAME VALUE) |
| 29 | SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE) |
| 30 | ENDFUNCTION(set_using_dynamic_name) |
| 31 | |
| 32 | # Extract major, minor, patch and qualifier from version text |
| 33 | # Parse a version string "X.Y.Z[-qualifier]" and outputs |
| 34 | # version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH, _QUALIFIER. |
| 35 | # If parse succed then ${OUPUT_PREFIX}_FOUND is TRUE. |
| 36 | MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX) |
| 37 | SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?") |
| 38 | IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) |
| 39 | STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT}) |
| 40 | list(APPEND VERSION_PARTS "") # empty qualifier to handle no qualifier case |
| 41 | LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR) |
| 42 | LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR) |
| 43 | LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH) |
| 44 | LIST(GET VERSION_PARTS 3 ${OUPUT_PREFIX}_QUALIFIER) |
| 45 | set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE ) |
| 46 | ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) |
| 47 | set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE ) |
| 48 | ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) |
| 49 | ENDMACRO(jsoncpp_parse_version) |
| 50 | |
| 51 | # Read out version from "version" file |
| 52 | FILE(STRINGS "version" JSONCPP_VERSION) |
| 53 | |
| 54 | jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) |
| 55 | IF(NOT JSONCPP_VERSION_FOUND) |
| 56 | MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z[-qualifier]") |
| 57 | ENDIF(NOT JSONCPP_VERSION_FOUND) |
| 58 | |
| 59 | MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}${JSONCPP_VERSION_QUALIFIER}") |
| 60 | # File version.h is only regenerated on CMake configure step |
| 61 | CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in" |
| 62 | "${PROJECT_SOURCE_DIR}/include/json/version.h" ) |
| 63 | |
| 64 | # Include our configuration header |
| 65 | INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include ) |
| 66 | |
| 67 | # Build the different applications |
| 68 | ADD_SUBDIRECTORY( src ) |
| 69 | |
| 70 | #install the includes |
| 71 | ADD_SUBDIRECTORY( include ) |