Add dependency from git-describe.h to DFHackVersion.cpp

Using add_custom_command allows cmake to track dependency from command
to git-describe.h that is implicit dependency of DFHackVersion.cpp.

The change also fixes issues if there is multiple build directories and
git-describe.h missing but git-dsecribe.h.tmp is present.
develop
Pauli 2018-06-25 15:25:13 +03:00
parent c82532fd4b
commit b3b23e8278
2 changed files with 16 additions and 6 deletions

@ -297,7 +297,14 @@ ELSE(WIN32)
SET(PROJECT_LIBS psapi dfhack-md5 ${DFHACK_TINYXML} dfhack-tinythread)
ENDIF()
ADD_LIBRARY(dfhack-version STATIC DFHackVersion.cpp)
set(VERSION_SRCS DFHackVersion.cpp)
set(VERSION_HDRS git-describe.h)
SET_SOURCE_FILES_PROPERTIES(${VERSION_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE)
LIST(APPEND VERSION_SRCS ${VERSION_HDRS})
ADD_LIBRARY(dfhack-version STATIC ${VERSION_SRCS})
SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS
DFHACK_VERSION="${DFHACK_VERSION}"
DF_VERSION="${DF_VERSION}"
@ -312,15 +319,19 @@ ENDIF()
# always re-run git-describe if cmake is re-run (e.g. if build ID or version changes)
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake)
ADD_CUSTOM_TARGET(git-describe
target_include_directories(dfhack-version PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/git-describe.h always_rebuild
COMMAND ${CMAKE_COMMAND}
-D dfhack_SOURCE_DIR:STRING=${dfhack_SOURCE_DIR}
-D git_describe_h:STRING=${CMAKE_CURRENT_BINARY_DIR}/git-describe.h
-D GIT_EXECUTABLE:STRING=${GIT_EXECUTABLE}
-D DFHACK_BUILD_ID:STRING=${DFHACK_BUILD_ID}
-P ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake
COMMENT "Obtaining git commit information"
DEPENDS ${GIT_EXECUTABLE}
VERBATIM
)
ADD_DEPENDENCIES(dfhack-version git-describe)
ADD_LIBRARY(dfhack SHARED ${PROJECT_SOURCES})
ADD_DEPENDENCIES(dfhack generate_headers generate_proto_core)

@ -2,10 +2,9 @@ if(NOT EXISTS ${dfhack_SOURCE_DIR}/.git/index OR NOT EXISTS ${dfhack_SOURCE_DIR}
MESSAGE(FATAL_ERROR "Could not find git index file(s)")
endif()
set(git_describe_tmp_h ${dfhack_SOURCE_DIR}/library/include/git-describe.tmp.h)
set(git_describe_h ${dfhack_SOURCE_DIR}/library/include/git-describe.h)
set(git_describe_tmp_h ${git_describe_h}.tmp)
if(EXISTS ${git_describe_tmp_h} AND
if(EXISTS ${git_describe_tmp_h} AND EXISTS ${git_describe_h} AND
NOT(${dfhack_SOURCE_DIR}/.git/index IS_NEWER_THAN ${git_describe_tmp_h}) AND
NOT(${dfhack_SOURCE_DIR}/.git/modules/library/xml/index IS_NEWER_THAN ${git_describe_tmp_h}) AND
NOT(${dfhack_SOURCE_DIR}/library/git-describe.cmake IS_NEWER_THAN ${git_describe_tmp_h}))