all: add UPX_VERSION_GIT_DESCRIBE

This commit is contained in:
Markus F.X.J. Oberhumer
2022-11-02 10:35:40 +01:00
parent 668cefec2f
commit 81e11987a2
2 changed files with 23 additions and 4 deletions
+17
View File
@@ -23,6 +23,7 @@ endif()
# determine git revision # determine git revision
set(GITREV_SHORT "") set(GITREV_SHORT "")
set(GITREV_PLUS "") set(GITREV_PLUS "")
set(GIT_DESCRIBE "")
find_package(Git) find_package(Git)
if(GIT_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV) if(GIT_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV)
execute_process( execute_process(
@@ -41,12 +42,25 @@ if(GIT_FOUND AND NOT UPX_CONFIG_DISABLE_GITREV)
else() else()
set(GITREV_SHORT "") set(GITREV_SHORT "")
endif() endif()
execute_process(
RESULT_VARIABLE result
COMMAND "${GIT_EXECUTABLE}" describe --match "v*.*.*" --tags --dirty
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GIT_DESCRIBE
)
if(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g(.+)$")
set(GIT_DESCRIBE "${CMAKE_MATCH_1}-devel.${CMAKE_MATCH_2}+git-${CMAKE_MATCH_3}")
endif()
endif() endif()
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git") # extra check if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git") # extra check
set(GITREV_SHORT "") set(GITREV_SHORT "")
endif() endif()
if(GITREV_SHORT) if(GITREV_SHORT)
message(STATUS "UPX_VERSION_GITREV = \"${GITREV_SHORT}${GITREV_PLUS}\"") message(STATUS "UPX_VERSION_GITREV = \"${GITREV_SHORT}${GITREV_PLUS}\"")
if(GIT_DESCRIBE)
message(STATUS "UPX_VERSION_GIT_DESCRIBE = \"${GIT_DESCRIBE}\"")
endif()
else() else()
message(STATUS "UPX_VERSION_GITREV: not set") message(STATUS "UPX_VERSION_GITREV: not set")
endif() endif()
@@ -142,6 +156,9 @@ target_include_directories(${t} PRIVATE vendor)
target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>) target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
if(GITREV_SHORT) if(GITREV_SHORT)
target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}") target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}")
if(GIT_DESCRIBE)
target_compile_definitions(${t} PRIVATE UPX_VERSION_GIT_DESCRIBE="${GIT_DESCRIBE}")
endif()
endif() endif()
if(NOT UPX_CONFIG_DISABLE_SANITIZE AND NOT MSVC) if(NOT UPX_CONFIG_DISABLE_SANITIZE AND NOT MSVC)
# default sanitizer for Debug builds # default sanitizer for Debug builds
+6 -4
View File
@@ -382,11 +382,13 @@ void show_version(bool one_line)
FILE *fp = stdout; FILE *fp = stdout;
const char *v; const char *v;
fprintf(fp, "upx %s\n", UPX_VERSION_STRING #if defined(UPX_VERSION_GIT_DESCRIBE)
#if defined(UPX_VERSION_GITREV) fprintf(fp, "upx %s\n", UPX_VERSION_GIT_DESCRIBE);
"-git-" UPX_VERSION_GITREV #elif defined(UPX_VERSION_GITREV)
fprintf(fp, "upx %s\n", UPX_VERSION_STRING "-git-" UPX_VERSION_GITREV);
#else
fprintf(fp, "upx %s\n", UPX_VERSION_STRING);
#endif #endif
);
if (one_line) if (one_line)
return; return;
#if (WITH_NRV) #if (WITH_NRV)