Findmpi4py.cmake 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. include(CMakeFindDependencyMacro)
  2. find_dependency("Python${VTK_PYTHON_VERSION}" COMPONENTS Interpreter)
  3. execute_process(
  4. COMMAND "${Python${VTK_PYTHON_VERSION}_EXECUTABLE}" -c
  5. "import mpi4py"
  6. OUTPUT_VARIABLE _mpi4py_out
  7. ERROR_VARIABLE _mpi4py_out
  8. RESULT_VARIABLE _mpi4py_res)
  9. if (_mpi4py_res)
  10. set(mpi4py_FOUND 0)
  11. endif ()
  12. if (NOT mpi4py_INCLUDE_DIR OR NOT EXISTS "${mpi4py_INCLUDE_DIR}")
  13. execute_process(
  14. COMMAND "${Python${VTK_PYTHON_VERSION}_EXECUTABLE}" -c
  15. "import mpi4py; print(mpi4py.get_include())"
  16. OUTPUT_VARIABLE _mpi4py_INCLUDE_DIR
  17. RESULT_VARIABLE _mpi4py_include_dir_res
  18. OUTPUT_STRIP_TRAILING_WHITESPACE)
  19. if (_mpi4py_include_dir_res)
  20. set(mpi4py_FOUND 0)
  21. endif ()
  22. set(mpi4py_INCLUDE_DIR "${_mpi4py_INCLUDE_DIR}"
  23. CACHE INTERNAL "Path of the MPI4Py include directory")
  24. endif ()
  25. include(FindPackageHandleStandardArgs)
  26. find_package_handle_standard_args(mpi4py
  27. REQUIRED_VARS mpi4py_INCLUDE_DIR)
  28. if (mpi4py_FOUND AND NOT TARGET mpi4py::mpi4py)
  29. add_library(mpi4py::mpi4py INTERFACE IMPORTED)
  30. set_target_properties(mpi4py::mpi4py
  31. PROPERTIES
  32. INTERFACE_INCLUDE_DIRECTORIES "${mpi4py_INCLUDE_DIR}")
  33. endif ()