mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-15 18:27:06 +00:00
Allow the CMake user to provide their own version string
This will be useful for downstream packagers, as well as rgbds-live
This commit is contained in:
+37
-27
@@ -82,35 +82,45 @@ endif()
|
|||||||
# Use versioning consistent with Makefile:
|
# Use versioning consistent with Makefile:
|
||||||
# the git revision is used but uses the fallback in an archive.
|
# the git revision is used but uses the fallback in an archive.
|
||||||
|
|
||||||
message(CHECK_START "Determining RGBDS version from Git history")
|
if(DEFINED RGBDS_VERSION_STRING) # Possibly stored in the cache, e.g. if specified on the CLI.
|
||||||
list(APPEND CMAKE_MESSAGE_INDENT " ")
|
if(RGBDS_VERSION_STRING STREQUAL "")
|
||||||
set(GIT_REV "") # This fallback is important!
|
message(STATUS "Will generate version string from `version.hpp`")
|
||||||
find_package(Git)
|
|
||||||
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
|
||||||
if(NOT Git_FOUND)
|
|
||||||
message(CHECK_FAIL "Git not found")
|
|
||||||
else()
|
|
||||||
execute_process(COMMAND "${GIT_EXECUTABLE}" --git-dir=.git -c safe.directory='*'
|
|
||||||
describe --tags --dirty --always --match "v[0-9]*"
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
ERROR_VARIABLE git_err ERROR_STRIP_TRAILING_WHITESPACE
|
|
||||||
RESULT_VARIABLE result)
|
|
||||||
if(NOT result EQUAL 0)
|
|
||||||
# Note that this happens e.g. when building from a tarball, so it shouldn't fail the build!
|
|
||||||
message(CHECK_FAIL "error ${result} from Git:")
|
|
||||||
list(APPEND CMAKE_MESSAGE_INDENT " ")
|
|
||||||
message("${git_err}")
|
|
||||||
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
|
||||||
else()
|
else()
|
||||||
message(CHECK_PASS "${GIT_REV}")
|
message(STATUS "Using provided version string - ${RGBDS_VERSION_STRING}")
|
||||||
if(NOT "${GIT_REV}" MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+(-rc[0-9]+)?")
|
endif()
|
||||||
# Can't find an ancestor tag! (That passes `--match`, anyway.)
|
else()
|
||||||
message(WARNING "No `v*` Git tag reachable; falling back")
|
message(CHECK_START "Determining RGBDS version from Git history")
|
||||||
elseif(NOT CMAKE_MATCH_0 STREQUAL "v${PROJECT_VERSION}")
|
# Note that we do NOT store this in the cache, since the Git revision is fairly volatile.
|
||||||
message(SEND_ERROR "\
|
set(RGBDS_VERSION_STRING "") # An empty value causes `version.cpp` to generate a version string.
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MESSAGE_INDENT " ")
|
||||||
|
find_package(Git)
|
||||||
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
||||||
|
if(NOT Git_FOUND)
|
||||||
|
message(CHECK_FAIL "Git not found")
|
||||||
|
else()
|
||||||
|
execute_process(COMMAND "${GIT_EXECUTABLE}" --git-dir=.git -c safe.directory='*'
|
||||||
|
describe --tags --dirty --always --match "v[0-9]*"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
OUTPUT_VARIABLE RGBDS_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_VARIABLE git_err ERROR_STRIP_TRAILING_WHITESPACE
|
||||||
|
RESULT_VARIABLE result)
|
||||||
|
if(NOT result EQUAL 0)
|
||||||
|
# Note that this happens e.g. when building from a tarball, so it shouldn't fail the build!
|
||||||
|
message(CHECK_FAIL "error ${result} from Git:")
|
||||||
|
list(APPEND CMAKE_MESSAGE_INDENT " ")
|
||||||
|
message("${git_err}")
|
||||||
|
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
||||||
|
else()
|
||||||
|
message(CHECK_PASS "${RGBDS_VERSION_STRING}")
|
||||||
|
if(NOT "${RGBDS_VERSION_STRING}" MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+(-rc[0-9]+)?")
|
||||||
|
# Can't find an ancestor tag! (That passes `--match`, anyway.)
|
||||||
|
message(WARNING "No `v*` Git tag reachable; falling back")
|
||||||
|
elseif(NOT CMAKE_MATCH_0 STREQUAL "v${PROJECT_VERSION}")
|
||||||
|
message(SEND_ERROR "\
|
||||||
Version mismatch! Git says ${CMAKE_MATCH_0},
|
Version mismatch! Git says ${CMAKE_MATCH_0},
|
||||||
version.hpp says v${PROJECT_VERSION}!")
|
version.hpp says v${PROJECT_VERSION}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ add_library(common OBJECT
|
|||||||
"util.cpp"
|
"util.cpp"
|
||||||
"version.cpp"
|
"version.cpp"
|
||||||
)
|
)
|
||||||
target_compile_definitions(common PRIVATE "BUILD_VERSION_STRING=\"${GIT_REV}\"")
|
target_compile_definitions(common PRIVATE "BUILD_VERSION_STRING=\"${RGBDS_VERSION_STRING}\"")
|
||||||
|
|
||||||
find_package(BISON 3.0.0 REQUIRED)
|
find_package(BISON 3.0.0 REQUIRED)
|
||||||
# BISON 4.0 deprecates passing this BISON_FLAGS string to `bison_target`'s `COMPILE_FLAGS`,
|
# BISON 4.0 deprecates passing this BISON_FLAGS string to `bison_target`'s `COMPILE_FLAGS`,
|
||||||
|
|||||||
Reference in New Issue
Block a user