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 <Robin Mueller>
This commit is contained in:
Robin Mueller 2022-05-17 18:08:18 +02:00 committed by GitHub
parent 7bb39b56bf
commit ba1db8b55b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -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})

View File

@ -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()