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()
 


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()
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to