diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -596,6 +596,21 @@ llvm_externalize_debuginfo(${name}) llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS}) endif() + # clang and newer versions of ninja use high-resolutions timestamps, + # but older versions of libtool on Darwin don't, so the archive will + # often get an older timestamp than the last object that was added + # or updated. To fix this, we add a custom command to touch archive + # after it's been built so that ninja won't rebuild it unnecessarily + # the next time it's run. + if(ARG_STATIC AND + (CMAKE_GENERATOR STREQUAL "Ninja" AND + (CMAKE_SYSTEM_NAME MATCHES "Darwin" AND + CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER "15.6.0"))) + add_custom_command(TARGET ${name} + POST_BUILD + COMMAND touch ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} + ) + endif() endfunction() function(add_llvm_install_targets target)