Skip to content

Commit

Permalink
Use git describe string when possible
Browse files Browse the repository at this point in the history
* Display git describe string in tr31-tool version output when possible
* Use git describe string for CPack package version when possible. Some
  generators use CPACK_PACKAGE_VERSION more than others.
  • Loading branch information
leonlynch committed Dec 3, 2022
1 parent b793c0a commit f00ee2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")

# Determine version string (use git describe string if possible)
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.git)
find_package(Git)

if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_DESCRIBE_FAILED
OUTPUT_VARIABLE GIT_DESCRIBE_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(GIT_DESCRIBE_FAILED)
message(WARNING "Failed to obtain git describe string (${GIT_DESCRIBE_FAILED})")
else()
message(STATUS "Using git describe string \"${GIT_DESCRIBE_STRING}\"")
set(TR31_VERSION_STRING ${GIT_DESCRIBE_STRING})
endif()
endif()
endif()
if(NOT TR31_VERSION_STRING)
# Otherwise use project version
set(TR31_VERSION_STRING ${tr31_VERSION})
endif()

# Configure testing before adding subdirectories
if(TR31_IS_TOP_LEVEL)
# Configure Valgrind before including CTest module
Expand Down Expand Up @@ -167,6 +193,7 @@ endif()

# configure CPack to generate .tgz package
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_VERSION "${TR31_VERSION_STRING}")
set(CPACK_PACKAGE_VENDOR "OpenEMV")
set(CPACK_PACKAGE_CONTACT "lynch.leon@gmail.com")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
Expand Down
2 changes: 1 addition & 1 deletion src/tr31_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef TR31_CONFIG_H
#define TR31_CONFIG_H

#define TR31_LIB_VERSION_STRING "@CMAKE_PROJECT_VERSION@"
#define TR31_LIB_VERSION_STRING "@TR31_VERSION_STRING@"
#cmakedefine HAVE_ARPA_INET_H
#cmakedefine HAVE_WINSOCK_H

Expand Down

0 comments on commit f00ee2b

Please sign in to comment.