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 3.0) 42 if (SWIG_FOUND) 43 FindPython3() 44 else() 45 message(STATUS "SWIG 3 or later is required for Python support in LLDB but could not be found") 46 endif() 47 48 get_property(MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 49 if ("${Python3_VERSION}" VERSION_GREATER_EQUAL "3.7" AND 50 "${SWIG_VERSION}" VERSION_LESS "4.0" AND WIN32 AND ( 51 ${MULTI_CONFIG} OR (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG"))) 52 # Technically this can happen with non-Windows builds too, but we are not 53 # able to detect whether Python was built with assertions, and only Windows 54 # has the requirement that Debug LLDB must use Debug Python. 55 message(WARNING "Debug builds of LLDB are likely to be unusable due to " 56 "<https://github.com/swig/swig/issues/1321>. Please use SWIG >= 4.0.") 57 endif() 58 59 include(FindPackageHandleStandardArgs) 60 find_package_handle_standard_args(PythonAndSwig 61 FOUND_VAR 62 PYTHONANDSWIG_FOUND 63 REQUIRED_VARS 64 Python3_LIBRARIES 65 Python3_INCLUDE_DIRS 66 Python3_EXECUTABLE 67 SWIG_EXECUTABLE) 68endif() 69