Skip to content

Commit 9e1843b

Browse files
committed
dynamically update version from CMake Input for releases
1 parent 5f290ca commit 9e1843b

File tree

5 files changed

+78
-22
lines changed

5 files changed

+78
-22
lines changed

CMakeLists.txt

+29-8
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,37 @@ if(NOT DEFINED PROJECT_VERSION)
2525
endif()
2626

2727
# Remove the 'v' prefix if it exists and extract the major, minor, and patch versions
28-
string(REGEX MATCH "^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)" _ ${PROJECT_VERSION})
29-
set(PROJECT_VERSION_BASE ${CMAKE_MATCH_1})
28+
# The pre-release part is optional
29+
string(REGEX MATCH "^[vV]?([0-9]+)\\.([0-9]+)\\.([0-9]+)(-(\\w+))?" _ ${PROJECT_VERSION})
30+
if(NOT CMAKE_MATCH_1 OR NOT CMAKE_MATCH_2 OR NOT CMAKE_MATCH_3)
31+
message(FATAL_ERROR "Invalid PROJECT_VERSION format. Expected format: x.y.z or x.y.z-pre")
32+
endif()
33+
34+
set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
35+
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
36+
set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
37+
set(PROJECT_VERSION_PRERELEASE ${CMAKE_MATCH_5})
38+
if(PROJECT_VERSION_PRERELEASE)
39+
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-${PROJECT_VERSION_PRERELEASE}")
40+
else()
41+
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
42+
endif()
3043

31-
# Use PROJECT_VERSION directly for CPack
32-
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
44+
project(capstone VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
45+
46+
# Overwrite the version header file
47+
configure_file(
48+
"${CMAKE_SOURCE_DIR}/version.h.in"
49+
"${CMAKE_SOURCE_DIR}/include/capstone/version.h"
50+
@ONLY
51+
)
3352

34-
# Set the project version without the pre-release identifier
35-
project(capstone VERSION ${PROJECT_VERSION_BASE})
36-
# Print the values of PROJECT_VERSION and PROJECT_VERSION_BASE
37-
message(STATUS "PROJECT_VERSION: ${CPACK_PACKAGE_VERSION} CAPSTONE_VERSION: ${PROJECT_VERSION_BASE}")
53+
# Overwrite the pkgconfig.mk file
54+
# configure_file(
55+
# "${CMAKE_SOURCE_DIR}/pkgconfig.mk.in"
56+
# "${CMAKE_SOURCE_DIR}/pkgconfig.mk"
57+
# @ONLY
58+
# )
3859

3960
set(UNIX_COMPILER_OPTIONS -Werror -Wall -Warray-bounds -Wshift-negative-value -Wreturn-type -Wformat -Wmissing-braces -Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context -Wmisleading-indentation)
4061

include/capstone/capstone.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
/* Capstone Disassembly Engine */
55
/* By Nguyen Anh Quynh <[email protected]>, 2013-2016 */
6+
#include "version.h"
67

78
#ifdef __cplusplus
89
extern "C" {
@@ -47,20 +48,6 @@ extern "C" {
4748
#define CAPSTONE_DEPRECATED
4849
#endif
4950

50-
// Capstone API version
51-
#define CS_API_MAJOR 6
52-
#define CS_API_MINOR 0
53-
54-
// Version for bleeding edge code of the Github's "next" branch.
55-
// Use this if you want the absolutely latest development code.
56-
// This version number will be bumped up whenever we have a new major change.
57-
#define CS_NEXT_VERSION 7
58-
59-
// Capstone package version
60-
#define CS_VERSION_MAJOR CS_API_MAJOR
61-
#define CS_VERSION_MINOR CS_API_MINOR
62-
#define CS_VERSION_EXTRA 0
63-
6451
/// Macro to create combined version which can be compared to
6552
/// result of cs_version() API.
6653
#define CS_MAKE_VERSION(major, minor) ((major << 8) + minor)

include/capstone/version.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef CAPSTONE_VERSION_H
2+
#define CAPSTONE_VERSION_H
3+
4+
// Capstone API version
5+
#define CS_API_MAJOR 6
6+
#define CS_API_MINOR 0
7+
#define CS_VERSION_EXTRA 0
8+
9+
// Version for bleeding edge code of the Github's "next" branch.
10+
// Use this if you want the absolutely latest development code.
11+
// This version number will be bumped up whenever we have a new major change.
12+
#define CS_NEXT_VERSION CS_API_MAJOR + 1
13+
14+
// Capstone package version
15+
#define CS_VERSION_MAJOR CS_API_MAJOR
16+
#define CS_VERSION_MINOR CS_API_MINOR
17+
18+
#endif // CAPSTONE_VERSION_H

pkgconfig.mk.in

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Package version of Capstone for Makefile.
2+
# To be used to generate capstone.pc for pkg-config
3+
4+
# version major & minor
5+
PKG_MAJOR = @PROJECT_VERSION_MAJOR@
6+
PKG_MINOR = @PROJECT_VERSION_MINOR@
7+
8+
# version bugfix level. Example: PKG_EXTRA = 1
9+
PKG_EXTRA = @PROJECT_VERSION_PATCH@
10+
11+
# version tag. Examples: rc1, b2, post1 - or just comment out for no tag
12+
PKG_TAG = @PROJECT_VERSION_PRERELEASE@

version.h.in

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef CAPSTONE_VERSION_H
2+
#define CAPSTONE_VERSION_H
3+
4+
// Capstone API version
5+
#define CS_API_MAJOR @PROJECT_VERSION_MAJOR@
6+
#define CS_API_MINOR @PROJECT_VERSION_MINOR@
7+
#define CS_VERSION_EXTRA @PROJECT_VERSION_PATCH@
8+
9+
// Version for bleeding edge code of the Github's "next" branch.
10+
// Use this if you want the absolutely latest development code.
11+
// This version number will be bumped up whenever we have a new major change.
12+
#define CS_NEXT_VERSION CS_API_MAJOR + 1
13+
14+
// Capstone package version
15+
#define CS_VERSION_MAJOR CS_API_MAJOR
16+
#define CS_VERSION_MINOR CS_API_MINOR
17+
18+
#endif // CAPSTONE_VERSION_H

0 commit comments

Comments
 (0)