1#.rst: 2# FindPythonAndSwig 3# ----------- 4# 5# Find the python interpreter and libraries as a whole. 6 7macro(FindPython3) 8 # Use PYTHON_HOME as a hint to find Python 3. 9 set(Python3_ROOT_DIR "${PYTHON_HOME}") 10 find_package(Python3 COMPONENTS Interpreter Development) 11 if(Python3_FOUND AND Python3_Interpreter_FOUND) 12 13 # The install name for the Python 3 framework in Xcode is relative to 14 # the framework's location and not the dylib itself. 15 # 16 # @rpath/Python3.framework/Versions/3.x/Python3 17 # 18 # This means that we need to compute the path to the Python3.framework 19 # and use that as the RPATH instead of the usual dylib's directory. 20 # 21 # The check below shouldn't match Homebrew's Python framework as it is 22 # called Python.framework instead of Python3.framework. 23 if (APPLE AND Python3_LIBRARIES MATCHES "Python3.framework") 24 string(FIND "${Python3_LIBRARIES}" "Python3.framework" python_framework_pos) 25 string(SUBSTRING "${Python3_LIBRARIES}" "0" ${python_framework_pos} Python3_RPATH) 26 endif() 27 28 set(PYTHON3_FOUND TRUE) 29 mark_as_advanced( 30 Python3_LIBRARIES 31 Python3_INCLUDE_DIRS 32 Python3_EXECUTABLE 33 Python3_RPATH 34 SWIG_EXECUTABLE) 35 endif() 36endmacro() 37 38if(Python3_LIBRARIES AND Python3_INCLUDE_DIRS AND Python3_EXECUTABLE AND SWIG_EXECUTABLE) 39 set(PYTHONANDSWIG_FOUND TRUE) 40else() 41 find_package(SWIG 2.0) 42 if (SWIG_FOUND) 43 FindPython3() 44 else() 45 message(STATUS "SWIG 2 or later is required for Python support in LLDB but could not be found") 46 endif() 47 48 include(FindPackageHandleStandardArgs) 49 find_package_handle_standard_args(PythonAndSwig 50 FOUND_VAR 51 PYTHONANDSWIG_FOUND 52 REQUIRED_VARS 53 Python3_LIBRARIES 54 Python3_INCLUDE_DIRS 55 Python3_EXECUTABLE 56 SWIG_EXECUTABLE) 57endif() 58