[Lldb-commits] [lldb] ae6d2ff - [lldb] fix RPATH when linking against Python3.framework

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 30 10:43:10 PDT 2020


Author: Jonas Devlieghere
Date: 2020-04-30T10:42:03-07:00
New Revision: ae6d2ff633a07a04aad62a0870afe28950472938

URL: https://github.com/llvm/llvm-project/commit/ae6d2ff633a07a04aad62a0870afe28950472938
DIFF: https://github.com/llvm/llvm-project/commit/ae6d2ff633a07a04aad62a0870afe28950472938.diff

LOG: [lldb] fix RPATH when linking against Python3.framework

The install name for the Python 3 framework in Xcode is relative to
the framework's location and not the dylib itself.

  @rpath/Python3.framework/Versions/3.x/Python3

This means that we need to compute the path to the Python3.framework
and use that as the RPATH instead of the usual dylib's directory.

Added: 
    

Modified: 
    lldb/cmake/modules/FindPythonInterpAndLibs.cmake
    lldb/source/API/CMakeLists.txt
    lldb/tools/lldb-test/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/lldb/cmake/modules/FindPythonInterpAndLibs.cmake b/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
index fa7a39185586..5ea7aab63230 100644
--- a/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
+++ b/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
@@ -17,10 +17,27 @@ else()
         set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
         set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
         set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
+
+        # The install name for the Python 3 framework in Xcode is relative to
+        # the framework's location and not the dylib itself.
+        #
+        #   @rpath/Python3.framework/Versions/3.x/Python3
+        #
+        # This means that we need to compute the path to the Python3.framework
+        # and use that as the RPATH instead of the usual dylib's directory.
+        #
+        # The check below shouldn't match Homebrew's Python framework as it is
+        # called Python.framework instead of Python3.framework.
+        if (APPLE AND Python3_LIBRARIES MATCHES "Python3.framework")
+          string(FIND "${Python3_LIBRARIES}" "Python3.framework" python_framework_pos)
+          string(SUBSTRING "${Python3_LIBRARIES}" "0" ${python_framework_pos} PYTHON_RPATH)
+        endif()
+
         mark_as_advanced(
           PYTHON_LIBRARIES
           PYTHON_INCLUDE_DIRS
           PYTHON_EXECUTABLE
+          PYTHON_RPATH
           SWIG_EXECUTABLE)
       elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
         # Use PYTHON_HOME as a hint to find Python 2.
@@ -34,6 +51,7 @@ else()
             PYTHON_LIBRARIES
             PYTHON_INCLUDE_DIRS
             PYTHON_EXECUTABLE
+            PYTHON_RPATH
             SWIG_EXECUTABLE)
         endif()
       endif()
@@ -54,6 +72,7 @@ else()
               PYTHON_LIBRARIES
               PYTHON_INCLUDE_DIRS
               PYTHON_EXECUTABLE
+              PYTHON_RPATH
               SWIG_EXECUTABLE)
           endif()
         endif()
@@ -63,6 +82,7 @@ else()
     message(STATUS "SWIG 2 or later is required for Python support in LLDB but could not be found")
   endif()
 
+
   include(FindPackageHandleStandardArgs)
   find_package_handle_standard_args(PythonInterpAndLibs
                                     FOUND_VAR
@@ -71,5 +91,6 @@ else()
                                       PYTHON_LIBRARIES
                                       PYTHON_INCLUDE_DIRS
                                       PYTHON_EXECUTABLE
+                                      PYTHON_RPATH
                                       SWIG_EXECUTABLE)
 endif()

diff  --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index f8ed1b37f4fa..ae6f2e8e3251 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -120,6 +120,10 @@ if(LLDB_ENABLE_PYTHON AND (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB) AND UNIX A
   set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "\$ORIGIN/../../../../lib${LLVM_LIBDIR_SUFFIX}")
 endif()
 
+if(PYTHON_RPATH)
+  set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${PYTHON_RPATH}")
+endif()
+
 if (MSVC)
   set_source_files_properties(SBReproducer.cpp PROPERTIES COMPILE_FLAGS /bigobj)
 endif()

diff  --git a/lldb/tools/lldb-test/CMakeLists.txt b/lldb/tools/lldb-test/CMakeLists.txt
index f3530fd7b859..60b4a7ca8f70 100644
--- a/lldb/tools/lldb-test/CMakeLists.txt
+++ b/lldb/tools/lldb-test/CMakeLists.txt
@@ -24,5 +24,9 @@ add_lldb_tool(lldb-test
     Support
   )
 
+if(PYTHON_RPATH)
+  set_property(TARGET lldb-test APPEND PROPERTY INSTALL_RPATH "${PYTHON_RPATH}")
+endif()
+
 target_include_directories(lldb-test PRIVATE ${LLDB_SOURCE_DIR}/source)
 target_include_directories(lldb-test PRIVATE ${LLDB_BINARY_DIR}/source)


        


More information about the lldb-commits mailing list