summaryrefslogtreecommitdiffstats
path: root/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2020-01-06 08:49:36 -0800
committerJonas Devlieghere <jonas@devlieghere.com>2020-01-06 09:05:05 -0800
commitb3757f3091d1c718a91f5b06b7364b2af28339fa (patch)
tree74b8b49bf954b9bf166558bc2251b62777817a30 /lldb/cmake/modules/FindPythonInterpAndLibs.cmake
parent83ec9b51ed21b39063f0e0e7b272e66ae57bbcba (diff)
downloadbcm5719-llvm-b3757f3091d1c718a91f5b06b7364b2af28339fa.tar.gz
bcm5719-llvm-b3757f3091d1c718a91f5b06b7364b2af28339fa.zip
[lldb/CMake] Autodetect Python dependency
Python was the last remaining "optional" dependency for LLDB. This moves the code to find Python into FindPythonInterpAndLibs using the same principles as FindCursesAndPanel. Differential revision: https://reviews.llvm.org/D72107
Diffstat (limited to 'lldb/cmake/modules/FindPythonInterpAndLibs.cmake')
-rw-r--r--lldb/cmake/modules/FindPythonInterpAndLibs.cmake51
1 files changed, 51 insertions, 0 deletions
diff --git a/lldb/cmake/modules/FindPythonInterpAndLibs.cmake b/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
new file mode 100644
index 00000000000..fcbf0212d72
--- /dev/null
+++ b/lldb/cmake/modules/FindPythonInterpAndLibs.cmake
@@ -0,0 +1,51 @@
+#.rst:
+# FindPythonInterpAndLibs
+# -----------
+#
+# Find the python interpreter and libraries as a whole.
+
+if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS AND PYTHON_EXECUTABLE)
+ set(PYTHONINTERPANDLIBS_FOUND TRUE)
+else()
+ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+ find_package(Python3 COMPONENTS Interpreter Development QUIET)
+ if (Python3_FOUND AND Python3_Interpreter_FOUND)
+ set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
+ set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
+ set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
+ mark_as_advanced(
+ PYTHON_LIBRARIES
+ PYTHON_INCLUDE_DIRS
+ PYTHON_EXECUTABLE)
+ endif()
+ else()
+ find_package(PythonInterp QUIET)
+ find_package(PythonLibs QUIET)
+ if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
+ if (NOT CMAKE_CROSSCOMPILING)
+ string(REPLACE "." ";" pythonlibs_version_list ${PYTHONLIBS_VERSION_STRING})
+ list(GET pythonlibs_version_list 0 pythonlibs_major)
+ list(GET pythonlibs_version_list 1 pythonlibs_minor)
+
+ # Ignore the patch version. Some versions of macOS report a different
+ # patch version for the system provided interpreter and libraries.
+ if (CMAKE_CROSSCOMPILING OR (PYTHON_VERSION_MAJOR VERSION_EQUAL pythonlibs_major AND
+ PYTHON_VERSION_MINOR VERSION_EQUAL pythonlibs_minor))
+ mark_as_advanced(
+ PYTHON_LIBRARIES
+ PYTHON_INCLUDE_DIRS
+ PYTHON_EXECUTABLE)
+ endif()
+ endif()
+ endif()
+ endif()
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(PythonInterpAndLibs
+ FOUND_VAR
+ PYTHONINTERPANDLIBS_FOUND
+ REQUIRED_VARS
+ PYTHON_LIBRARIES
+ PYTHON_INCLUDE_DIRS
+ PYTHON_EXECUTABLE)
+endif()
OpenPOWER on IntegriCloud