Skip to content

Commit 9e5d57c

Browse files
committed
ENH: Use cmake builtin versioning capabilities
The project directive in cmake 3.1 has a builtin mechanism for providing consistent versioning in a package.
1 parent 2f2b9ce commit 9e5d57c

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

CMakeLists.txt

+8-30
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
88
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
99
endif()
1010

11-
project(jsoncpp)
11+
project(JSONCPP
12+
VERSION 1.8.4 # <major>[.<minor>[.<patch>[.<tweak>]]]
13+
LANGUAGES CXX)
14+
15+
set( JSONCPP_VERSION ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH} )
16+
message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
17+
set( JSONCPP_SOVERSION 19 )
18+
1219
enable_testing()
1320

1421
option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
@@ -34,37 +41,8 @@ function(set_using_dynamic_name VAR_NAME VALUE)
3441
set( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
3542
endfunction()
3643

37-
# Extract major, minor, patch from version text
38-
# Parse a version string "X.Y.Z" and outputs
39-
# version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH.
40-
# If parse succeeds then ${OUPUT_PREFIX}_FOUND is TRUE.
41-
macro(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
42-
set(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
43-
if( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
44-
string(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
45-
list(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
46-
list(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
47-
list(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
48-
set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE )
49-
else( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
50-
set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE )
51-
endif()
52-
endmacro()
53-
54-
# Read out version from "version" file
55-
#file(STRINGS "version" JSONCPP_VERSION)
56-
#set( JSONCPP_VERSION_MAJOR X )
57-
#set( JSONCPP_VERSION_MINOR Y )
58-
#set( JSONCPP_VERSION_PATCH Z )
59-
set( JSONCPP_VERSION 1.8.4 )
60-
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
61-
#if(NOT JSONCPP_VERSION_FOUND)
62-
# message(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
63-
#endif(NOT JSONCPP_VERSION_FOUND)
64-
set( JSONCPP_SOVERSION 19 )
6544
set( JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
6645

67-
message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
6846
# File version.h is only regenerated on CMake configure step
6947
configure_file( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
7048
"${PROJECT_BINARY_DIR}/include/json/version.h"

0 commit comments

Comments
 (0)