Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# (build time): re-runs git and rewrites the header.
#
# With no git available (source tarball / conan-from-recipe) it falls back to
# 0.0.0 and "unknown" git fields.
# 0.0.0 and "unknown" git fields, unless -D KICKMSG_VERSION_OVERRIDE=X.Y.Z is
# passed (e.g. by a package recipe that knows the release version).

function(_kickmsg_compute_version src_dir)
set(_describe "unknown")
Expand Down Expand Up @@ -48,6 +49,20 @@ function(_kickmsg_compute_version src_dir)
endif()
endif()

# Explicit override (release tarball / packaging, where no .git exists).
if(KICKMSG_VERSION_OVERRIDE)
string(REGEX REPLACE "^v" "" _override "${KICKMSG_VERSION_OVERRIDE}")
if(_override MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+")
set(_ver "${_override}")
if(_describe STREQUAL "unknown")
set(_describe "v${_ver}")
endif()
if(_tag STREQUAL "")
set(_tag "v${_ver}")
endif()
endif()
endif()

if(_ver MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
set(_maj "${CMAKE_MATCH_1}")
set(_min "${CMAKE_MATCH_2}")
Expand Down Expand Up @@ -98,6 +113,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND}
-D KICKMSG_VERSION_SRC=${CMAKE_CURRENT_SOURCE_DIR}
-D KICKMSG_VERSION_OUT=${KICKMSG_VERSION_H}
-D KICKMSG_VERSION_OVERRIDE=${KICKMSG_VERSION_OVERRIDE}
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cmake"
DEPENDS ${_version_deps}
COMMENT "Regenerating kickmsg/version.h from git"
Expand Down
Loading