Skip to content

Commit

Permalink
Just shove the version generation stuff directly into the CMake file
Browse files Browse the repository at this point in the history
  • Loading branch information
InfoTeddy committed Jul 11, 2024
1 parent 32d0dc5 commit 1a9341c
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions desktop_version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,49 @@ if(NOT OFFICIAL_BUILD)
set(VERSION_INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.in.c)
set(VERSION_OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.out.c)

add_custom_target(
GenerateVersion ALL
COMMAND ${CMAKE_COMMAND}
# These args have to be passed through, otherwise the script can't see them
# Also, these args have to come BEFORE `-P`! (Otherwise it fails with an unclear error)
-DINPUT_FILE=${VERSION_INPUT_FILE}
-DOUTPUT_FILE=${VERSION_OUTPUT_FILE}
-P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake
)
set(INPUT_FILE "${VERSION_INPUT_FILE}")
set(OUTPUT_FILE "${VERSION_OUTPUT_FILE}")

# find_package sets GIT_FOUND and GIT_EXECUTABLE
find_package(Git)

if(GIT_FOUND)
# Get interim commit and date of commit
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
OUTPUT_VARIABLE INTERIM_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%cd --date=short
OUTPUT_VARIABLE COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND "${GIT_EXECUTABLE}" branch --show-current
OUTPUT_VARIABLE BRANCH_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

# Defaults if we don't have git or its commands fail for any reason or give blanks
# For annoying CMake reasons, must use "${VAR}" syntax rather than VAR
if("${INTERIM_COMMIT}" STREQUAL "")
set(INTERIM_COMMIT "(commit?)")
endif()
if("${COMMIT_DATE}" STREQUAL "")
set(COMMIT_DATE "(date?)")
endif()
if("${BRANCH_NAME}" STREQUAL "")
set(BRANCH_NAME "(branch?)")
endif()

message(STATUS "This is interim commit ${INTERIM_COMMIT} (committed ${COMMIT_DATE}) on branch ${BRANCH_NAME}")

# Take the template file and replace the macros with what we have
configure_file(${INPUT_FILE} ${OUTPUT_FILE})

add_dependencies(VVVVVV GenerateVersion)

Expand Down

0 comments on commit 1a9341c

Please sign in to comment.