Skip to content

Commit

Permalink
dynamically update version from CMake Input for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewQuijano committed Jan 21, 2025
1 parent 5f290ca commit 11d709d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 22 deletions.
33 changes: 25 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,33 @@ if(NOT DEFINED PROJECT_VERSION)
endif()

# Remove the 'v' prefix if it exists and extract the major, minor, and patch versions
string(REGEX MATCH "^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)" _ ${PROJECT_VERSION})
set(PROJECT_VERSION_BASE ${CMAKE_MATCH_1})
# The pre-release part is optional
string(REGEX MATCH "^[vV]?([0-9]+)\\.([0-9]+)\\.([0-9]+)(-(\\w+))?" _ ${PROJECT_VERSION})
set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
set(PROJECT_VERSION_PRERELEASE ${CMAKE_MATCH_5})
if(PROJECT_VERSION_PRERELEASE)
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-${PROJECT_VERSION_PRERELEASE}")
else()
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
endif()

# Use PROJECT_VERSION directly for CPack
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
project(capstone VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

# Overwrite the version header file
configure_file(
"${CMAKE_SOURCE_DIR}/version.h.in"
"${CMAKE_SOURCE_DIR}/include/capstone/version.h"
@ONLY
)

# Set the project version without the pre-release identifier
project(capstone VERSION ${PROJECT_VERSION_BASE})
# Print the values of PROJECT_VERSION and PROJECT_VERSION_BASE
message(STATUS "PROJECT_VERSION: ${CPACK_PACKAGE_VERSION} CAPSTONE_VERSION: ${PROJECT_VERSION_BASE}")
# Overwrite the pkgconfig.mk file
# configure_file(
# "${CMAKE_SOURCE_DIR}/pkgconfig.mk.in"
# "${CMAKE_SOURCE_DIR}/pkgconfig.mk"
# @ONLY
# )

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)

Expand Down
15 changes: 1 addition & 14 deletions include/capstone/capstone.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -47,20 +48,6 @@ extern "C" {
#define CAPSTONE_DEPRECATED
#endif

// Capstone API version
#define CS_API_MAJOR 6
#define CS_API_MINOR 0

// Version for bleeding edge code of the Github's "next" branch.
// Use this if you want the absolutely latest development code.
// This version number will be bumped up whenever we have a new major change.
#define CS_NEXT_VERSION 7

// Capstone package version
#define CS_VERSION_MAJOR CS_API_MAJOR
#define CS_VERSION_MINOR CS_API_MINOR
#define CS_VERSION_EXTRA 0

/// Macro to create combined version which can be compared to
/// result of cs_version() API.
#define CS_MAKE_VERSION(major, minor) ((major << 8) + minor)
Expand Down
18 changes: 18 additions & 0 deletions include/capstone/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef CAPSTONE_VERSION_H
#define CAPSTONE_VERSION_H

// Capstone API version
#define CS_API_MAJOR 6
#define CS_API_MINOR 0
#define CS_VERSION_EXTRA 0

// Version for bleeding edge code of the Github's "next" branch.
// Use this if you want the absolutely latest development code.
// This version number will be bumped up whenever we have a new major change.
#define CS_NEXT_VERSION CS_API_MAJOR + 1

// Capstone package version
#define CS_VERSION_MAJOR CS_API_MAJOR
#define CS_VERSION_MINOR CS_API_MINOR

#endif // CAPSTONE_VERSION_H
12 changes: 12 additions & 0 deletions pkgconfig.mk.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Package version of Capstone for Makefile.
# To be used to generate capstone.pc for pkg-config

# version major & minor
PKG_MAJOR = @PROJECT_VERSION_MAJOR@
PKG_MINOR = @PROJECT_VERSION_MINOR@

# version bugfix level. Example: PKG_EXTRA = 1
PKG_EXTRA = @PROJECT_VERSION_PATCH@

# version tag. Examples: rc1, b2, post1 - or just comment out for no tag
PKG_TAG = @PROJECT_VERSION_PRERELEASE@
18 changes: 18 additions & 0 deletions version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef CAPSTONE_VERSION_H
#define CAPSTONE_VERSION_H

// Capstone API version
#define CS_API_MAJOR @PROJECT_VERSION_MAJOR@
#define CS_API_MINOR @PROJECT_VERSION_MINOR@
#define CS_VERSION_EXTRA @PROJECT_VERSION_PATCH@

// Version for bleeding edge code of the Github's "next" branch.
// Use this if you want the absolutely latest development code.
// This version number will be bumped up whenever we have a new major change.
#define CS_NEXT_VERSION CS_API_MAJOR + 1

// Capstone package version
#define CS_VERSION_MAJOR CS_API_MAJOR
#define CS_VERSION_MINOR CS_API_MINOR

#endif // CAPSTONE_VERSION_H

0 comments on commit 11d709d

Please sign in to comment.