1# Macros and functions related to detecting details of the Python environment.
2
3# Detects a pybind11 package installed in the current python environment
4# and sets variables to allow it to be found. This allows pybind11 to be
5# installed via pip, which typically yields a much more recent version than
6# the OS install, which will be available otherwise.
7function(mlir_detect_pybind11_install)
8  if(pybind11_DIR)
9    message(STATUS "Using explicit pybind11 cmake directory: ${pybind11_DIR} (-Dpybind11_DIR to change)")
10  else()
11    message(STATUS "Checking for pybind11 in python path...")
12    execute_process(
13      COMMAND "${Python3_EXECUTABLE}"
14      -c "import pybind11;print(pybind11.get_cmake_dir(), end='')"
15      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
16      RESULT_VARIABLE STATUS
17      OUTPUT_VARIABLE PACKAGE_DIR
18      ERROR_QUIET)
19    if(NOT STATUS EQUAL "0")
20      message(STATUS "not found (install via 'pip install pybind11' or set pybind11_DIR)")
21      return()
22    endif()
23    message(STATUS "found (${PACKAGE_DIR})")
24    set(pybind11_DIR "${PACKAGE_DIR}" PARENT_SCOPE)
25  endif()
26endfunction()
27