From 88da95573d600f2af8538c3c5a29459a1146127c Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Fri, 10 Jul 2020 15:35:17 -0700 Subject: [PATCH] Always Update Git information when rebuilding (#4696) Commit 61734b41b7b96e7e7cbf46021a357d840d64b42e changed the way some of our source files are generated. However, the change meant that once `git_versioninfo.cpp` was generated, it was never updated again: The custom command for `git_versioninfo.cpp` has no dependencies, so CMake does not rebuild it unless the output file is missing [0]. This commit reverts the change to our `gen-gitinfo` target and adds `git_versioninfo.cpp` to `BYPRODUCTS` for the target to indicate that the file may have changed. I am not sure if there is a better solution because we actually have to run `GitInfo.cmake` to see if there have been any changes in the Git information. Introducing a dependency on all source files is not sufficient because other files or just the branch name may change. Note: The original solution only updates the timestamp of `git_versioninfo.cpp` if its contents actually change (`GitInfo.cmake` uses `configure_file()` to generate `git_versioninfo.cpp`, which only updates the timestamp when the contents changed [1]), so we don't do any unnecessary work. [0] https://cmake.org/cmake/help/latest/command/add_custom_command.html [1] https://cmake.org/cmake/help/latest/command/configure_file.html Signed-off-by: Andrew V. Jones Co-authored-by: Andrew V. Jones --- src/base/CMakeLists.txt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 96b188238..a34716fea 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -4,17 +4,9 @@ find_package(Git) configure_file(GitInfo.cmake.in GitInfo.cmake @ONLY) -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/git_versioninfo.cpp - COMMAND ${CMAKE_COMMAND} -DGIT_FOUND=${GIT_FOUND} -P GitInfo.cmake -) -set_source_files_properties( - ${CMAKE_CURRENT_BINARY_DIR}/git_versioninfo.cpp - PROPERTIES GENERATED TRUE -) add_custom_target(gen-gitinfo - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/git_versioninfo.cpp -) + BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/git_versioninfo.cpp + COMMAND ${CMAKE_COMMAND} -DGIT_FOUND=${GIT_FOUND} -P GitInfo.cmake) #-----------------------------------------------------------------------------# -- 2.30.2