summaryrefslogtreecommitdiff
path: root/lldb/cmake
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2023-01-10 11:21:09 -0800
committerJonas Devlieghere <jonas@devlieghere.com>2023-01-10 11:22:47 -0800
commitf6ce39cf1d1d80699e13cd1422f60d428e5cf0ec (patch)
tree139b315ded7dd97f9c8f3736a77ec7a63e0f9e9f /lldb/cmake
parent886e92c1abf17a98abb9fb7f58bc02028a3f9a7e (diff)
downloadllvm-f6ce39cf1d1d80699e13cd1422f60d428e5cf0ec.tar.gz
[lldb] Remove tools copied into LLDB.framework before install
CMake supports building Framework bundles for Apple platforms. We rely on this functionality to create LLDB.framework. From CMake's perspective, a framework is associated with a single target. In reality, this is often not the case. In addition to a main library (liblldb) the frameworks often contains associated resources that are their own CMake targets, such as debugserver and lldb-argdumper. When building and using the framework to run the test suite, those binaries are expected to be in LLDB.framework. We have a function (lldb_add_to_buildtree_lldb_framework) that copies those targets into the framework. When CMake installs a framework, it copies over the content of the framework directory and "installs" the associated target. In addition to copying the target, installing also means updating the RPATH. However, the RPATH is only updated for the target associated with the framework. Everything else is naively copied over, including executables or libraries that have a different build and install RPATH. This means that those tools need to have their own install rules. If the framework is installed first, the aforementioned tools are copied over with build RPATHs from the build tree. And when the tools themselves are installed, the binaries get overwritten and the RPATHs updated to the install RPATHs. The problem is that CMake provides no guarantees when it comes to the order in which components get installed. If those tools get installed first, the inverse happens and the binaries get overwritten with the ones that have build RPATHs. lldb_add_to_buildtree_lldb_framework has a comment correctly stating that those copied binaries should be removed before install. This patch adds a custom target (lldb-framework-cleanup) that will be run before the install phase and remove those files from LLDB.framework in the build tree. Differential revision: https://reviews.llvm.org/D141021
Diffstat (limited to 'lldb/cmake')
-rw-r--r--lldb/cmake/modules/AddLLDB.cmake10
-rw-r--r--lldb/cmake/modules/LLDBConfig.cmake14
2 files changed, 24 insertions, 0 deletions
diff --git a/lldb/cmake/modules/AddLLDB.cmake b/lldb/cmake/modules/AddLLDB.cmake
index ea52b47d6d72..a5be4afb40fb 100644
--- a/lldb/cmake/modules/AddLLDB.cmake
+++ b/lldb/cmake/modules/AddLLDB.cmake
@@ -243,6 +243,16 @@ function(lldb_add_to_buildtree_lldb_framework name subdir)
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}> ${copy_dest}
COMMENT "Copy ${name} to ${copy_dest}"
)
+
+ # Create a custom target to remove the copy again from LLDB.framework in the
+ # build tree.
+ # Intentionally use remove_directory because the target can be a either a
+ # file or directory and using remove_directory is harmless for files.
+ add_custom_target(${name}-cleanup
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${copy_dest}
+ COMMENT "Removing ${name} from LLDB.framework")
+ add_dependencies(lldb-framework-cleanup
+ ${name}-cleanup)
endfunction()
# Add extra install steps for dSYM creation and stripping for the given target.
diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index f3f1103d244f..ebb1eec8464a 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -101,6 +101,20 @@ if(LLDB_BUILD_FRAMEWORK)
# Essentially, emit the framework's dSYM outside of the framework directory.
set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING
"Directory to emit dSYM files stripped from executables and libraries (Darwin Only)")
+
+ # Custom target to remove the targets (binaries, directories) that were
+ # copied into LLDB.framework in the build tree.
+ #
+ # These targets need to be removed before the install phase because otherwise
+ # because otherwise they may overwrite already installed binaries with the
+ # wrong RPATH (i.e. build RPATH instead of install RPATH).
+ #
+ # This target needs to be created here (rather than in API/CMakeLists.txt)
+ # because add_lldb_tool creates the custom rules to copy the binaries before
+ # the framework target exists and that's the only place where this is
+ # tracked.
+ add_custom_target(lldb-framework-cleanup
+ COMMENT "Cleaning up build-tree frameworks in preparation for install")
endif()
if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode)