From 9aa4681052026886b66e547e4c5be3175f98c7f2 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Tue, 16 Sep 2014 12:26:50 -0700 Subject: [PATCH] Revert "Merge branch 'no-version'" This reverts commit d9ced92d4040ee6c1475e96e18d715f99647e668, reversing changes made to d2fa664a12b478b3fd21f7659f3674c8520bf43b. Conflicts: include/json/version.h (keep) --- .gitignore | 1 + CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ src/lib_json/CMakeLists.txt | 1 + 3 files changed, 34 insertions(+) diff --git a/.gitignore b/.gitignore index aa5d4c6..60c4a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /libs/ /doc/doxyfile /dist/ +/include/json/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index eef9aaa..0e3dc28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,38 @@ FUNCTION(set_using_dynamic_name VAR_NAME VALUE) SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE) ENDFUNCTION(set_using_dynamic_name) +# Extract major, minor, patch and qualifier from version text +# Parse a version string "X.Y.Z[-qualifier]" and outputs +# version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH, _QUALIFIER. +# If parse succed then ${OUPUT_PREFIX}_FOUND is TRUE. +MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX) + SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?") + IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) + STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT}) + list(APPEND VERSION_PARTS "") # empty qualifier to handle no qualifier case + LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR) + LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR) + LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH) + LIST(GET VERSION_PARTS 3 ${OUPUT_PREFIX}_QUALIFIER) + set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE ) + ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) + set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE ) + ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) +ENDMACRO(jsoncpp_parse_version) + +# Read out version from "version" file +FILE(STRINGS "version" JSONCPP_VERSION) + +jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) +IF(NOT JSONCPP_VERSION_FOUND) + MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z[-qualifier]") +ENDIF(NOT JSONCPP_VERSION_FOUND) + +MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}${JSONCPP_VERSION_QUALIFIER}") +# File version.h is only regenerated on CMake configure step +CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in" + "${PROJECT_SOURCE_DIR}/include/json/version.h" ) + macro(UseCompilationWarningAsError) if ( MSVC ) # Only enabled in debug because some old versions of VS STL generate diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 91e1806..dc3d977 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -34,6 +34,7 @@ ADD_LIBRARY( jsoncpp_lib ${JSONCPP_LIB_TYPE} json_valueiterator.inl json_value.cpp json_writer.cpp + version.h.in ) SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp ) SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSON_CPP_VERSION} SOVERSION ${JSON_CPP_VERSION} )