Index: cmake/modules/AddLLDB.cmake =================================================================== --- cmake/modules/AddLLDB.cmake +++ cmake/modules/AddLLDB.cmake @@ -44,9 +44,15 @@ if (PARAM_OBJECT) add_library(${name} ${libkind} ${srcs}) else() - llvm_add_library(${name} ${libkind} ${srcs} LINK_LIBS - ${PARAM_LINK_LIBS} - DEPENDS ${PARAM_DEPENDS}) + if(LLDB_NO_INSTALL_DEFAULT_RPATH) + set(pass_NO_INSTALL_RPATH NO_INSTALL_RPATH) + endif() + + llvm_add_library(${name} ${libkind} ${srcs} + LINK_LIBS ${PARAM_LINK_LIBS} + DEPENDS ${PARAM_DEPENDS} + ${pass_NO_INSTALL_RPATH} + ) if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") if (PARAM_SHARED) @@ -98,8 +104,15 @@ ${ARGN} ) + if(LLDB_NO_INSTALL_DEFAULT_RPATH) + set(pass_NO_INSTALL_RPATH NO_INSTALL_RPATH) + endif() + list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS}) - add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS} ENTITLEMENTS ${ARG_ENTITLEMENTS}) + add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS} + ENTITLEMENTS ${ARG_ENTITLEMENTS} + ${pass_NO_INSTALL_RPATH} + ) target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS}) set_target_properties(${name} PROPERTIES FOLDER "lldb executables") @@ -135,3 +148,29 @@ # Now set them onto the target. set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags}) endfunction() + +# Account for different directory structures of build-tree and install-tree with +# LLDB_BUILD_FRAMEWORK, replacing default RPATH settings (see llvm_setup_rpath), +# so that we emit correct load commands for tools that dynamically link to the +# framework bundle. +function(lldb_setup_rpaths_framework name) + # In the build-tree, we know the exact path to the binary in the framework. + set(rpath_build_tree "$") + + # The installed framework is relocatable and can be in different locations. + set(rpaths_install_tree "@loader_path/../../../SharedFrameworks") + list(APPEND rpaths_install_tree "@loader_path/../../System/Library/PrivateFrameworks") + list(APPEND rpaths_install_tree "@loader_path/../../Library/PrivateFrameworks") + + if(LLDB_FRAMEWORK_INSTALL_DIR) + set(rpaths_install_tree "@loader_path/../${LLDB_FRAMEWORK_INSTALL_DIR}") + endif() + + set_target_properties(${name} PROPERTIES + BUILD_WITH_INSTALL_RPATH OFF + BUILD_RPATH "${rpath_build_tree}" + INSTALL_RPATH "${rpaths_install_tree}" + ) + + add_dependencies(${name} lldb-framework) +endfunction() Index: cmake/modules/LLDBConfig.cmake =================================================================== --- cmake/modules/LLDBConfig.cmake +++ cmake/modules/LLDBConfig.cmake @@ -47,6 +47,7 @@ option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to locate Python." OFF) option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install a copy of it" OFF) option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF) +option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF) option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON) set(LLDB_CODESIGN_IDENTITY lldb_codesign CACHE STRING Index: tools/driver/CMakeLists.txt =================================================================== --- tools/driver/CMakeLists.txt +++ tools/driver/CMakeLists.txt @@ -22,3 +22,7 @@ LLDBOptionsTableGen ${tablegen_deps} ) + +if(LLDB_BUILD_FRAMEWORK) + lldb_setup_rpaths_framework(lldb) +endif() Index: tools/lldb-mi/CMakeLists.txt =================================================================== --- tools/lldb-mi/CMakeLists.txt +++ tools/lldb-mi/CMakeLists.txt @@ -93,3 +93,7 @@ LINK_COMPONENTS Support ) + +if(LLDB_BUILD_FRAMEWORK) + lldb_setup_rpaths_framework(lldb-mi) +endif() Index: tools/lldb-vscode/CMakeLists.txt =================================================================== --- tools/lldb-vscode/CMakeLists.txt +++ tools/lldb-vscode/CMakeLists.txt @@ -28,3 +28,7 @@ LINK_COMPONENTS Support ) + +if(LLDB_BUILD_FRAMEWORK) + lldb_setup_rpaths_framework(lldb-vscode) +endif()