Only run once codegen.pl and git-describe.cmake with make

ninja has a single build file which avoided issues if multiple targets
depend on same files. But Unix Makefiles generator user recursive make
which requires each ADD_CUSTOM_COMMAND to have only one target depending
on them.

Then makefile generator also has stupid rule that it touches all
secundary output files if primary file has been updated.

It was surprising hard to find a version that actually works correctly
for both issues. Solution is using BYPRODUCTS and refactoring command
and target dependencies.

As a bonus this change now allows build to work from source tarball if
the tarball includes git-describe.h.
develop
Pauli 2018-07-08 13:32:04 +03:00
parent fad9d58ac6
commit c92b52537c
2 changed files with 23 additions and 32 deletions

@ -258,20 +258,19 @@ LIST(APPEND PROJECT_SOURCES ${GENERATED_HDRS})
FILE(GLOB GENERATE_INPUT_SCRIPTS ${dfapi_SOURCE_DIR}/xml/*.pm ${dfapi_SOURCE_DIR}/xml/*.xslt) FILE(GLOB GENERATE_INPUT_SCRIPTS ${dfapi_SOURCE_DIR}/xml/*.pm ${dfapi_SOURCE_DIR}/xml/*.xslt)
FILE(GLOB GENERATE_INPUT_XMLS ${dfapi_SOURCE_DIR}/xml/df.*.xml) FILE(GLOB GENERATE_INPUT_XMLS ${dfapi_SOURCE_DIR}/xml/df.*.xml)
STRING(REPLACE ":" " " GEN_HDRS_STR "${GENERATED_HDRS}")
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
OUTPUT ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml ${GEN_HDRS_STR} OUTPUT ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml
COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/xml/codegen.pl COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/xml/codegen.pl
${CMAKE_CURRENT_SOURCE_DIR}/xml ${CMAKE_CURRENT_SOURCE_DIR}/xml
${CMAKE_CURRENT_SOURCE_DIR}/include/df ${CMAKE_CURRENT_SOURCE_DIR}/include/df
MAIN_DEPENDENCY ${dfapi_SOURCE_DIR}/xml/codegen.pl MAIN_DEPENDENCY ${dfapi_SOURCE_DIR}/xml/codegen.pl
BYPRODUCTS ${GENERATED_HDRS}
COMMENT "Generating codegen.out.xml and df/headers" COMMENT "Generating codegen.out.xml and df/headers"
DEPENDS ${GENERATE_INPUT_XMLS} ${GENERATE_INPUT_SCRIPTS} DEPENDS ${GENERATE_INPUT_XMLS} ${GENERATE_INPUT_SCRIPTS}
) )
ADD_CUSTOM_TARGET(generate_headers ADD_CUSTOM_TARGET(generate_headers
DEPENDS ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml ${GEN_HDRS_STR}) DEPENDS ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml)
IF(REMOVE_SYMBOLS_FROM_DF_STUBS) IF(REMOVE_SYMBOLS_FROM_DF_STUBS)
IF(UNIX) IF(UNIX)
@ -325,24 +324,29 @@ ENDIF()
# always re-run git-describe if cmake is re-run (e.g. if build ID or version changes) # 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) EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake)
ADD_CUSTOM_COMMAND(OUTPUT always_rebuild if (EXISTS ${CMAKE_SOURCE_DIR}/.git/index AND EXISTS ${CMAKE_SOURCE_DIR}/.git/modules/library/xml/index)
COMMAND ${CMAKE_COMMAND} -E echo) ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/git-describe.h
COMMAND ${CMAKE_COMMAND}
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/git-describe.h -D dfhack_SOURCE_DIR:STRING=${dfhack_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -D git_describe_tmp_h:STRING=${CMAKE_CURRENT_BINARY_DIR}/git-describe.h
-D dfhack_SOURCE_DIR:STRING=${dfhack_SOURCE_DIR} -D GIT_EXECUTABLE:STRING=${GIT_EXECUTABLE}
-D git_describe_h:STRING=${CMAKE_CURRENT_SOURCE_DIR}/include/git-describe.h -D DFHACK_BUILD_ID:STRING=${DFHACK_BUILD_ID}
-D git_describe_tmp_h:STRING=${CMAKE_CURRENT_BINARY_DIR}/git-describe.h -P ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake
-D GIT_EXECUTABLE:STRING=${GIT_EXECUTABLE} COMMENT "Obtaining git commit information"
-D DFHACK_BUILD_ID:STRING=${DFHACK_BUILD_ID} DEPENDS ${CMAKE_SOURCE_DIR}/.git/index
-P ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake ${CMAKE_SOURCE_DIR}/.git/modules/library/xml/index
COMMENT "Obtaining git commit information" ${CMAKE_CURRENT_SOURCE_DIR}/git-describe.cmake
DEPENDS ${GIT_EXECUTABLE} always_rebuild )
VERBATIM ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/git-describe.h
) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/git-describe.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/git-describe.h ${CMAKE_CURRENT_SOURCE_DIR}/include/git-describe.h
COMMENT "Copy include/git-describe.h"
)
endif ()
ADD_LIBRARY(dfhack SHARED ${PROJECT_SOURCES}) ADD_LIBRARY(dfhack SHARED ${PROJECT_SOURCES})
ADD_DEPENDENCIES(dfhack generate_proto_core) ADD_DEPENDENCIES(dfhack generate_proto_core)
ADD_DEPENDENCIES(dfhack generate_headers)
ADD_LIBRARY(dfhack-client SHARED RemoteClient.cpp ColorText.cpp MiscUtils.cpp Error.cpp ${PROJECT_PROTO_SRCS}) ADD_LIBRARY(dfhack-client SHARED RemoteClient.cpp ColorText.cpp MiscUtils.cpp Error.cpp ${PROJECT_PROTO_SRCS})
ADD_DEPENDENCIES(dfhack-client dfhack) ADD_DEPENDENCIES(dfhack-client dfhack)

@ -1,14 +1,3 @@
if(NOT EXISTS ${dfhack_SOURCE_DIR}/.git/index OR NOT EXISTS ${dfhack_SOURCE_DIR}/.git/modules/library/xml/index)
MESSAGE(FATAL_ERROR "Could not find git index file(s)")
endif()
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}))
return()
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=8 --long execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=8 --long
WORKING_DIRECTORY "${dfhack_SOURCE_DIR}" WORKING_DIRECTORY "${dfhack_SOURCE_DIR}"
OUTPUT_VARIABLE DFHACK_GIT_DESCRIPTION) OUTPUT_VARIABLE DFHACK_GIT_DESCRIPTION)
@ -46,5 +35,3 @@ endif()
if(${DFHACK_GIT_XML_COMMIT} STREQUAL ${DFHACK_GIT_XML_EXPECTED_COMMIT}) if(${DFHACK_GIT_XML_COMMIT} STREQUAL ${DFHACK_GIT_XML_EXPECTED_COMMIT})
file(APPEND ${git_describe_tmp_h} "#define DFHACK_GIT_XML_MATCH\n") file(APPEND ${git_describe_tmp_h} "#define DFHACK_GIT_XML_MATCH\n")
endif() endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${git_describe_tmp_h} ${git_describe_h})