Skip to content

Commit f6ce39c

Browse files
committed
[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
1 parent 886e92c commit f6ce39c

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

lldb/cmake/modules/AddLLDB.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ function(lldb_add_to_buildtree_lldb_framework name subdir)
243243
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}> ${copy_dest}
244244
COMMENT "Copy ${name} to ${copy_dest}"
245245
)
246+
247+
# Create a custom target to remove the copy again from LLDB.framework in the
248+
# build tree.
249+
# Intentionally use remove_directory because the target can be a either a
250+
# file or directory and using remove_directory is harmless for files.
251+
add_custom_target(${name}-cleanup
252+
COMMAND ${CMAKE_COMMAND} -E remove_directory ${copy_dest}
253+
COMMENT "Removing ${name} from LLDB.framework")
254+
add_dependencies(lldb-framework-cleanup
255+
${name}-cleanup)
246256
endfunction()
247257

248258
# Add extra install steps for dSYM creation and stripping for the given target.

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ if(LLDB_BUILD_FRAMEWORK)
101101
# Essentially, emit the framework's dSYM outside of the framework directory.
102102
set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING
103103
"Directory to emit dSYM files stripped from executables and libraries (Darwin Only)")
104+
105+
# Custom target to remove the targets (binaries, directories) that were
106+
# copied into LLDB.framework in the build tree.
107+
#
108+
# These targets need to be removed before the install phase because otherwise
109+
# because otherwise they may overwrite already installed binaries with the
110+
# wrong RPATH (i.e. build RPATH instead of install RPATH).
111+
#
112+
# This target needs to be created here (rather than in API/CMakeLists.txt)
113+
# because add_lldb_tool creates the custom rules to copy the binaries before
114+
# the framework target exists and that's the only place where this is
115+
# tracked.
116+
add_custom_target(lldb-framework-cleanup
117+
COMMENT "Cleaning up build-tree frameworks in preparation for install")
104118
endif()
105119

106120
if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode)

lldb/source/API/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,9 @@ endif()
211211

212212
if(LLDB_BUILD_FRAMEWORK)
213213
include(LLDBFramework)
214+
215+
add_dependencies(install-liblldb
216+
lldb-framework-cleanup)
217+
add_dependencies(install-liblldb-stripped
218+
lldb-framework-cleanup)
214219
endif()

0 commit comments

Comments
 (0)