diff --git a/lldb/cmake/modules/AddLLDB.cmake b/lldb/cmake/modules/AddLLDB.cmake --- a/lldb/cmake/modules/AddLLDB.cmake +++ b/lldb/cmake/modules/AddLLDB.cmake @@ -243,6 +243,16 @@ COMMAND ${CMAKE_COMMAND} -E copy $ ${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 --- a/lldb/cmake/modules/LLDBConfig.cmake +++ b/lldb/cmake/modules/LLDBConfig.cmake @@ -101,6 +101,20 @@ # 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) diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -211,4 +211,9 @@ if(LLDB_BUILD_FRAMEWORK) include(LLDBFramework) + + add_dependencies(install-liblldb + lldb-framework-cleanup) + add_dependencies(install-liblldb-stripped + lldb-framework-cleanup) endif()