1be691f3bSpatrick#.rst: 2be691f3bSpatrick# FindPythonAndSwig 3be691f3bSpatrick# ----------- 4be691f3bSpatrick# 5be691f3bSpatrick# Find the python interpreter and libraries as a whole. 6be691f3bSpatrick 7be691f3bSpatrickmacro(FindPython3) 8be691f3bSpatrick # Use PYTHON_HOME as a hint to find Python 3. 9be691f3bSpatrick set(Python3_ROOT_DIR "${PYTHON_HOME}") 10be691f3bSpatrick find_package(Python3 COMPONENTS Interpreter Development) 11be691f3bSpatrick if(Python3_FOUND AND Python3_Interpreter_FOUND) 12be691f3bSpatrick 13be691f3bSpatrick # The install name for the Python 3 framework in Xcode is relative to 14be691f3bSpatrick # the framework's location and not the dylib itself. 15be691f3bSpatrick # 16be691f3bSpatrick # @rpath/Python3.framework/Versions/3.x/Python3 17be691f3bSpatrick # 18be691f3bSpatrick # This means that we need to compute the path to the Python3.framework 19be691f3bSpatrick # and use that as the RPATH instead of the usual dylib's directory. 20be691f3bSpatrick # 21be691f3bSpatrick # The check below shouldn't match Homebrew's Python framework as it is 22be691f3bSpatrick # called Python.framework instead of Python3.framework. 23be691f3bSpatrick if (APPLE AND Python3_LIBRARIES MATCHES "Python3.framework") 24be691f3bSpatrick string(FIND "${Python3_LIBRARIES}" "Python3.framework" python_framework_pos) 25be691f3bSpatrick string(SUBSTRING "${Python3_LIBRARIES}" "0" ${python_framework_pos} Python3_RPATH) 26be691f3bSpatrick endif() 27be691f3bSpatrick 28be691f3bSpatrick set(PYTHON3_FOUND TRUE) 29be691f3bSpatrick mark_as_advanced( 30be691f3bSpatrick Python3_LIBRARIES 31be691f3bSpatrick Python3_INCLUDE_DIRS 32be691f3bSpatrick Python3_EXECUTABLE 33*f6aab3d8Srobert Python3_RPATH) 34be691f3bSpatrick endif() 35be691f3bSpatrickendmacro() 36be691f3bSpatrick 37*f6aab3d8Srobertif(Python3_LIBRARIES AND Python3_INCLUDE_DIRS AND Python3_EXECUTABLE AND LLDB_ENABLE_SWIG) 38be691f3bSpatrick set(PYTHONANDSWIG_FOUND TRUE) 39be691f3bSpatrickelse() 40*f6aab3d8Srobert if (LLDB_ENABLE_SWIG) 41be691f3bSpatrick FindPython3() 42be691f3bSpatrick else() 43be691f3bSpatrick message(STATUS "SWIG 3 or later is required for Python support in LLDB but could not be found") 44be691f3bSpatrick endif() 45be691f3bSpatrick 46be691f3bSpatrick get_property(MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 47be691f3bSpatrick if ("${Python3_VERSION}" VERSION_GREATER_EQUAL "3.7" AND 48be691f3bSpatrick "${SWIG_VERSION}" VERSION_LESS "4.0" AND WIN32 AND ( 49be691f3bSpatrick ${MULTI_CONFIG} OR (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG"))) 50be691f3bSpatrick # Technically this can happen with non-Windows builds too, but we are not 51be691f3bSpatrick # able to detect whether Python was built with assertions, and only Windows 52be691f3bSpatrick # has the requirement that Debug LLDB must use Debug Python. 53be691f3bSpatrick message(WARNING "Debug builds of LLDB are likely to be unusable due to " 54be691f3bSpatrick "<https://github.com/swig/swig/issues/1321>. Please use SWIG >= 4.0.") 55be691f3bSpatrick endif() 56be691f3bSpatrick 57be691f3bSpatrick include(FindPackageHandleStandardArgs) 58be691f3bSpatrick find_package_handle_standard_args(PythonAndSwig 59be691f3bSpatrick FOUND_VAR 60be691f3bSpatrick PYTHONANDSWIG_FOUND 61be691f3bSpatrick REQUIRED_VARS 62be691f3bSpatrick Python3_LIBRARIES 63be691f3bSpatrick Python3_INCLUDE_DIRS 64be691f3bSpatrick Python3_EXECUTABLE 65*f6aab3d8Srobert LLDB_ENABLE_SWIG) 66be691f3bSpatrickendif() 67