forked from mirror/openmw-tes3mp
Regenerate components/version/version.hpp as HEAD moves on a git checkout
Pull request #416 introduced a common bug where version.hpp wouldn't be regenerated every build, poteantially leading to stale version data. This commit adds a custom build target, git-version, which updates version.hpp before the components library is built.
This commit is contained in:
parent
82ef145e79
commit
3024c67995
3 changed files with 48 additions and 24 deletions
|
@ -20,33 +20,13 @@ set(OPENMW_VERSION_TAGHASH "")
|
||||||
|
|
||||||
set(OPENMW_VERSION "${OPENMW_VERSION_MAJOR}.${OPENMW_VERSION_MINOR}.${OPENMW_VERSION_RELEASE}")
|
set(OPENMW_VERSION "${OPENMW_VERSION_MAJOR}.${OPENMW_VERSION_MINOR}.${OPENMW_VERSION_RELEASE}")
|
||||||
|
|
||||||
|
set(GIT_CHECKOUT FALSE)
|
||||||
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
|
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
|
||||||
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow)
|
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow)
|
||||||
find_package(Git)
|
find_package(Git)
|
||||||
|
|
||||||
if(GIT_FOUND)
|
if(GIT_FOUND)
|
||||||
execute_process (
|
set(GIT_CHECKOUT TRUE)
|
||||||
COMMAND "${GIT_EXECUTABLE}" rev-list --tags --max-count=1
|
|
||||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
|
|
||||||
RESULT_VARIABLE EXITCODE1
|
|
||||||
OUTPUT_VARIABLE TAGHASH
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
|
|
||||||
execute_process (
|
|
||||||
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
|
|
||||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
|
|
||||||
RESULT_VARIABLE EXITCODE2
|
|
||||||
OUTPUT_VARIABLE COMMITHASH
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
|
|
||||||
string (COMPARE EQUAL "${EXITCODE1}:${EXITCODE2}" "0:0" SUCCESS)
|
|
||||||
if (SUCCESS)
|
|
||||||
set(OPENMW_VERSION_COMMITHASH "${COMMITHASH}")
|
|
||||||
set(OPENMW_VERSION_TAGHASH "${TAGHASH}")
|
|
||||||
message(STATUS "OpenMW version ${OPENMW_VERSION}")
|
|
||||||
else (SUCCESS)
|
|
||||||
message(WARNING "Failed to get valid version information from Git")
|
|
||||||
endif (SUCCESS)
|
|
||||||
else(GIT_FOUND)
|
else(GIT_FOUND)
|
||||||
message(WARNING "Git executable not found")
|
message(WARNING "Git executable not found")
|
||||||
endif(GIT_FOUND)
|
endif(GIT_FOUND)
|
||||||
|
@ -874,4 +854,3 @@ if (DOXYGEN_FOUND)
|
||||||
WORKING_DIRECTORY ${OpenMW_BINARY_DIR}
|
WORKING_DIRECTORY ${OpenMW_BINARY_DIR}
|
||||||
COMMENT "Generating documentation for the github-pages at ${DOXYGEN_PAGES_OUTPUT_DIR}" VERBATIM)
|
COMMENT "Generating documentation for the github-pages at ${DOXYGEN_PAGES_OUTPUT_DIR}" VERBATIM)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
24
cmake/GitVersion.cmake
Normal file
24
cmake/GitVersion.cmake
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
execute_process (
|
||||||
|
COMMAND ${GIT_EXECUTABLE} rev-list --tags --max-count=1
|
||||||
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
|
RESULT_VARIABLE EXITCODE1
|
||||||
|
OUTPUT_VARIABLE TAGHASH
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
execute_process (
|
||||||
|
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
||||||
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
|
RESULT_VARIABLE EXITCODE2
|
||||||
|
OUTPUT_VARIABLE COMMITHASH
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
string (COMPARE EQUAL "${EXITCODE1}:${EXITCODE2}" "0:0" SUCCESS)
|
||||||
|
if (SUCCESS)
|
||||||
|
set(OPENMW_VERSION_COMMITHASH "${COMMITHASH}")
|
||||||
|
set(OPENMW_VERSION_TAGHASH "${TAGHASH}")
|
||||||
|
message(STATUS "OpenMW version ${OPENMW_VERSION}")
|
||||||
|
else (SUCCESS)
|
||||||
|
message(WARNING "Failed to get valid version information from Git")
|
||||||
|
endif (SUCCESS)
|
||||||
|
|
||||||
|
configure_file(${VERSION_HPP_IN} ${VERSION_HPP})
|
|
@ -2,7 +2,24 @@ project (Components)
|
||||||
set (CMAKE_BUILD_TYPE DEBUG)
|
set (CMAKE_BUILD_TYPE DEBUG)
|
||||||
|
|
||||||
# Version file
|
# Version file
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version/version.hpp.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/version/version.hpp")
|
set (VERSION_HPP_IN ${CMAKE_CURRENT_SOURCE_DIR}/version/version.hpp.cmake)
|
||||||
|
set (VERSION_HPP ${CMAKE_CURRENT_SOURCE_DIR}/version/version.hpp)
|
||||||
|
if (GIT_CHECKOUT)
|
||||||
|
add_custom_target (git-version
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||||
|
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
|
||||||
|
-DVERSION_HPP_IN=${VERSION_HPP_IN}
|
||||||
|
-DVERSION_HPP=${VERSION_HPP}
|
||||||
|
-DOPENMW_VERSION_MAJOR=${OPENMW_VERSION_MAJOR}
|
||||||
|
-DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR}
|
||||||
|
-DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE}
|
||||||
|
-DOPENMW_VERSION=${OPENMW_VERSION}
|
||||||
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GitVersion.cmake
|
||||||
|
VERBATIM)
|
||||||
|
else (GIT_CHECKOUT)
|
||||||
|
configure_file(${VERSION_HPP_IN} ${VERSION_HPP})
|
||||||
|
endif (GIT_CHECKOUT)
|
||||||
|
|
||||||
# source files
|
# source files
|
||||||
|
|
||||||
|
@ -145,6 +162,10 @@ add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR})
|
||||||
|
|
||||||
target_link_libraries(components ${Boost_LIBRARIES} ${OGRE_LIBRARIES})
|
target_link_libraries(components ${Boost_LIBRARIES} ${OGRE_LIBRARIES})
|
||||||
|
|
||||||
|
if (GIT_CHECKOUT)
|
||||||
|
add_dependencies (components git-version)
|
||||||
|
endif (GIT_CHECKOUT)
|
||||||
|
|
||||||
# Fix for not visible pthreads functions for linker with glibc 2.15
|
# Fix for not visible pthreads functions for linker with glibc 2.15
|
||||||
if (UNIX AND NOT APPLE)
|
if (UNIX AND NOT APPLE)
|
||||||
target_link_libraries(components ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(components ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
|
Loading…
Reference in a new issue