[Lldb-commits] [PATCH] D69535: build: improve python check for Windows

Saleem Abdulrasool via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 28 14:47:00 PDT 2019


compnerd created this revision.
compnerd added reviewers: xiaobai, stella.stamenova.
Herald added subscribers: JDevlieghere, mgorny.
Herald added a project: LLDB.

If we have a new enough CMake, use `find_package(Python3)`.  This version is able to check both 32-bit and 64-bit versions and will setup everything properly without the user needing to specify `PYTHON_HOME`.  This enables building lldb's python bindings on Windows under Azure's CI again.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D69535

Files:
  lldb/cmake/modules/LLDBConfig.cmake


Index: lldb/cmake/modules/LLDBConfig.cmake
===================================================================
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -221,34 +221,43 @@
 endfunction(find_python_libs_windows)
 
 if (NOT LLDB_DISABLE_PYTHON)
-  if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-    find_python_libs_windows()
-
-    if (NOT LLDB_RELOCATABLE_PYTHON)
-      file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
-      add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" )
+  if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND CMAKE_SYSTEM_NAME STREQUAL Windows)
+    find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
+    if(Python3_VERSION VERSION_LESS 3.5)
+      message(FATAL_ERROR "Python 3.5 or newer is required (found: ${Python3_VERSION})")
     endif()
+    set(PYTHON_LIBRARY ${Python3_LIBRARIES})
+    include_directories(${Python3_INCLUDE_DIRS})
   else()
-    find_package(PythonInterp REQUIRED)
-    find_package(PythonLibs REQUIRED)
-  endif()
+    if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+      find_python_libs_windows()
+
+      if (NOT LLDB_RELOCATABLE_PYTHON)
+        file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
+        add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" )
+      endif()
+    else()
+      find_package(PythonInterp REQUIRED)
+      find_package(PythonLibs REQUIRED)
+    endif()
 
-  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 (NOT PYTHON_VERSION_MAJOR VERSION_EQUAL pythonlibs_major OR
-        NOT PYTHON_VERSION_MINOR VERSION_EQUAL pythonlibs_minor)
-      message(FATAL_ERROR "Found incompatible Python interpreter (${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})"
-                          " and Python libraries (${pythonlibs_major}.${pythonlibs_minor})")
+    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 (NOT PYTHON_VERSION_MAJOR VERSION_EQUAL pythonlibs_major OR
+          NOT PYTHON_VERSION_MINOR VERSION_EQUAL pythonlibs_minor)
+        message(FATAL_ERROR "Found incompatible Python interpreter (${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})"
+                            " and Python libraries (${pythonlibs_major}.${pythonlibs_minor})")
+      endif()
     endif()
-  endif()
 
-  if (PYTHON_INCLUDE_DIR)
-    include_directories(${PYTHON_INCLUDE_DIR})
+    if (PYTHON_INCLUDE_DIR)
+      include_directories(${PYTHON_INCLUDE_DIR})
+    endif()
   endif()
 endif()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69535.226753.patch
Type: text/x-patch
Size: 3120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191028/3db35996/attachment.bin>


More information about the lldb-commits mailing list