Skip to content

Commit

Permalink
Some CMake handling improvements (#538)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
robamu authored May 17, 2022
1 parent 7bb39b5 commit ba1db8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
10 changes: 5 additions & 5 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}")
Expand All @@ -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()

0 comments on commit ba1db8b

Please sign in to comment.