How to force a static archive to be recreated when another file changes

Thanks for the hint, but it doesn’t make a difference. Neither setting it to ON/OFF nor undefined.

Given the documentation for OPTIMIZE_DEPENDENCIES, I thought maybe i can force a file-level dependency by adding a custom_command indirection, but that didn’t help either.

This was my attempt:

cmake_minimum_required(VERSION 3.16)
project(proj LANGUAGES CXX)

# Allow using response files.
if(APPLE)
    set(CMAKE_CXX_ARCHIVE_CREATE "libtool -o <TARGET> <LINK_FLAGS> <OBJECTS>")
endif()

set(cpp_file "${CMAKE_CURRENT_BINARY_DIR}/core.cpp")
file(CONFIGURE OUTPUT "${cpp_file}" CONTENT "int core() { return 1;}")

set(response_file "${CMAKE_CURRENT_BINARY_DIR}/response_file.rsp")
set(response_file_fake "${CMAKE_CURRENT_BINARY_DIR}/response_file_fake.txt")
file(CONFIGURE OUTPUT "${response_file}" CONTENT "-v")

add_custom_command(
    OUTPUT "${response_file_fake}"
    COMMAND ${CMAKE_COMMAND} -E touch "${response_file_fake}"
    DEPENDS "${response_file}"
)

add_library(foo STATIC "${cpp_file}")
target_sources(foo PRIVATE "${response_file_fake}" "${response_file}")
set_target_properties(foo PROPERTIES STATIC_LIBRARY_OPTIONS "@${response_file}")

touching the response file still doesn’t force archive recreation, even though the custom_command rule is triggered.