Skip to content

Commit

Permalink
Set GDAL_DEV_SUFFIX to the pre-release suffix if a corresponding Git …
Browse files Browse the repository at this point in the history
…tag was found.
  • Loading branch information
SunBlack committed Nov 22, 2024
1 parent 4ab9ce5 commit 34dbb6d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cmake/helpers/GdalVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@ endif ()

if (EXISTS ${GDAL_ROOT_SOURCE_DIR}/.git)
set(GDAL_DEV_SUFFIX "dev")

# Try look in the Git tags to see if it is a special version
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" "tag" "--points-at" "HEAD"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_tags
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(git_result EQUAL 0)
# First replaces the line breaks by a ";", so we can iterate over it
string(REGEX REPLACE "\r?\n" ";" git_tags ${git_tags})
foreach(git_tag ${git_tags})
# GDAL is currently not fully compatible with Semantic Versioning 2.0.0, as there would have to be a minus before the pre-release tag, so we allow it to be omitted.
if (git_tag MATCHES "^v${GDAL_VERSION_MAJOR}.${GDAL_VERSION_MINOR}.${GDAL_VERSION_REV}-?(.*)")
# ${CMAKE_MATCH_1} contains the pre-release suffix
if (NOT CMAKE_MATCH_1)
# In case there is no pre-release suffix, it is a release version.
set(GDAL_DEV_SUFFIX "")
# Ignore further suffixes (e.g., a RC tag)
break()
else()
# Take the pre-release suffix as dev suffix. Normally there should only be one pre-release tag,
# so we don't need any logic here to compare the pre-release tags with each other. However,
# as there may still be a release tag without a pre-release suffix, we do not break the loop.
set(GDAL_DEV_SUFFIX "${CMAKE_MATCH_1}")
endif()
endif()
endforeach()
endif()
endif()
else()
set(GDAL_DEV_SUFFIX "")
endif()
Expand Down

0 comments on commit 34dbb6d

Please sign in to comment.