[build] Add better version info to the binary for debugging purposes

This commit is contained in:
Marko Viitanen 2022-05-02 20:51:24 +03:00
parent 6b3dd245f6
commit dc83d15ea7
3 changed files with 56 additions and 8 deletions

View file

@ -6,10 +6,6 @@ HOMEPAGE_URL https://github.com/ultravideo/uvg266
DESCRIPTION "An open-source VVC encoder licensed under 3-clause BSD" DESCRIPTION "An open-source VVC encoder licensed under 3-clause BSD"
VERSION 0.2.3 ) VERSION 0.2.3 )
# Apply dynamic info to the config files
configure_file("${PROJECT_SOURCE_DIR}/src/uvg266.pc.in" "${PROJECT_SOURCE_DIR}/src/uvg266.pc" @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/src/version.h.in" "${PROJECT_SOURCE_DIR}/src/version.h" @ONLY)
option(BUILD_SHARED_LIBS "Build using shared uvg266 library" ON) option(BUILD_SHARED_LIBS "Build using shared uvg266 library" ON)
option(BUILD_TESTS "Build tests" ON) option(BUILD_TESTS "Build tests" ON)
@ -17,7 +13,7 @@ option(BUILD_TESTS "Build tests" ON)
find_package(Git QUIET) find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed # Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON) option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE) if(GIT_SUBMODULE)
message(STATUS "Submodule update") message(STATUS "Submodule update")
@ -28,12 +24,61 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(WARNING "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") message(WARNING "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif() endif()
endif() endif()
# Check git hash and fetch tag
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_HEAD_OK
OUTPUT_VARIABLE GIT_HEAD)
if(GIT_HEAD_OK EQUAL "0")
string(SUBSTRING ${GIT_HEAD} 0 30 GIT_TAG_LONG)
execute_process(COMMAND ${GIT_EXECUTABLE} name-rev --tags --name-only ${GIT_TAG_LONG}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_TAG_OK
OUTPUT_VARIABLE GIT_TAG)
string(SUBSTRING ${GIT_TAG} 0 9 GIT_TAG_STRIP)
# If tag is not defined, add part of the commit hash to the version
if(GIT_TAG_OK EQUAL "0" AND GIT_TAG_STRIP STREQUAL "undefined")
string(SUBSTRING ${GIT_HEAD} 0 7 GIT_TAG_SHORT)
set(PROJECT_VERSION ${PROJECT_VERSION}-${GIT_TAG_SHORT})
message(INFO " No tag detected, version changed to ${PROJECT_VERSION}")
endif()
endif()
endif() endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/greatest/greatest.h") if(NOT EXISTS "${PROJECT_SOURCE_DIR}/greatest/greatest.h")
message(WARNING "The submodule greatest was not loaded, some tests may fail") message(WARNING "The submodule greatest was not loaded, some tests may fail")
endif() endif()
# Grab <year>-<month>-<day> timestamp for debug purposes
string(TIMESTAMP CMAKE_BUILD_DATE %Y-%m-%d)
# Format compiler info based on platform
set(UVG_COMPILER_VERSION "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}")
if(MSVC)
if(MSVC_VERSION LESS 1800)
set(UVG_COMPILER_VERSION "VS")
elseif(MSVC_VERSION LESS 1900)
set(UVG_COMPILER_VERSION "VS2013")
elseif(MSVC_VERSION LESS 1910)
set(UVG_COMPILER_VERSION "VS2015")
elseif(MSVC_VERSION LESS 1920)
set(UVG_COMPILER_VERSION "VS2017")
elseif(MSVC_VERSION LESS 1930)
set(UVG_COMPILER_VERSION "VS2019")
else()
set(UVG_COMPILER_VERSION "VS2022")
endif()
endif()
# Set compiler info to print at runtime
set(UVG_COMPILER_STRING "${UVG_COMPILER_VERSION}")
# Apply dynamic info to the config files
configure_file("${PROJECT_SOURCE_DIR}/src/uvg266.pc.in" "${PROJECT_SOURCE_DIR}/src/uvg266.pc" @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/src/version.h.in" "${PROJECT_SOURCE_DIR}/src/version.h" @ONLY)
# Add all sources in src/ base # Add all sources in src/ base
file(GLOB LIB_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} "src/*.h" "src/*.c") file(GLOB LIB_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} "src/*.h" "src/*.c")

View file

@ -385,8 +385,9 @@ void cmdline_opts_free(const uvg_api *const api, cmdline_opts_t *opts)
void print_usage(void) void print_usage(void)
{ {
print_version();
fprintf(stdout, fprintf(stdout,
"uvg266 usage: -i and --input-res to set input, -o to set output\n" "usage: -i and --input-res to set input, -o to set output\n"
" --help for more information\n"); " --help for more information\n");
} }
@ -394,13 +395,13 @@ void print_usage(void)
void print_version(void) void print_version(void)
{ {
fprintf(stdout, fprintf(stdout,
"uvg266 " VERSION_STRING "\n" "uvg266 " VERSION_STRING " [" UVG_COMPILER_STRING "] " UVG_COMPILE_DATE "\n");
"uvg266 license: 3-clause BSD\n");
} }
void print_help(void) void print_help(void)
{ {
print_version();
fprintf(stdout, fprintf(stdout,
"Usage:\n" "Usage:\n"
"uvg266 -i <input> --input-res <width>x<height> -o <output>\n" "uvg266 -i <input> --input-res <width>x<height> -o <output>\n"

View file

@ -34,4 +34,6 @@
#ifndef UVG_VERSION #ifndef UVG_VERSION
#define UVG_VERSION @PROJECT_VERSION@ #define UVG_VERSION @PROJECT_VERSION@
#endif #endif
#define UVG_COMPILER_STRING "@UVG_COMPILER_STRING@"
#define UVG_COMPILE_DATE "@CMAKE_BUILD_DATE@"
#define VERSION_STRING QUOTE_EXPAND(UVG_VERSION) #define VERSION_STRING QUOTE_EXPAND(UVG_VERSION)