[Lldb-commits] [lldb] r350392 - [CMake] Revised RPATH handling
Stefan Granitz via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 4 04:46:57 PST 2019
Author: stefan.graenitz
Date: Fri Jan 4 04:46:57 2019
New Revision: 350392
URL: http://llvm.org/viewvc/llvm-project?rev=350392&view=rev
Log:
[CMake] Revised RPATH handling
Summary:
If we build LLDB.framework, dependant tools need appropriate RPATHs in both locations, the build-tree (for testing) and the install-tree (for deployment). Luckily, CMake can handle it for us: https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling.
* In the build-tree, tools use the absolute path to the framework's actual output location.
* In the install-tree, tools get a list of RPATHs to look for the framework when deployed.
`LLDB_FRAMEWORK_INSTALL_DIR` is added to the `CMAKE_INSTALL_PREFIX` to change the relative location of LLDB.framework in the install-tree.
If it is not empty, it will be added as an additional RPATH to all dependant tools (so they are functional in the install-tree).
If it is empty, LLDB.framework goes to the root and tools will not be functional in the directory structure of the LLVM install-tree.
For historical reasons `LLDB_FRAMEWORK_INSTALL_DIR` defaults to "Library/Frameworks".
Reviewers: xiaobai, JDevlieghere, aprantl, clayborg
Reviewed By: JDevlieghere
Subscribers: ki.stfu, mgorny, lldb-commits, #lldb
Differential Revision: https://reviews.llvm.org/D55330
Modified:
lldb/trunk/cmake/modules/AddLLDB.cmake
lldb/trunk/cmake/modules/LLDBConfig.cmake
lldb/trunk/tools/driver/CMakeLists.txt
lldb/trunk/tools/lldb-mi/CMakeLists.txt
lldb/trunk/tools/lldb-vscode/CMakeLists.txt
Modified: lldb/trunk/cmake/modules/AddLLDB.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/AddLLDB.cmake?rev=350392&r1=350391&r2=350392&view=diff
==============================================================================
--- lldb/trunk/cmake/modules/AddLLDB.cmake (original)
+++ lldb/trunk/cmake/modules/AddLLDB.cmake Fri Jan 4 04:46:57 2019
@@ -44,9 +44,15 @@ function(add_lldb_library name)
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 @@ function(add_lldb_executable name)
${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,40 @@ function(lldb_append_link_flags target_n
# Now set them onto the target.
set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags})
endfunction()
+
+# For tools that depend on liblldb, account for varying directory structures in
+# which LLDB.framework can be used and distributed: In the build-tree we find it
+# by its absolute target path. This is only relevant for running the test suite.
+# In the install step CMake will remove this entry and insert the final RPATHs.
+# These are relative to the file path from where the tool will be loaded on the
+# enduser system.
+#
+# Note that the LLVM install-tree doesn't match the enduser system structure
+# for LLDB.framework, so by default dependent tools will not be functional in
+# their install location. The LLDB_FRAMEWORK_INSTALL_DIR variable allows to fix
+# this. If specified, it causes the install-tree location of the framework to be
+# added as an extra RPATH below.
+#
+function(lldb_setup_framework_rpaths_in_tool name)
+ # In the build-tree, we know the exact path to the binary in the framework.
+ set(rpath_build_tree "$<TARGET_FILE:liblldb>")
+
+ # 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()
+
+ # If LLDB_NO_INSTALL_DEFAULT_RPATH was NOT enabled (default), this overwrites
+ # the default settings from llvm_setup_rpath().
+ 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()
Modified: lldb/trunk/cmake/modules/LLDBConfig.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/LLDBConfig.cmake?rev=350392&r1=350391&r2=350392&view=diff
==============================================================================
--- lldb/trunk/cmake/modules/LLDBConfig.cmake (original)
+++ lldb/trunk/cmake/modules/LLDBConfig.cmake Fri Jan 4 04:46:57 2019
@@ -48,6 +48,7 @@ option(LLDB_RELOCATABLE_PYTHON "Use the
option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install a copy of it" OFF)
option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
+option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
if(LLDB_BUILD_FRAMEWORK)
if(NOT APPLE)
Modified: lldb/trunk/tools/driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/CMakeLists.txt?rev=350392&r1=350391&r2=350392&view=diff
==============================================================================
--- lldb/trunk/tools/driver/CMakeLists.txt (original)
+++ lldb/trunk/tools/driver/CMakeLists.txt Fri Jan 4 04:46:57 2019
@@ -22,3 +22,7 @@ add_dependencies(lldb
LLDBOptionsTableGen
${tablegen_deps}
)
+
+if(LLDB_BUILD_FRAMEWORK)
+ lldb_setup_framework_rpaths_in_tool(lldb)
+endif()
Modified: lldb/trunk/tools/lldb-mi/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/CMakeLists.txt?rev=350392&r1=350391&r2=350392&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/CMakeLists.txt (original)
+++ lldb/trunk/tools/lldb-mi/CMakeLists.txt Fri Jan 4 04:46:57 2019
@@ -93,3 +93,7 @@ add_lldb_tool(lldb-mi
LINK_COMPONENTS
Support
)
+
+if(LLDB_BUILD_FRAMEWORK)
+ lldb_setup_framework_rpaths_in_tool(lldb-mi)
+endif()
Modified: lldb/trunk/tools/lldb-vscode/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/CMakeLists.txt?rev=350392&r1=350391&r2=350392&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-vscode/CMakeLists.txt (original)
+++ lldb/trunk/tools/lldb-vscode/CMakeLists.txt Fri Jan 4 04:46:57 2019
@@ -28,3 +28,7 @@ add_lldb_tool(lldb-vscode
LINK_COMPONENTS
Support
)
+
+if(LLDB_BUILD_FRAMEWORK)
+ lldb_setup_framework_rpaths_in_tool(lldb-vscode)
+endif()
More information about the lldb-commits
mailing list