@@ -37,12 +37,6 @@ foreach(pold "") # Currently Empty
37
37
endif ()
38
38
endforeach ()
39
39
40
- # Build the library with C++11 standard support, independent from other including
41
- # software which may use a different CXX_STANDARD or CMAKE_CXX_STANDARD.
42
- set (CMAKE_CXX_STANDARD 11)
43
- set (CMAKE_CXX_EXTENSIONS OFF )
44
- set (CMAKE_CXX_STANDARD_REQUIRED ON )
45
-
46
40
# Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators.
47
41
if (NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES )
48
42
set (CMAKE_BUILD_TYPE Release CACHE STRING
@@ -59,19 +53,47 @@ if(CCACHE_EXECUTABLE)
59
53
set (CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE} " CACHE PATH "ccache" FORCE)
60
54
endif ()
61
55
56
+ # Note: project(VERSION XX) - the VERSION here is number, but VERSION in meson is string.
57
+ # Thus, it is better to be consistent.
62
58
project (JSONCPP
63
- # Note: version must be updated in three places when doing a release. This
64
- # annoying process ensures that amalgamate, CMake, and meson all report the
65
- # correct version.
66
- # 1. ./meson.build
67
- # 2. ./include/json/version.h
68
- # 3. ./CMakeLists.txt
69
- # IMPORTANT: also update the JSONCPP_SOVERSION!!
70
- VERSION 1.9.3 # <major>[.<minor>[.<patch>[.<tweak>]]]
71
59
LANGUAGES CXX)
72
60
61
+ # Set variable named ${VAR_NAME} to value ${VALUE}
62
+ function (set_using_dynamic_name VAR_NAME VALUE )
63
+ set ( "${VAR_NAME} " "${VALUE} " PARENT_SCOPE)
64
+ endfunction ()
65
+
66
+ # Extract major, minor, patch from version text
67
+ # Parse a version string "X.Y.Z" and outputs
68
+ # version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH.
69
+ # If parse succeeds then ${OUPUT_PREFIX}_FOUND is TRUE.
70
+ macro (jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
71
+ set (VERSION_REGEX "[0-9]+\\ .[0-9]+\\ .[0-9]+(-[a-zA-Z0-9_]+)?" )
72
+ if ( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
73
+ string (REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT} )
74
+ list (GET VERSION_PARTS 0 ${OUPUT_PREFIX} _MAJOR)
75
+ list (GET VERSION_PARTS 1 ${OUPUT_PREFIX} _MINOR)
76
+ list (GET VERSION_PARTS 2 ${OUPUT_PREFIX} _PATCH)
77
+ set_using_dynamic_name( "${OUPUT_PREFIX} _FOUND" TRUE )
78
+ else ( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
79
+ set_using_dynamic_name( "${OUPUT_PREFIX} _FOUND" FALSE )
80
+ endif ()
81
+ endmacro ()
82
+
83
+ # Note: version must be updated in three places when doing a release. This
84
+ # annoying process ensures that amalgamate, CMake, and meson all report the
85
+ # correct version.
86
+ # 1. ./meson.build
87
+ # 2. ./include/json/version.h
88
+ # 3. ./CMakeLists.txt
89
+ # IMPORTANT: also update the JSONCPP_SOVERSION!!
90
+ set ( JSONCPP_VERSION 00.11.0 )
91
+ set ( JSONCPP_SOVERSION 23 )
92
+ jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
73
93
message (STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR} .${JSONCPP_VERSION_MINOR} .${JSONCPP_VERSION_PATCH} " )
74
- set (JSONCPP_SOVERSION 23)
94
+ #if(NOT JSONCPP_VERSION_FOUND)
95
+ # message(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
96
+ #endif(NOT JSONCPP_VERSION_FOUND)
75
97
76
98
option (JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON )
77
99
option (JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON )
@@ -81,6 +103,36 @@ option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
81
103
option (JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON )
82
104
option (JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF )
83
105
option (BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF )
106
+ option (BUILD_WITH_CXX_11 "Build jsoncpp_lib with C++11 standard." ON )
107
+
108
+ ## To compatible with C++0x and C++1x
109
+ set (CMAKE_MINIMUN_CXX_STANDARD 98)
110
+ if (CMAKE_COMPILER_IS_GNUCXX)
111
+ set (CMAKE_CXX_COMPILER "/usr/bin/g++" )
112
+ execute_process (COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CXX_VERSION)
113
+ if (CXX_VERSION VERSION_GREATER 4.8.0)
114
+ if (BUILD_WITH_CXX_11)
115
+ set (CMAKE_CXX_STANDARD 11)
116
+ message (STATUS "Compiled with C++11(or newer) standard!" )
117
+ else ()
118
+ set (CMAKE_CXX_STANDARD 98)
119
+ message (STATUS "Compiled with C++0x standard!" )
120
+ endif ()
121
+ else ()
122
+ set (CMAKE_CXX_STANDARD 98)
123
+ message (STATUS "Compiled with C++0x standard!" )
124
+ endif ()
125
+ endif ()
126
+
127
+ if (NOT CMAKE_CXX_STANDARD)
128
+ if (BUILD_WITH_CXX_11)
129
+ set (CMAKE_CXX_STANDARD 11)
130
+ message (STATUS "Compiled with C++1x standard!" )
131
+ else ()
132
+ set (CMAKE_CXX_STANDARD 98)
133
+ message (STATUS "Compiled with C++0x standard!" )
134
+ endif ()
135
+ endif ()
84
136
85
137
# Adhere to GNU filesystem layout conventions
86
138
include (GNUInstallDirs)
@@ -127,7 +179,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
127
179
# not yet ready for -Wsign-conversion
128
180
129
181
if (JSONCPP_WITH_STRICT_ISO)
130
- add_compile_options (-Wpedantic )
182
+ add_compile_options (-Wall )
131
183
endif ()
132
184
if (JSONCPP_WITH_WARNING_AS_ERROR)
133
185
add_compile_options (-Werror=conversion)
@@ -160,7 +212,7 @@ if(JSONCPP_WITH_CMAKE_PACKAGE)
160
212
DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/jsoncpp
161
213
FILE jsoncppConfig.cmake)
162
214
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR} /jsoncppConfigVersion.cmake"
163
- VERSION ${PROJECT_VERSION }
215
+ VERSION ${JSONCPP_VERSION }
164
216
COMPATIBILITY SameMajorVersion)
165
217
install (FILES ${CMAKE_CURRENT_BINARY_DIR} /jsoncppConfigVersion.cmake
166
218
DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/jsoncpp)
0 commit comments