[CMake][runtimes] Add file level dependency to merge_archives commands

Both libc++ and libc++abi have options of merging with another archive. In the case of libc++abi, libunwind can be merged into it and in the case of libc++, libc++abi can be merged into it.

This is realized using add_custom_command with POST_BUILD and the usage of the CMake generator expression TARGET_LINKER_FILE in the arguments. For such generator expressions CMake doc states: "This target-level dependency does NOT add a file-level dependency that would cause the custom command to re-run whenever the executable is recompiled" [1]

This patch adds a DEPENDS argument to both add_custom_command invocations so that the archives also have a file-level dependency on the target they are merging with. That way, changes in say, libunwind source code, will be updated in the libc++abi and/or libc++ static libraries as well.

[1] https://cmake.org/cmake/help/v3.20/command/add_custom_command.html

Differential Revision: https://reviews.llvm.org/D98129
This commit is contained in:
Markus Böck 2021-03-18 18:51:10 +01:00
parent eb37d3546c
commit 6359049c35
2 changed files with 5 additions and 0 deletions

View File

@ -299,6 +299,9 @@ if (LIBCXX_ENABLE_STATIC)
else()
set(MERGE_ARCHIVES_ABI_TARGET
"${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_STATIC_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}")
if (LIBCXX_CXX_ABI_LIBRARY_PATH)
set(MERGE_ARCHIVES_ABI_TARGET "${LIBCXX_CXX_ABI_LIBRARY_PATH}/${MERGE_ARCHIVES_ABI_TARGET}")
endif ()
endif()
if (APPLE)
set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}")
@ -314,6 +317,7 @@ if (LIBCXX_ENABLE_STATIC)
"${MERGE_ARCHIVES_ABI_TARGET}"
"${MERGE_ARCHIVES_SEARCH_PATHS}"
WORKING_DIRECTORY ${LIBCXX_BUILD_DIR}
DEPENDS ${MERGE_ARCHIVES_ABI_TARGET}
)
endif()
endif()

View File

@ -302,6 +302,7 @@ if (LIBCXXABI_ENABLE_STATIC)
"$<TARGET_LINKER_FILE:cxxabi_static>"
"$<TARGET_LINKER_FILE:unwind_static>"
WORKING_DIRECTORY ${LIBCXXABI_BUILD_DIR}
DEPENDS unwind_static
)
endif()
endif()