Skip to content

Commit

Permalink
Add dependency from git-describe.h to DFHackVersion.cpp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
suokko committed Jul 13, 2018
1 parent c82532f commit b3b23e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 14 additions & 3 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions library/git-describe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
Expand Down

0 comments on commit b3b23e8

Please sign in to comment.