[Mlir-commits] [mlir] 3d92722 - [mlir][python] Add a warning for cmake version < 3.15.

Stella Laurenzo llvmlistbot at llvm.org
Tue Oct 12 21:14:10 PDT 2021


Author: Stella Laurenzo
Date: 2021-10-12T21:13:54-07:00
New Revision: 3d92722f74993969243d1400bc3257ca3d03902f

URL: https://github.com/llvm/llvm-project/commit/3d92722f74993969243d1400bc3257ca3d03902f
DIFF: https://github.com/llvm/llvm-project/commit/3d92722f74993969243d1400bc3257ca3d03902f.diff

LOG: [mlir][python] Add a warning for cmake version < 3.15.

As discussed on discord, we have never actually been able to build with the project-wide published min version of 3.14.3. The buildbot that tests the Python configuration is currently pinned to 3.19.1, and there are a number of non-version/policy controlled features that Python building relies on that makes it unreliable with older versions. Some of the issues are pretty fundamental and I don't know how to do them on the older version. I think that, as an optional feature, at least advertising the PSA as in this patch is a good middle ground until the next project-wide CMake version bump.

Also moves setup logic to a macro so that everyone can use it.

Added: 
    

Modified: 
    mlir/CMakeLists.txt
    mlir/cmake/modules/MLIRDetectPythonEnv.cmake

Removed: 
    


################################################################################
diff  --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 8c7858d4fd03e..8c131f27b2a81 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -99,31 +99,9 @@ option(MLIR_INCLUDE_INTEGRATION_TESTS
 
 set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL
        "Enables building of Python bindings.")
-
 if(MLIR_ENABLE_BINDINGS_PYTHON)
   include(MLIRDetectPythonEnv)
-  # After CMake 3.18, we are able to limit the scope of the search to just
-  # Development.Module. Searching for Development will fail in situations where
-  # the Python libraries are not available. When possible, limit to just
-  # Development.Module.
-  # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode
-  if(CMAKE_VERSION VERSION_LESS "3.18.0")
-    set(_python_development_component Development)
-  else()
-    set(_python_development_component Development.Module)
-  endif()
-  find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
-    COMPONENTS Interpreter ${_python_development_component} NumPy REQUIRED)
-  unset(_python_development_component)
-  message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
-  message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
-  message(STATUS "Found numpy v${Python3_NumPy_VERSION}: ${Python3_NumPy_INCLUDE_DIRS}")
-  mlir_detect_pybind11_install()
-  find_package(pybind11 2.6 CONFIG REQUIRED)
-  message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}")
-  message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
-                 "suffix = '${PYTHON_MODULE_SUFFIX}', "
-                 "extension = '${PYTHON_MODULE_EXTENSION}")
+  mlir_configure_python_dev_packages()
 endif()
 
 include_directories( "include")

diff  --git a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
index 77bb700c919a0..4739fddd93a4b 100644
--- a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
+++ b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
@@ -1,5 +1,44 @@
 # Macros and functions related to detecting details of the Python environment.
 
+# Finds and configures python packages needed to build MLIR Python bindings.
+macro(mlir_configure_python_dev_packages)
+  if(CMAKE_VERSION VERSION_LESS "3.15.0")
+  message(SEND_ERROR
+      "Building MLIR Python bindings is known to rely on CMake features "
+      "that require at least version 3.15. Recommend upgrading to 3.18+ "
+      "for full support. Detected current version: ${CMAKE_VERSION}")
+  endif()
+
+  # After CMake 3.18, we are able to limit the scope of the search to just
+  # Development.Module. Searching for Development will fail in situations where
+  # the Python libraries are not available. When possible, limit to just
+  # Development.Module.
+  # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode
+  if(CMAKE_VERSION VERSION_LESS "3.18.0")
+    message(WARNING
+        "This version of CMake is not compatible with statically built Python "
+        "installations. If Python fails to detect below this may apply to you. "
+        "Recommend upgrading to at least CMake 3.18. "
+        "Detected current version: ${CMAKE_VERSION}"
+    )
+    set(_python_development_component Development)
+  else()
+    set(_python_development_component Development.Module)
+  endif()
+  find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
+    COMPONENTS Interpreter ${_python_development_component} NumPy REQUIRED)
+  unset(_python_development_component)
+  message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
+  message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
+  message(STATUS "Found numpy v${Python3_NumPy_VERSION}: ${Python3_NumPy_INCLUDE_DIRS}")
+  mlir_detect_pybind11_install()
+  find_package(pybind11 2.6 CONFIG REQUIRED)
+  message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}")
+  message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
+                 "suffix = '${PYTHON_MODULE_SUFFIX}', "
+                 "extension = '${PYTHON_MODULE_EXTENSION}")
+endmacro()
+
 # Detects a pybind11 package installed in the current python environment
 # and sets variables to allow it to be found. This allows pybind11 to be
 # installed via pip, which typically yields a much more recent version than


        


More information about the Mlir-commits mailing list