74 lines · plain
1#.rst:2# FindPythonAndSwig3# -----------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 if(NOT Python3_ROOT_DIR)10 set(Python3_ROOT_DIR "${PYTHON_HOME}")11 endif()12 find_package(Python3 COMPONENTS Interpreter Development)13 if(Python3_FOUND AND Python3_Interpreter_FOUND)14 15 # The install name for the Python 3 framework in Xcode is relative to16 # the framework's location and not the dylib itself.17 #18 # @rpath/Python3.framework/Versions/3.x/Python319 #20 # This means that we need to compute the path to the Python3.framework21 # and use that as the RPATH instead of the usual dylib's directory.22 #23 # The check below shouldn't match Homebrew's Python framework as it is24 # called Python.framework instead of Python3.framework.25 if (APPLE AND Python3_LIBRARIES MATCHES "Python3.framework")26 string(FIND "${Python3_LIBRARIES}" "Python3.framework" python_framework_pos)27 string(SUBSTRING "${Python3_LIBRARIES}" "0" ${python_framework_pos} Python3_RPATH)28 endif()29 30 set(PYTHON3_FOUND TRUE)31 mark_as_advanced(32 Python3_LIBRARIES33 Python3_INCLUDE_DIRS34 Python3_EXECUTABLE35 Python3_RPATH)36 endif()37endmacro()38 39if(Python3_LIBRARIES AND Python3_INCLUDE_DIRS AND Python3_EXECUTABLE AND LLDB_ENABLE_SWIG)40 set(PYTHONANDSWIG_FOUND TRUE)41else()42 if (LLDB_ENABLE_SWIG)43 FindPython3()44 else()45 message(STATUS "SWIG 4 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" AND50 "${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 not53 # able to detect whether Python was built with assertions, and only Windows54 # 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(PythonAndSwig61 FOUND_VAR62 PYTHONANDSWIG_FOUND63 REQUIRED_VARS64 Python3_LIBRARIES65 Python3_INCLUDE_DIRS66 Python3_EXECUTABLE67 LLDB_ENABLE_SWIG)68endif()69 70set(LLDB_RECOMMENDED_PYTHON "3.8")71if(PYTHONANDSWIG_FOUND AND "${Python3_VERSION}" VERSION_LESS "${LLDB_RECOMMENDED_PYTHON}")72 message(WARNING "Using Python ${Python3_VERSION}. ${LLDB_RECOMMENDED_PYTHON} "73 "is recommended and will be required from LLDB 21.")74endif()