From ba1db8b55ba4fbfe2d0a6ca4f7aba4e7d26a88f1 Mon Sep 17 00:00:00 2001 From: Robin Mueller <31589589+robamu@users.noreply.github.com> Date: Tue, 17 May 2022 18:08:18 +0200 Subject: [PATCH] Some CMake handling improvements (#538) * Some CMake handling improvements - Set version from version.txt file if git retrieval fails - Add FORCE flag to ETL_VERSION CACHE entry setting. The user should not have any reason to set this entry from the command line * correction for cache entry text * a little bit more context information * message prefix for info printout Co-authored-by: Robin Mueller --- CMakeLists.txt | 4 ++++ cmake/helpers.cmake | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9b33a5db..51cf9eddd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,11 @@ cmake_minimum_required(VERSION 3.5.0) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake) +set(MSG_PREFIX "etl |") determine_version_with_git(${GIT_DIR_LOOKUP_POLICY}) +if(NOT ETL_VERSION) + determine_version("version.txt") +endif() project(etl VERSION ${ETL_VERSION}) diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index 72e6017eb..f27189d9e 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -3,9 +3,9 @@ function(determine_version VER_FILE_NAME) # Remove trailing whitespaces and/or newline string(STRIP ${ETL_VERSION_RAW} ETL_VERSION) set(ETL_VERSION ${ETL_VERSION} CACHE STRING - "ETL version determined from version.txt" + "ETL version determined from version.txt" FORCE ) - message(STATUS "Determined ETL version ${ETL_VERSION} from version.txt file") + message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from version.txt file") endfunction() function(determine_version_with_git) @@ -16,7 +16,7 @@ function(determine_version_with_git) message(WARNING "Version string ${VERSION} retrieved with git describe is invalid") return() endif() - message(STATUS ${VERSION}) + message(STATUS "${MSG_PREFIX} Version string determined with git describe: ${VERSION}") # Parse the version information into pieces. string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}") string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}") @@ -25,7 +25,7 @@ function(determine_version_with_git) set(ETL_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") set(ETL_VERSION ${ETL_VERSION} CACHE STRING - "ETL version determined from version.txt" + "ETL version determined with git describe" FORCE ) - message(STATUS "Determined ETL version ${ETL_VERSION} from the git tag") + message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from the git tag") endfunction()