diff --git a/CMakeLists.txt b/CMakeLists.txt index e532ee9ba5..45c0eb14c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/capstone/capstone.h b/include/capstone/capstone.h index ce7698a1a3..f5882483a4 100644 --- a/include/capstone/capstone.h +++ b/include/capstone/capstone.h @@ -3,6 +3,7 @@ /* Capstone Disassembly Engine */ /* By Nguyen Anh Quynh , 2013-2016 */ +#include "version.h" #ifdef __cplusplus extern "C" { @@ -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) diff --git a/include/capstone/version.h b/include/capstone/version.h new file mode 100644 index 0000000000..684a3511a9 --- /dev/null +++ b/include/capstone/version.h @@ -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 diff --git a/pkgconfig.mk.in b/pkgconfig.mk.in new file mode 100644 index 0000000000..503fca5f39 --- /dev/null +++ b/pkgconfig.mk.in @@ -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@ diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000000..7616e784a7 --- /dev/null +++ b/version.h.in @@ -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 \ No newline at end of file