[MLIR] Workaround for python detection problems.
authorStephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Tue, 25 Jan 2022 15:53:48 +0000 (07:53 -0800)
committerStephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Thu, 27 Jan 2022 21:32:29 +0000 (13:32 -0800)
Although cmake should be platform-independent, we've observed
that some aspects of Python detection don't work on all platforms,
even with recent versions of cmake.  This appears to be due to bugs
in the python detection logic, especially when the NumPy component
is required and not located within the python installation.
As a workaround, this patch first searches for "Development" before
searching for "Development.Module", which seems to workaround the
issue.

Differential Revision: https://reviews.llvm.org/D118148

mlir/cmake/modules/MLIRDetectPythonEnv.cmake

index 9b36406..87039fd 100644 (file)
@@ -23,6 +23,11 @@ macro(mlir_configure_python_dev_packages)
     )
     set(_python_development_component Development)
   else()
+    # Prime the search for python to see if there is a full
+    # development package. This seems to work around cmake bugs
+    # searching only for Development.Module in some environments.
+    find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
+      COMPONENTS Development)
     set(_python_development_component Development.Module)
   endif()
   find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}