Don't warn on tag missing when subproject (#653) (#655)

Different solution than proposed in the issue, since that proposed
solution would given unexpected results when an intermediate
(untagged) commit is checked out.

This change simply skips warning about a missing git version when this
is a subproject, and uses the original version calculation logic.

I've also renamed `determine_version` to `determine_version_with_file`.
I'd originally done this in an intermediate version of this PR, but I
think that keeping the renaming is clearer code.
This commit is contained in:
Flaviu Tamas 2023-01-04 04:39:28 -05:00 committed by GitHub
parent e74f8b46de
commit e66750de53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -8,7 +8,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake)
set(MSG_PREFIX "etl |") set(MSG_PREFIX "etl |")
determine_version_with_git(${GIT_DIR_LOOKUP_POLICY}) determine_version_with_git(${GIT_DIR_LOOKUP_POLICY})
if(NOT ETL_VERSION) if(NOT ETL_VERSION)
determine_version("version.txt") determine_version_with_file("version.txt")
endif() endif()
project(etl VERSION ${ETL_VERSION} LANGUAGES CXX) project(etl VERSION ${ETL_VERSION} LANGUAGES CXX)

View File

@ -1,4 +1,4 @@
function(determine_version VER_FILE_NAME) function(determine_version_with_file VER_FILE_NAME)
file(READ ${VER_FILE_NAME} ETL_VERSION_RAW) file(READ ${VER_FILE_NAME} ETL_VERSION_RAW)
# Remove trailing whitespaces and/or newline # Remove trailing whitespaces and/or newline
string(STRIP ${ETL_VERSION_RAW} ETL_VERSION) string(STRIP ${ETL_VERSION_RAW} ETL_VERSION)
@ -13,7 +13,11 @@ function(determine_version_with_git)
git_describe(VERSION ${ARGN}) git_describe(VERSION ${ARGN})
string(FIND ${VERSION} "." VALID_VERSION) string(FIND ${VERSION} "." VALID_VERSION)
if(VALID_VERSION EQUAL -1) if(VALID_VERSION EQUAL -1)
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid") if(PROJECT_IS_TOP_LEVEL)
# only warn if this is the top-level project, since we may be
# building from a tarball as a subproject
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid")
endif()
return() return()
endif() endif()
message(STATUS "${MSG_PREFIX} Version string determined with git describe: ${VERSION}") message(STATUS "${MSG_PREFIX} Version string determined with git describe: ${VERSION}")