You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

FindNumPy.cmake 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # * Find the NumPy libraries This module finds if NumPy is installed, and sets the
  2. # following variables indicating where it is.
  3. #
  4. # TODO: Update to provide the libraries and paths for linking npymath lib.
  5. #
  6. # NUMPY_FOUND - was NumPy found NUMPY_VERSION - the version of
  7. # NumPy found as a string NUMPY_VERSION_MAJOR - the major version number of NumPy
  8. # NUMPY_VERSION_MINOR - the minor version number of NumPy NUMPY_VERSION_PATCH -
  9. # the patch version number of NumPy NUMPY_VERSION_DECIMAL - e.g. version 1.6.1 is
  10. # 10601 NUMPY_INCLUDE_DIR - path to the NumPy include files
  11. unset(NUMPY_VERSION)
  12. unset(NUMPY_INCLUDE_DIR)
  13. if(PYTHONINTERP_FOUND)
  14. execute_process(
  15. COMMAND "${PYTHON_EXECUTABLE}" "-c"
  16. "import numpy as n; print(n.__version__); print(n.get_include());"
  17. RESULT_VARIABLE __result
  18. OUTPUT_VARIABLE __output
  19. OUTPUT_STRIP_TRAILING_WHITESPACE)
  20. if(__result MATCHES 0)
  21. string(REGEX REPLACE ";" "\\\\;" __values ${__output})
  22. string(REGEX REPLACE "\r?\n" ";" __values ${__values})
  23. list(GET __values 0 NUMPY_VERSION)
  24. list(GET __values 1 NUMPY_INCLUDE_DIR)
  25. string(REGEX MATCH "^([0-9])+\\.([0-9])+\\.([0-9])+" __ver_check "${NUMPY_VERSION}")
  26. if(NOT "${__ver_check}" STREQUAL "")
  27. set(NUMPY_VERSION_MAJOR ${CMAKE_MATCH_1})
  28. set(NUMPY_VERSION_MINOR ${CMAKE_MATCH_2})
  29. set(NUMPY_VERSION_PATCH ${CMAKE_MATCH_3})
  30. math(
  31. EXPR
  32. NUMPY_VERSION_DECIMAL
  33. "(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}"
  34. )
  35. string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIR ${NUMPY_INCLUDE_DIR})
  36. else()
  37. unset(NUMPY_VERSION)
  38. unset(NUMPY_INCLUDE_DIR)
  39. message(
  40. STATUS
  41. "Requested NumPy version and include path, but got instead:\n${__output}\n")
  42. endif()
  43. endif()
  44. else()
  45. message(STATUS "To find NumPy Python interpretator is required to be found.")
  46. endif()
  47. include(FindPackageHandleStandardArgs)
  48. find_package_handle_standard_args(
  49. NumPy
  50. REQUIRED_VARS NUMPY_INCLUDE_DIR NUMPY_VERSION
  51. VERSION_VAR NUMPY_VERSION)
  52. if(NUMPY_FOUND)
  53. message(STATUS "NumPy ver. ${NUMPY_VERSION} found (include: ${NUMPY_INCLUDE_DIR})")
  54. endif()