Derive program version from last commit

This commit is contained in:
Marius Greuel 2022-01-03 12:29:59 +01:00
parent aa2f132b24
commit 12a67554d9
3 changed files with 59 additions and 7 deletions

View File

@ -21,7 +21,7 @@
# cmake --build build
cmake_minimum_required(VERSION 3.12)
project(avrdude VERSION 6.99.20211218)
project(avrdude VERSION 6.99)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
@ -40,8 +40,53 @@ include(GNUInstallDirs)
include(FindPackageMessage)
set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
set(AVRDUDE_FULL_VERSION ${CMAKE_PROJECT_VERSION})
set(AVRDUDE_EXTERNAL_PATH "${PROJECT_SOURCE_DIR}/external")
# =====================================
# Get Git commit info
# =====================================
# GIT_COMMIT_HASH -> hash of latest commit, e.g. b8b859f5
# GIT_COMMIT_DATE -> date of latest commit, e.g. 20201231
# GIT_COMMIT_YEAR -> year of latest commit, e.g. 2020
find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_HASH
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%ad --date=format:%Y%m%d
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_DATE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%ad --date=format:%Y
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_YEAR
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --tags --format=%h
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_TAG_HASH
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
# If the commit is not tagged, include the date and commit hash in the full version string.
if(NOT GIT_COMMIT_HASH STREQUAL GIT_TAG_HASH)
set(AVRDUDE_FULL_VERSION "${CMAKE_PROJECT_VERSION}-${GIT_COMMIT_DATE} (${GIT_COMMIT_HASH})")
endif()
endif()
# =====================================
# Detect flex and yacc/bison
# =====================================
@ -253,6 +298,7 @@ if (DEBUG_CMAKE)
message(STATUS "CMAKE_HOST_SYSTEM: ${CMAKE_HOST_SYSTEM}")
message(STATUS "CMAKE_SYSTEM: ${CMAKE_SYSTEM}")
message(STATUS "CONFIG_DIR: ${CONFIG_DIR}")
message(STATUS "AVRDUDE_FULL_VERSION: ${AVRDUDE_FULL_VERSION}")
message(STATUS "USE_EXTERNAL: ${USE_EXTERNAL}")
message(STATUS "USE_LIBUSBWIN32: ${USE_LIBUSBWIN32}")
message(STATUS "HAVE_LIBELF: ${HAVE_LIBELF}")

View File

@ -20,7 +20,7 @@
#include "msvc/msvc_compat.h"
#endif
#define VERSION "@PROJECT_VERSION@"
#define VERSION "@AVRDUDE_FULL_VERSION@"
/* Options */

View File

@ -28,34 +28,40 @@ BEGIN
END
#cmakedefine PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#cmakedefine PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
#cmakedefine PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#cmakedefine PROJECT_VERSION_TWEAK @PROJECT_VERSION_TWEAK@
#ifdef PROJECT_VERSION_MAJOR
#define VER_MAJOR PROJECT_VERSION_MAJOR
#else
#define VER_MAJOR 0
#endif
#cmakedefine PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
#ifdef PROJECT_VERSION_MINOR
#define VER_MINOR PROJECT_VERSION_MINOR
#else
#define VER_MINOR 0
#endif
#cmakedefine PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#ifdef PROJECT_VERSION_PATCH
#define VER_BUILD PROJECT_VERSION_PATCH
#else
#define VER_BUILD 0
#endif
#cmakedefine PROJECT_VERSION_TWEAK @PROJECT_VERSION_TWEAK@
#ifdef PROJECT_VERSION_TWEAK
#define VER_REVISION PROJECT_VERSION_TWEAK
#else
#define VER_REVISION 0
#endif
#cmakedefine GIT_COMMIT_YEAR "@GIT_COMMIT_YEAR@"
#ifdef GIT_COMMIT_YEAR
#define VER_COMMIT_YEAR GIT_COMMIT_YEAR
#else
#define VER_COMMIT_YEAR ""
#endif
#define _STR(s) #s
#define _VER_STR(a, b, c, d) _STR(a) "." _STR(b) "." _STR(c) "." _STR(d)
@ -67,7 +73,7 @@ END
#define VER_FILEDESCRIPTION_STR "AVRDUDE"
#define VER_PRODUCTNAME_STR "AVRDUDE"
#define VER_INTERNALNAME_STR "avrdude.exe"
#define VER_LEGALCOPYRIGHT_STR "\251 2021 The AVRDUDE authors"
#define VER_LEGALCOPYRIGHT_STR "\251 " VER_COMMIT_YEAR " The AVRDUDE authors"
#define VER_ORIGINALFILENAME_STR VER_INTERNALNAME_STR
#define VER_COMMENTS_STR "https://github.com/avrdudes/avrdude"
#define VER_FILETYPE VFT_APP