From 136a653ade792ec2e713b0302166ab59a1c91b80 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Jul 2026 20:07:41 -0700 Subject: [PATCH] cmake: prevent install_tactic.deps from triggering spurious rebuilds on reconfigure (#10102) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `z3_add_install_tactic_rule` unconditionally called `file(WRITE)` during CMake configure, updating `install_tactic.deps`'s mtime on every reconfiguration — even when the content was identical. Since `install_tactic.cpp` lists `install_tactic.deps` as a dependency, any CMake reconfigure (e.g. touching `src/api/ml/CMakeLists.txt`) caused a full rebuild of the tactic installation target. ## Change - **`cmake/z3_add_component.cmake` — `z3_add_install_tactic_rule`**: Replace unconditional `file(WRITE)` with a read-and-compare guard; the deps file is only rewritten when its content actually changes. ```cmake # Before file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps" ${_tactic_header_files}) # After set(_install_tactic_deps_file "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps") if (EXISTS "${_install_tactic_deps_file}") file(READ "${_install_tactic_deps_file}" _install_tactic_deps_old) else() set(_install_tactic_deps_old "") endif() if (NOT _install_tactic_deps_old STREQUAL "${_tactic_header_files}") file(WRITE "${_install_tactic_deps_file}" "${_tactic_header_files}") endif() ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- cmake/z3_add_component.cmake | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmake/z3_add_component.cmake b/cmake/z3_add_component.cmake index 962b02f684..e3dc2dd80c 100644 --- a/cmake/z3_add_component.cmake +++ b/cmake/z3_add_component.cmake @@ -273,7 +273,19 @@ macro(z3_add_install_tactic_rule) unset(_component_tactic_header_files) string(REPLACE ";" "\n" _tactic_header_files "${_tactic_header_files}") - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps" ${_tactic_header_files}) + # Only write the deps file if content has changed to avoid unnecessary rebuilds + # (file(WRITE) always updates the timestamp even if content is unchanged) + set(_install_tactic_deps_file "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps") + if (EXISTS "${_install_tactic_deps_file}") + file(READ "${_install_tactic_deps_file}" _install_tactic_deps_old) + else() + set(_install_tactic_deps_old "") + endif() + if (NOT _install_tactic_deps_old STREQUAL "${_tactic_header_files}") + file(WRITE "${_install_tactic_deps_file}" "${_tactic_header_files}") + endif() + unset(_install_tactic_deps_old) + unset(_install_tactic_deps_file) add_custom_command(OUTPUT "install_tactic.cpp" COMMAND "${Python3_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/mk_install_tactic_cpp.py"