From f1ab89183d25084531dace2c5af8b94c8b6af86d Mon Sep 17 00:00:00 2001 From: VintagePC <53943260+vintagepc@users.noreply.github.com> Date: Mon, 11 Sep 2023 18:24:52 -0400 Subject: [PATCH] improve handling of invalid COMMIT_DSC --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 225a5e545..1c670a757 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ include(cmake/ProjectVersion.cmake) resolve_version_variables() OPTION(ENFORCE_VERSION_MATCH "Enforce checking that configuration.h matches any parsed git tags" OFF) +OPTION(NO_TAG_IS_FATAL "If tag parsing fails, issue a fatal error" OFF) set(PROJECT_VERSION_SUFFIX "" @@ -45,7 +46,7 @@ message(STATUS "Project version description......: ${PROJECT_VERSION_FULL}") # testing # SET(FW_COMMIT_DSC "v3.13.0-1234") -if(NOT "${PROJECT_VERSION_SUFFIX}" STREQUAL "UNKNOWN") # else -> no commit hash is known... likely no git. +if(NOT "${PROJECT_VERSION_SUFFIX}" STREQUAL "UNKNOWN" AND NOT "${FW_COMMIT_DSC}" MATCHES ".+NOTFOUND\$") # else -> no commit hash is known... likely no git. string(REGEX MATCH "v([0-9]+)\.([0-9]+)\.([0-9]+)-?(${DEV_TAG_REGEX})?([0-9]+)?-([0-9]+)" TAG_VERSION "${FW_COMMIT_DSC}") if (CMAKE_MATCH_4) # Do we have a build type? @@ -83,8 +84,11 @@ MESSAGE(STATUS "These tag values will override Configuration.h") SET(PROJECT_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}.${PROJECT_VER_TAG_FLV}) SET(PROJECT_VERSION_COMMIT ${CMAKE_MATCH_6}) else(GIT_FOUND) - -MESSAGE(STATUS "Git was not found. Falling back to Configuration.h values (${PROJECT_VERSION}).") +if (NO_TAG_IS_FATAL) + MESSAGE(FATAL_ERROR "Git was not found or an error occurred parsing the tag. This is a fatal error according to the settings.") +else() + MESSAGE(STATUS "Git was not found or an error occurred parsing the tag. Falling back to Configuration.h values (${PROJECT_VERSION}).") +endif() set(FW_COMMIT_HASH "0") # Clear it, the code expects a binary... endif()