1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

CMake: update version on each compiling

This commit is contained in:
Ivan Romanov 2018-02-09 21:45:50 +05:00 committed by Arseniy Shestakov
parent c1138d9df7
commit 3c1c72319b
4 changed files with 21 additions and 9 deletions

View File

@ -28,9 +28,6 @@ project(VCMI)
# - Try to get rid of FOLDER override with define_property
# It's used currently to make sure that 3rd-party dependencies in git submodules get proper FOLDER property
# - Make FindFuzzyLite check for the right version and disable FORCE_BUNDLED_FL by default
# - Find a way to regenerate Version.cpp before each build.
# PRE_BUILD only work for some generators.
# So for now commit hash only updated when CMake reconfigured.
############################################
# User-provided options #
@ -88,10 +85,9 @@ define_property(
# Generate Version.cpp
if(ENABLE_GITVERSION)
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Version.cpp.in" "${CMAKE_BINARY_DIR}/Version.cpp" @ONLY)
vcmi_print_git_commit_hash()
add_custom_target(update_version ALL
COMMAND ${CMAKE_COMMAND} -DGIT_SHA1="${GIT_SHA1}" -P "${CMAKE_MODULE_PATH}/Version.cmake"
)
else()
add_definitions(-DVCMI_NO_EXTRA_VERSION)
endif(ENABLE_GITVERSION)

View File

@ -40,7 +40,7 @@ set(__get_git_revision_description YES)
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_PARENT_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
@ -110,7 +110,7 @@ function(git_describe _var)
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_LIST_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE

View File

@ -0,0 +1,6 @@
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
include(GetGitRevisionDescription)
include(VCMIUtils)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
configure_file("${CMAKE_CURRENT_LIST_DIR}/../Version.cpp.in" "Version.cpp" @ONLY)
vcmi_print_git_commit_hash()

View File

@ -156,6 +156,11 @@ set(lib_SRCS
${VCMILIB_ADDITIONAL_SOURCES}
)
# Version.cpp is a generated file
set_source_files_properties(${CMAKE_BINARY_DIR}/Version.cpp
PROPERTIES GENERATED TRUE
)
set(lib_HEADERS
StdInc.h
../Global.h
@ -363,4 +368,9 @@ add_custom_command(TARGET vcmi POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Mods ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/Mods
)
# Update version before vcmi compiling
if(TARGET update_version)
add_dependencies(vcmi update_version)
endif()
install(TARGETS vcmi RUNTIME DESTINATION ${LIB_DIR} LIBRARY DESTINATION ${LIB_DIR})