221
|
1 # Macros and functions related to detecting details of the Python environment.
|
|
2
|
236
|
3 # Finds and configures python packages needed to build MLIR Python bindings.
|
|
4 macro(mlir_configure_python_dev_packages)
|
|
5 if(MLIR_DETECT_PYTHON_ENV_PRIME_SEARCH)
|
|
6 # Prime the search for python to see if there is a full development
|
|
7 # package. This seems to work around cmake bugs searching only for
|
|
8 # Development.Module in some environments. However, in other environments
|
|
9 # it may interfere with the subsequent search for Development.Module.
|
|
10 find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
|
|
11 COMPONENTS Interpreter Development)
|
|
12 endif()
|
|
13
|
|
14 # After CMake 3.18, we are able to limit the scope of the search to just
|
|
15 # Development.Module. Searching for Development will fail in situations where
|
|
16 # the Python libraries are not available. When possible, limit to just
|
|
17 # Development.Module.
|
|
18 # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode
|
|
19 set(_python_development_component Development.Module)
|
|
20
|
|
21 find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
|
|
22 COMPONENTS Interpreter ${_python_development_component} NumPy REQUIRED)
|
|
23 unset(_python_development_component)
|
|
24 message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
|
|
25 message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
|
|
26 message(STATUS "Found numpy v${Python3_NumPy_VERSION}: ${Python3_NumPy_INCLUDE_DIRS}")
|
|
27 mlir_detect_pybind11_install()
|
252
|
28 find_package(pybind11 2.9 CONFIG REQUIRED)
|
236
|
29 message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}")
|
|
30 message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
|
|
31 "suffix = '${PYTHON_MODULE_SUFFIX}', "
|
|
32 "extension = '${PYTHON_MODULE_EXTENSION}")
|
|
33 endmacro()
|
|
34
|
221
|
35 # Detects a pybind11 package installed in the current python environment
|
|
36 # and sets variables to allow it to be found. This allows pybind11 to be
|
|
37 # installed via pip, which typically yields a much more recent version than
|
|
38 # the OS install, which will be available otherwise.
|
|
39 function(mlir_detect_pybind11_install)
|
|
40 if(pybind11_DIR)
|
|
41 message(STATUS "Using explicit pybind11 cmake directory: ${pybind11_DIR} (-Dpybind11_DIR to change)")
|
|
42 else()
|
|
43 message(STATUS "Checking for pybind11 in python path...")
|
|
44 execute_process(
|
|
45 COMMAND "${Python3_EXECUTABLE}"
|
|
46 -c "import pybind11;print(pybind11.get_cmake_dir(), end='')"
|
|
47 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
48 RESULT_VARIABLE STATUS
|
|
49 OUTPUT_VARIABLE PACKAGE_DIR
|
|
50 ERROR_QUIET)
|
|
51 if(NOT STATUS EQUAL "0")
|
|
52 message(STATUS "not found (install via 'pip install pybind11' or set pybind11_DIR)")
|
|
53 return()
|
|
54 endif()
|
|
55 message(STATUS "found (${PACKAGE_DIR})")
|
|
56 set(pybind11_DIR "${PACKAGE_DIR}" PARENT_SCOPE)
|
|
57 endif()
|
|
58 endfunction()
|