39 lines
1.1 KiB
CMake
39 lines
1.1 KiB
CMake
cmake_minimum_required(VERSION 3.27)
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
|
|
# Original path to the target executable
|
|
set(TARGET_PATH ${TARGET_DIR}/${PROJECT_NAME})
|
|
|
|
# The name of the target we're renaming
|
|
set(TARGET "${TARGET_PATH}${TARGET_EXTENSION}")
|
|
|
|
# The command to get the version string from Git
|
|
find_package(Git REQUIRED)
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
OUTPUT_VARIABLE GIT_VERSION
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
)
|
|
|
|
if (NOT GIT_VERSION)
|
|
message(FATAL_ERROR "Could not get the Git version")
|
|
else()
|
|
|
|
# New path containing the Git version
|
|
set(VERSIONED_PATH ${TARGET_PATH}-${GIT_VERSION})
|
|
|
|
# Rename the target to include the version string
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET} "${VERSIONED_PATH}${TARGET_EXTENSION}"
|
|
)
|
|
|
|
# Rename program database file created by VS
|
|
if (EXISTS ${TARGET_PATH}.pdb)
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -E copy "${TARGET_PATH}.pdb" "${VERSIONED_PATH}.pdb"
|
|
)
|
|
endif()
|
|
endif()
|
|
|