Skip to content

Commit 082e37f

Browse files
committed
Cleanup versioning strategy
Currently, versioning is a mess. CMake and Meson have seperate build version number storage locations, with no way of knowing you need to have both. Plus, due to recent revisions the amalgamate script is broken unless you build first, and may still be broken afterwards. This PR fixes some issues with versioning, and adds comments clarifying what has to be done when doing a release.
1 parent 645250b commit 082e37f

File tree

7 files changed

+54
-57
lines changed

7 files changed

+54
-57
lines changed

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
6363
endif()
6464

6565
project(JSONCPP
66-
VERSION 1.9.0 # <major>[.<minor>[.<patch>[.<tweak>]]]
66+
# Note: version must be updated in three places when doing a release. This
67+
# annoying process ensures that amalgamate, CMake, and meson all report the
68+
# correct version.
69+
# 1. /meson.build
70+
# 2. /include/json/version.h
71+
# 3. /CMakeLists.txt
72+
VERSION 1.9.2 # <major>[.<minor>[.<patch>[.<tweak>]]]
6773
LANGUAGES CXX)
6874

6975
message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
@@ -89,10 +95,6 @@ set(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the libra
8995

9096
set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
9197

92-
# File version.h is only regenerated on CMake configure step
93-
configure_file( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
94-
"${PROJECT_BINARY_DIR}/include/json/version.h"
95-
NEWLINE_STYLE UNIX )
9698
configure_file( "${PROJECT_SOURCE_DIR}/version.in"
9799
"${PROJECT_BINARY_DIR}/version"
98100
NEWLINE_STYLE UNIX )

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Then,
2626
LIB_TYPE=shared
2727
#LIB_TYPE=static
2828
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
29-
#ninja -v -C build-${LIB_TYPE} test # This stopped working on my Mac.
3029
ninja -v -C build-${LIB_TYPE}
3130
cd build-${LIB_TYPE}
3231
meson test --no-rebuild --print-errorlogs

amalgamate.py

100644100755
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
"""Amalgamate json-cpp library sources into a single source and header file.
24
35
Works with python2.6+ and python3.4+.
@@ -9,6 +11,9 @@
911
import os.path
1012
import sys
1113

14+
INCLUDE_PATH = "include/json"
15+
SRC_PATH = "src/lib_json"
16+
1217
class AmalgamationFile:
1318
def __init__(self, top_dir):
1419
self.top_dir = top_dir
@@ -66,15 +71,15 @@ def amalgamate_source(source_top_dir=None,
6671
header.add_text("/// If defined, indicates that the source file is amalgamated")
6772
header.add_text("/// to prevent private header inclusion.")
6873
header.add_text("#define JSON_IS_AMALGAMATION")
69-
header.add_file("include/json/version.h")
70-
header.add_file("include/json/allocator.h")
71-
header.add_file("include/json/config.h")
72-
header.add_file("include/json/forwards.h")
73-
header.add_file("include/json/features.h")
74-
header.add_file("include/json/value.h")
75-
header.add_file("include/json/reader.h")
76-
header.add_file("include/json/writer.h")
77-
header.add_file("include/json/assertions.h")
74+
header.add_file(os.path.join(INCLUDE_PATH, "version.h"))
75+
header.add_file(os.path.join(INCLUDE_PATH, "allocator.h"))
76+
header.add_file(os.path.join(INCLUDE_PATH, "config.h"))
77+
header.add_file(os.path.join(INCLUDE_PATH, "forwards.h"))
78+
header.add_file(os.path.join(INCLUDE_PATH, "features.h"))
79+
header.add_file(os.path.join(INCLUDE_PATH, "value.h"))
80+
header.add_file(os.path.join(INCLUDE_PATH, "reader.h"))
81+
header.add_file(os.path.join(INCLUDE_PATH, "writer.h"))
82+
header.add_file(os.path.join(INCLUDE_PATH, "assertions.h"))
7883
header.add_text("#endif //ifndef JSON_AMALGAMATED_H_INCLUDED")
7984

8085
target_header_path = os.path.join(os.path.dirname(target_source_path), header_include_path)
@@ -94,8 +99,8 @@ def amalgamate_source(source_top_dir=None,
9499
header.add_text("/// If defined, indicates that the source file is amalgamated")
95100
header.add_text("/// to prevent private header inclusion.")
96101
header.add_text("#define JSON_IS_AMALGAMATION")
97-
header.add_file("include/json/config.h")
98-
header.add_file("include/json/forwards.h")
102+
header.add_file(os.path.join(INCLUDE_PATH, "config.h"))
103+
header.add_file(os.path.join(INCLUDE_PATH, "forwards.h"))
99104
header.add_text("#endif //ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED")
100105

101106
target_forward_header_path = os.path.join(os.path.dirname(target_source_path),
@@ -116,12 +121,11 @@ def amalgamate_source(source_top_dir=None,
116121
#endif
117122
""")
118123
source.add_text("")
119-
lib_json = "src/lib_json"
120-
source.add_file(os.path.join(lib_json, "json_tool.h"))
121-
source.add_file(os.path.join(lib_json, "json_reader.cpp"))
122-
source.add_file(os.path.join(lib_json, "json_valueiterator.inl"))
123-
source.add_file(os.path.join(lib_json, "json_value.cpp"))
124-
source.add_file(os.path.join(lib_json, "json_writer.cpp"))
124+
source.add_file(os.path.join(SRC_PATH, "json_tool.h"))
125+
source.add_file(os.path.join(SRC_PATH, "json_reader.cpp"))
126+
source.add_file(os.path.join(SRC_PATH, "json_valueiterator.inl"))
127+
source.add_file(os.path.join(SRC_PATH, "json_value.cpp"))
128+
source.add_file(os.path.join(SRC_PATH, "json_writer.cpp"))
125129

126130
print("Writing amalgamated source to %r" % target_source_path)
127131
source.write_to(target_source_path)

src/lib_json/version.h.in renamed to include/json/version.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
// DO NOT EDIT. This file (and "version") is a template used by the build system
2-
// (either CMake or Meson) to generate a "version.h" header file.
31
#ifndef JSON_VERSION_H_INCLUDED
42
#define JSON_VERSION_H_INCLUDED
53

6-
#define JSONCPP_VERSION_STRING "@JSONCPP_VERSION@"
7-
#define JSONCPP_VERSION_MAJOR @JSONCPP_VERSION_MAJOR@
8-
#define JSONCPP_VERSION_MINOR @JSONCPP_VERSION_MINOR@
9-
#define JSONCPP_VERSION_PATCH @JSONCPP_VERSION_PATCH@
4+
// Note: version must be updated in three places when doing a release. This
5+
// annoying process ensures that amalgamate, CMake, and meson all report the
6+
// correct version.
7+
// 1. /meson.build
8+
// 2. /include/json/version.h
9+
// 3. /CMakeLists.txt
10+
11+
#define JSONCPP_VERSION_STRING "1.9.2"
12+
#define JSONCPP_VERSION_MAJOR 1
13+
#define JSONCPP_VERSION_MINOR 9
14+
#define JSONCPP_VERSION_PATCH 2
1015
#define JSONCPP_VERSION_QUALIFIER
1116
#define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) \
1217
| (JSONCPP_VERSION_MINOR << 16) \
@@ -15,7 +20,7 @@
1520
#ifdef JSONCPP_USING_SECURE_MEMORY
1621
#undef JSONCPP_USING_SECURE_MEMORY
1722
#endif
18-
#define JSONCPP_USING_SECURE_MEMORY @JSONCPP_USE_SECURE_MEMORY@
23+
#define JSONCPP_USING_SECURE_MEMORY 0
1924
// If non-zero, the library zeroes any memory that it has allocated before
2025
// it frees its memory.
2126

meson.build

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
project(
22
'jsoncpp',
33
'cpp',
4-
version : '1.9.0',
4+
5+
# Note: version must be updated in three places when doing a release. This
6+
# annoying process ensures that amalgamate, CMake, and meson all report the
7+
# correct version.
8+
# 1. /meson.build
9+
# 2. /include/json/version.h
10+
# 3. /CMakeLists.txt
11+
12+
version : '1.9.2',
513
default_options : [
614
'buildtype=release',
715
'cpp_std=c++11',
816
'warning_level=1'],
917
license : 'Public Domain',
1018
meson_version : '>= 0.50.0')
1119

12-
jsoncpp_ver_arr = meson.project_version().split('.')
13-
jsoncpp_major_version = jsoncpp_ver_arr[0]
14-
jsoncpp_minor_version = jsoncpp_ver_arr[1]
15-
jsoncpp_patch_version = jsoncpp_ver_arr[2]
16-
17-
jsoncpp_cdata = configuration_data()
18-
jsoncpp_cdata.set('JSONCPP_VERSION', meson.project_version())
19-
jsoncpp_cdata.set('JSONCPP_VERSION_MAJOR', jsoncpp_major_version)
20-
jsoncpp_cdata.set('JSONCPP_VERSION_MINOR', jsoncpp_minor_version)
21-
jsoncpp_cdata.set('JSONCPP_VERSION_PATCH', jsoncpp_patch_version)
22-
jsoncpp_cdata.set('JSONCPP_USE_SECURE_MEMORY',0)
23-
24-
jsoncpp_gen_sources = configure_file(
25-
input : 'src/lib_json/version.h.in',
26-
output : 'version.h',
27-
configuration : jsoncpp_cdata,
28-
install : true,
29-
install_dir : join_paths(get_option('prefix'), get_option('includedir'), 'json')
30-
)
3120

3221
jsoncpp_headers = [
3322
'include/json/allocator.h',
@@ -39,6 +28,7 @@ jsoncpp_headers = [
3928
'include/json/json.h',
4029
'include/json/reader.h',
4130
'include/json/value.h',
31+
'include/json/version.h',
4232
'include/json/writer.h']
4333
jsoncpp_include_directories = include_directories('include')
4434

@@ -56,8 +46,7 @@ endif
5646

5747
jsoncpp_lib = library(
5848
'jsoncpp',
59-
[ jsoncpp_gen_sources,
60-
jsoncpp_headers,
49+
[ jsoncpp_headers,
6150
'src/lib_json/json_tool.h',
6251
'src/lib_json/json_reader.cpp',
6352
'src/lib_json/json_value.cpp',
@@ -79,7 +68,7 @@ jsoncpp_dep = declare_dependency(
7968
include_directories : jsoncpp_include_directories,
8069
link_with : jsoncpp_lib,
8170
version : meson.project_version(),
82-
sources : jsoncpp_gen_sources)
71+
)
8372

8473
# tests
8574
python = import('python3').find_python()

src/lib_json/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ set( PUBLIC_HEADERS
4545
${JSONCPP_INCLUDE_DIR}/json/features.h
4646
${JSONCPP_INCLUDE_DIR}/json/value.h
4747
${JSONCPP_INCLUDE_DIR}/json/reader.h
48+
${JSONCPP_INCLUDE_DIR}/json/version.h
4849
${JSONCPP_INCLUDE_DIR}/json/writer.h
4950
${JSONCPP_INCLUDE_DIR}/json/assertions.h
50-
${PROJECT_BINARY_DIR}/include/json/version.h
5151
)
5252

5353
source_group( "Public API" FILES ${PUBLIC_HEADERS} )
@@ -57,8 +57,7 @@ set(jsoncpp_sources
5757
json_reader.cpp
5858
json_valueiterator.inl
5959
json_value.cpp
60-
json_writer.cpp
61-
version.h.in)
60+
json_writer.cpp)
6261

6362
# Install instructions for this target
6463
if(JSONCPP_WITH_CMAKE_PACKAGE)

version.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)