Skip to content

Commit 34eb982

Browse files
committed
Update version in conda recipes
Pull version automatically from git tag
1 parent 7f02657 commit 34eb982

8 files changed

Lines changed: 159 additions & 47 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Because YggdrasilRapidJSON continues to merge updates from RapidJSON, the RapidJ
99

1010
### Maintenance
1111
* Added missing option for YGGDRASIL_RAPIDJSON_CHECK_PYREFS, YGGDRASIL_RAPIDJSON_PYTHON_WRAPPER, YGGDRASIL_RAPIDJSON_BUILD_ASAN, & YGGDRASIL_RAPIDJSON_ENABLE_INSTRUMENTATION_OPT
12+
* Read version from git tags and use it to set the cmake project version and the header version, bumping if there are commits after the last tag
1213

1314
## 1.1.0.2 - 2026-05-28
1415

CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1414
endif()
1515
endif()
1616

17-
set(LIB_MAJOR_VERSION "1")
18-
set(LIB_MINOR_VERSION "1")
19-
set(LIB_PATCH_VERSION "0")
20-
set(LIB_EXTEN_VERSION "1")
21-
set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VERSION}.${LIB_EXTEN_VERSION}")
17+
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
18+
include(${CMAKE_CURRENT_SOURCE_DIR}/YggdrasilRapidJSONMacros.cmake)
19+
gitversion(LIB_VERSION_STRING "1.1.0.2")
2220

2321
PROJECT(YggdrasilRapidJSON VERSION "${LIB_VERSION_STRING}" LANGUAGES C CXX)
22+
set(PROJECT_NAME_UPPER "YGGDRASIL_RAPIDJSON")
2423
set(PROJECT_NAME_LOWER "yggdrasil_rapidjson")
2524
set(PROJECT_INCLUDE_DIR "include/yggdrasil_rapidjson")
2625

@@ -262,6 +261,14 @@ SET(CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" CACHE PATH "The directory cmake fi
262261
# Interface for export
263262
# ===============================
264263

264+
# Version header
265+
generate_version_header(
266+
${PROJECT_NAME_UPPER}
267+
${PROJECT_VERSION}
268+
${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME_LOWER}/${PROJECT_NAME_LOWER}_version.h.in
269+
${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME_LOWER}/${PROJECT_NAME_LOWER}_version.h
270+
)
271+
265272
add_library(${PROJECT_NAME} INTERFACE)
266273

267274
if (YGGDRASIL_RAPIDJSON_NEST_HEADERS)

YggdrasilRapidJSONMacros.cmake

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,59 @@ macro(yggdrasil_rapidjson_options_config OUTPUT_PREFIX)
147147
endif()
148148

149149
endmacro()
150+
151+
macro(gitversion OUTPUT_VARIABLE DEFAULT)
152+
find_package(Git)
153+
if(NOT Git_FOUND)
154+
message(STATUS "Failed to find Git cmake package, falling back to version ${DEFAULT}")
155+
set(${OUTPUT_VARIABLE} ${DEFAULT})
156+
else()
157+
# Generate a git-describe version string from Git repository tags
158+
execute_process(
159+
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
160+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
161+
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
162+
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
163+
OUTPUT_STRIP_TRAILING_WHITESPACE
164+
)
165+
if(GIT_DESCRIBE_ERROR_CODE)
166+
message(STATUS "Error getting git tag, falling back to version ${DEFAULT}")
167+
set(${OUTPUT_VARIABLE} ${DEFAULT})
168+
else()
169+
string(SUBSTRING "${GIT_DESCRIBE_VERSION}" 1 -1 GIT_DESCRIBE_VERSION)
170+
string(FIND "${GIT_DESCRIBE_VERSION}" "-" idx)
171+
if(NOT ${idx} EQUAL "-1")
172+
string(SUBSTRING "${GIT_DESCRIBE_VERSION}" 0 ${idx} GIT_DESCRIBE_VERSION)
173+
string(FIND "${GIT_DESCRIBE_VERSION}" "." idx REVERSE)
174+
math(EXPR idxp1 "${idx}+1")
175+
string(SUBSTRING "${GIT_DESCRIBE_VERSION}" ${idxp1} -1 EXTEN_VERSION)
176+
math(EXPR EXTEN_VERSION "${EXTEN_VERSION}+1")
177+
string(SUBSTRING "${GIT_DESCRIBE_VERSION}" 0 ${idx} GIT_DESCRIBE_VERSION)
178+
set(GIT_DESCRIBE_VERSION "${GIT_DESCRIBE_VERSION}.${EXTEN_VERSION}")
179+
endif()
180+
set(${OUTPUT_VARIABLE} ${GIT_DESCRIBE_VERSION})
181+
endif()
182+
endif()
183+
endmacro()
184+
185+
function(generate_version_header MACRO_PREFIX VERSION_STRING SRC DST)
186+
set(rem ${VERSION_STRING})
187+
set(idx 0)
188+
set(parts)
189+
while(NOT ${idx} EQUAL "-1")
190+
string(FIND "${rem}" "." idx)
191+
if(${idx} EQUAL "-1")
192+
list(APPEND parts "${rem}")
193+
else()
194+
string(SUBSTRING "${rem}" 0 ${idx} part)
195+
list(APPEND parts "${part}")
196+
math(EXPR idxp1 "${idx}+1")
197+
string(SUBSTRING "${rem}" ${idxp1} -1 rem)
198+
endif()
199+
endwhile()
200+
list(GET parts 0 MAJOR_VERSION)
201+
list(GET parts 1 MINOR_VERSION)
202+
list(GET parts 2 PATCH_VERSION)
203+
list(GET parts 3 EXTEN_VERSION)
204+
configure_file(${SRC} ${DST} @ONLY)
205+
endfunction()

conda.recipe/recipe.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
context:
2-
version: "1.1.0.2"
2+
version: "1.1.0.3"
33

44
package:
55
name: yggdrasil-rapidjson

include/yggdrasil_rapidjson/yggdrasil_rapidjson.h

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,53 +41,15 @@
4141
#ifndef DISABLE_YGGDRASIL_RAPIDJSON
4242
#include <complex>
4343
#endif // DISABLE_YGGDRASIL_RAPIDJSON
44+
#include "yggdrasil_rapidjson_version.h"
4445

45-
///////////////////////////////////////////////////////////////////////////////
46-
// YGGDRASIL_RAPIDJSON_VERSION_STRING
47-
//
48-
// ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt.
49-
//
50-
51-
//!@cond YGGDRASIL_RAPIDJSON_HIDDEN_FROM_DOXYGEN
52-
// token stringification
53-
#define YGGDRASIL_RAPIDJSON_STRINGIFY(x) YGGDRASIL_RAPIDJSON_DO_STRINGIFY(x)
54-
#define YGGDRASIL_RAPIDJSON_DO_STRINGIFY(x) #x
55-
46+
//!@cond @MACRO_PREFIX@_HIDDEN_FROM_DOXYGEN
5647
// token concatenation
5748
#define YGGDRASIL_RAPIDJSON_JOIN(X, Y) YGGDRASIL_RAPIDJSON_DO_JOIN(X, Y)
5849
#define YGGDRASIL_RAPIDJSON_DO_JOIN(X, Y) YGGDRASIL_RAPIDJSON_DO_JOIN2(X, Y)
5950
#define YGGDRASIL_RAPIDJSON_DO_JOIN2(X, Y) X##Y
6051
//!@endcond
6152

62-
/*! \def YGGDRASIL_RAPIDJSON_MAJOR_VERSION
63-
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
64-
\brief Major version of RapidJSON in integer
65-
that this version of YggdrasilRapidJSON is based on.
66-
*/
67-
/*! \def YGGDRASIL_RAPIDJSON_MINOR_VERSION
68-
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
69-
\brief Minor version of RapidJSON in integer
70-
that this version of YggdrasilRapidJSON is based on.
71-
*/
72-
/*! \def YGGDRASIL_RAPIDJSON_PATCH_VERSION
73-
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
74-
\brief Patch version of RapidJSON in integer
75-
that this version of YggdrasilRapidJSON is based on.
76-
*/
77-
/*! \def YGGDRASIL_RAPIDJSON_EXTEN_VERSION
78-
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
79-
\brief Version of YggdrasilRapidJSON based on RapidJSON.
80-
*/
81-
/*! \def YGGDRASIL_RAPIDJSON_VERSION_STRING
82-
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
83-
\brief Version of RapidJSON in "<major>.<minor>.<patch>.<exten>" string format.
84-
*/
85-
#define YGGDRASIL_RAPIDJSON_MAJOR_VERSION 1
86-
#define YGGDRASIL_RAPIDJSON_MINOR_VERSION 1
87-
#define YGGDRASIL_RAPIDJSON_PATCH_VERSION 0
88-
#define YGGDRASIL_RAPIDJSON_EXTEN_VERSION 1
89-
#define YGGDRASIL_RAPIDJSON_VERSION_STRING \
90-
YGGDRASIL_RAPIDJSON_STRINGIFY(YGGDRASIL_RAPIDJSON_MAJOR_VERSION.YGGDRASIL_RAPIDJSON_MINOR_VERSION.YGGDRASIL_RAPIDJSON_PATCH_VERSION.YGGDRASIL_RAPIDJSON_EXTEN_VERSION)
9153

9254
///////////////////////////////////////////////////////////////////////////////
9355
// YGGDRASIL_RAPIDJSON_NAMESPACE_(BEGIN|END)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// YGGDRASIL_RAPIDJSON_VERSION_STRING
3+
//
4+
#ifndef YGGDRASIL_RAPIDJSON_VERSION_H_
5+
#define YGGDRASIL_RAPIDJSON_VERSION_H_
6+
7+
//!@cond YGGDRASIL_RAPIDJSON_HIDDEN_FROM_DOXYGEN
8+
// token stringification
9+
#define YGGDRASIL_RAPIDJSON_STRINGIFY(x) YGGDRASIL_RAPIDJSON_DO_STRINGIFY(x)
10+
#define YGGDRASIL_RAPIDJSON_DO_STRINGIFY(x) #x
11+
//!@endcond
12+
13+
/*! \def YGGDRASIL_RAPIDJSON_MAJOR_VERSION
14+
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
15+
\brief Major version of RapidJSON in integer
16+
that this version of YggdrasilRapidJSON is based on.
17+
*/
18+
/*! \def YGGDRASIL_RAPIDJSON_MINOR_VERSION
19+
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
20+
\brief Minor version of RapidJSON in integer
21+
that this version of YggdrasilRapidJSON is based on.
22+
*/
23+
/*! \def YGGDRASIL_RAPIDJSON_PATCH_VERSION
24+
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
25+
\brief Patch version of RapidJSON in integer
26+
that this version of YggdrasilRapidJSON is based on.
27+
*/
28+
/*! \def YGGDRASIL_RAPIDJSON_EXTEN_VERSION
29+
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
30+
\brief Version of YggdrasilRapidJSON based on RapidJSON.
31+
*/
32+
/*! \def YGGDRASIL_RAPIDJSON_VERSION_STRING
33+
\ingroup YGGDRASIL_RAPIDJSON_CONFIG
34+
\brief Version of RapidJSON in "<major>.<minor>.<patch>.<exten>" string format.
35+
*/
36+
#define YGGDRASIL_RAPIDJSON_MAJOR_VERSION 1
37+
#define YGGDRASIL_RAPIDJSON_MINOR_VERSION 1
38+
#define YGGDRASIL_RAPIDJSON_PATCH_VERSION 0
39+
#define YGGDRASIL_RAPIDJSON_EXTEN_VERSION 3
40+
#define YGGDRASIL_RAPIDJSON_VERSION_STRING \
41+
YGGDRASIL_RAPIDJSON_STRINGIFY(YGGDRASIL_RAPIDJSON_MAJOR_VERSION.YGGDRASIL_RAPIDJSON_MINOR_VERSION.YGGDRASIL_RAPIDJSON_PATCH_VERSION.YGGDRASIL_RAPIDJSON_EXTEN_VERSION)
42+
43+
#endif // YGGDRASIL_RAPIDJSON_VERSION_H_
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// YGGDRASIL_RAPIDJSON_VERSION_STRING
3+
//
4+
#ifndef @MACRO_PREFIX@_VERSION_H_
5+
#define @MACRO_PREFIX@_VERSION_H_
6+
7+
//!@cond @MACRO_PREFIX@_HIDDEN_FROM_DOXYGEN
8+
// token stringification
9+
#define @MACRO_PREFIX@_STRINGIFY(x) @MACRO_PREFIX@_DO_STRINGIFY(x)
10+
#define @MACRO_PREFIX@_DO_STRINGIFY(x) #x
11+
//!@endcond
12+
13+
/*! \def @MACRO_PREFIX@_MAJOR_VERSION
14+
\ingroup @MACRO_PREFIX@_CONFIG
15+
\brief Major version of RapidJSON in integer
16+
that this version of YggdrasilRapidJSON is based on.
17+
*/
18+
/*! \def @MACRO_PREFIX@_MINOR_VERSION
19+
\ingroup @MACRO_PREFIX@_CONFIG
20+
\brief Minor version of RapidJSON in integer
21+
that this version of YggdrasilRapidJSON is based on.
22+
*/
23+
/*! \def @MACRO_PREFIX@_PATCH_VERSION
24+
\ingroup @MACRO_PREFIX@_CONFIG
25+
\brief Patch version of RapidJSON in integer
26+
that this version of YggdrasilRapidJSON is based on.
27+
*/
28+
/*! \def @MACRO_PREFIX@_EXTEN_VERSION
29+
\ingroup @MACRO_PREFIX@_CONFIG
30+
\brief Version of YggdrasilRapidJSON based on RapidJSON.
31+
*/
32+
/*! \def @MACRO_PREFIX@_VERSION_STRING
33+
\ingroup @MACRO_PREFIX@_CONFIG
34+
\brief Version of RapidJSON in "<major>.<minor>.<patch>.<exten>" string format.
35+
*/
36+
#define @MACRO_PREFIX@_MAJOR_VERSION @MAJOR_VERSION@
37+
#define @MACRO_PREFIX@_MINOR_VERSION @MINOR_VERSION@
38+
#define @MACRO_PREFIX@_PATCH_VERSION @PATCH_VERSION@
39+
#define @MACRO_PREFIX@_EXTEN_VERSION @EXTEN_VERSION@
40+
#define @MACRO_PREFIX@_VERSION_STRING \
41+
@MACRO_PREFIX@_STRINGIFY(@MACRO_PREFIX@_MAJOR_VERSION.@MACRO_PREFIX@_MINOR_VERSION.@MACRO_PREFIX@_PATCH_VERSION.@MACRO_PREFIX@_EXTEN_VERSION)
42+
43+
#endif // @MACRO_PREFIX@_VERSION_H_

recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set name = "yggdrasil-rapidjson" %}
2-
{% set version = "1.1.0.2" %}
2+
{% set version = "1.1.0.3" %}
33

44
package:
55
name: {{ name|lower }}

0 commit comments

Comments
 (0)