175966ee2SJonas Devlieghere#.rst: 275966ee2SJonas Devlieghere# FindPythonAndSwig 375966ee2SJonas Devlieghere# ----------- 475966ee2SJonas Devlieghere# 575966ee2SJonas Devlieghere# Find the python interpreter and libraries as a whole. 675966ee2SJonas Devlieghere 775966ee2SJonas Devliegheremacro(FindPython3) 875966ee2SJonas Devlieghere # Use PYTHON_HOME as a hint to find Python 3. 975966ee2SJonas Devlieghere set(Python3_ROOT_DIR "${PYTHON_HOME}") 1075966ee2SJonas Devlieghere find_package(Python3 COMPONENTS Interpreter Development) 1175966ee2SJonas Devlieghere if(Python3_FOUND AND Python3_Interpreter_FOUND) 1275966ee2SJonas Devlieghere 1375966ee2SJonas Devlieghere # The install name for the Python 3 framework in Xcode is relative to 1475966ee2SJonas Devlieghere # the framework's location and not the dylib itself. 1575966ee2SJonas Devlieghere # 1675966ee2SJonas Devlieghere # @rpath/Python3.framework/Versions/3.x/Python3 1775966ee2SJonas Devlieghere # 1875966ee2SJonas Devlieghere # This means that we need to compute the path to the Python3.framework 1975966ee2SJonas Devlieghere # and use that as the RPATH instead of the usual dylib's directory. 2075966ee2SJonas Devlieghere # 2175966ee2SJonas Devlieghere # The check below shouldn't match Homebrew's Python framework as it is 2275966ee2SJonas Devlieghere # called Python.framework instead of Python3.framework. 2375966ee2SJonas Devlieghere if (APPLE AND Python3_LIBRARIES MATCHES "Python3.framework") 2475966ee2SJonas Devlieghere string(FIND "${Python3_LIBRARIES}" "Python3.framework" python_framework_pos) 2575966ee2SJonas Devlieghere string(SUBSTRING "${Python3_LIBRARIES}" "0" ${python_framework_pos} Python3_RPATH) 2675966ee2SJonas Devlieghere endif() 2775966ee2SJonas Devlieghere 2875966ee2SJonas Devlieghere set(PYTHON3_FOUND TRUE) 2975966ee2SJonas Devlieghere mark_as_advanced( 3075966ee2SJonas Devlieghere Python3_LIBRARIES 3175966ee2SJonas Devlieghere Python3_INCLUDE_DIRS 3275966ee2SJonas Devlieghere Python3_EXECUTABLE 3375966ee2SJonas Devlieghere Python3_RPATH 3475966ee2SJonas Devlieghere SWIG_EXECUTABLE) 3575966ee2SJonas Devlieghere endif() 3675966ee2SJonas Devlieghereendmacro() 3775966ee2SJonas Devlieghere 3875966ee2SJonas Devlieghereif(Python3_LIBRARIES AND Python3_INCLUDE_DIRS AND Python3_EXECUTABLE AND SWIG_EXECUTABLE) 3975966ee2SJonas Devlieghere set(PYTHONANDSWIG_FOUND TRUE) 4075966ee2SJonas Devlieghereelse() 41*cb6d53ccSJonas Devlieghere find_package(SWIG 3.0) 4275966ee2SJonas Devlieghere if (SWIG_FOUND) 4375966ee2SJonas Devlieghere FindPython3() 4475966ee2SJonas Devlieghere else() 45*cb6d53ccSJonas Devlieghere message(STATUS "SWIG 3 or later is required for Python support in LLDB but could not be found") 4675966ee2SJonas Devlieghere endif() 4775966ee2SJonas Devlieghere 48d4a7c707SPavel Labath get_property(MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 49d4a7c707SPavel Labath if ("${Python3_VERSION}" VERSION_GREATER_EQUAL "3.7" AND 50d4a7c707SPavel Labath "${SWIG_VERSION}" VERSION_LESS "4.0" AND WIN32 AND ( 5126459e6dSChristopher Tetreault ${MULTI_CONFIG} OR (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG"))) 52d4a7c707SPavel Labath # Technically this can happen with non-Windows builds too, but we are not 53d4a7c707SPavel Labath # able to detect whether Python was built with assertions, and only Windows 54d4a7c707SPavel Labath # has the requirement that Debug LLDB must use Debug Python. 55d4a7c707SPavel Labath message(WARNING "Debug builds of LLDB are likely to be unusable due to " 56d4a7c707SPavel Labath "<https://github.com/swig/swig/issues/1321>. Please use SWIG >= 4.0.") 57d4a7c707SPavel Labath endif() 58d4a7c707SPavel Labath 5975966ee2SJonas Devlieghere include(FindPackageHandleStandardArgs) 6075966ee2SJonas Devlieghere find_package_handle_standard_args(PythonAndSwig 6175966ee2SJonas Devlieghere FOUND_VAR 6275966ee2SJonas Devlieghere PYTHONANDSWIG_FOUND 6375966ee2SJonas Devlieghere REQUIRED_VARS 6475966ee2SJonas Devlieghere Python3_LIBRARIES 6575966ee2SJonas Devlieghere Python3_INCLUDE_DIRS 6675966ee2SJonas Devlieghere Python3_EXECUTABLE 6775966ee2SJonas Devlieghere SWIG_EXECUTABLE) 6875966ee2SJonas Devlieghereendif() 69