Python.cmake 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- cmake -*-
  2. if (PYTHON_CMAKE_INCLUDED)
  3. return()
  4. endif (PYTHON_CMAKE_INCLUDED)
  5. set (PYTHON_CMAKE_INCLUDED TRUE)
  6. set(PYTHONINTERP_FOUND)
  7. if (WINDOWS)
  8. # On Windows, explicitly avoid Cygwin Python.
  9. find_program(PYTHON_EXECUTABLE
  10. NAMES python313.exe python312.exe python311.exe python310.exe python39.exe python38.exe python37.exe python36.exe python35.exe python34.exe python33.exe python.exe
  11. NO_DEFAULT_PATH # added so that cmake does not find cygwin python
  12. PATHS
  13. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.13\\InstallPath]
  14. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.13\\InstallPath]
  15. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.12\\InstallPath]
  16. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.12\\InstallPath]
  17. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.11\\InstallPath]
  18. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.11\\InstallPath]
  19. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.10\\InstallPath]
  20. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.10\\InstallPath]
  21. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.9\\InstallPath]
  22. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.9\\InstallPath]
  23. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.8\\InstallPath]
  24. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.8\\InstallPath]
  25. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.7\\InstallPath]
  26. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.7\\InstallPath]
  27. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.6\\InstallPath]
  28. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.6\\InstallPath]
  29. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.5\\InstallPath]
  30. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.5\\InstallPath]
  31. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.4\\InstallPath]
  32. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.4\\InstallPath]
  33. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.3\\InstallPath]
  34. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.3\\InstallPath]
  35. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.9-32\\InstallPath]
  36. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.9-32\\InstallPath]
  37. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.8-32\\InstallPath]
  38. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.8-32\\InstallPath]
  39. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.7-32\\InstallPath]
  40. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.7-32\\InstallPath]
  41. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.6-32\\InstallPath]
  42. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.6-32\\InstallPath]
  43. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.5-32\\InstallPath]
  44. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.5-32\\InstallPath]
  45. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.4-32\\InstallPath]
  46. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.4-32\\InstallPath]
  47. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\3.3-32\\InstallPath]
  48. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\3.3-32\\InstallPath]
  49. )
  50. if (PYTHON_EXECUTABLE)
  51. set(PYTHONINTERP_FOUND ON)
  52. endif (PYTHON_EXECUTABLE)
  53. elseif (LINUX)
  54. string(REPLACE ":" ";" PATH_LIST "$ENV{PATH}")
  55. find_program(PYTHON_EXECUTABLE python3.13 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3 python
  56. PATHS ${PATH_LIST})
  57. if (PYTHON_EXECUTABLE)
  58. set(PYTHONINTERP_FOUND ON)
  59. endif (PYTHON_EXECUTABLE)
  60. elseif (DARWIN)
  61. # On MAC OS X be sure to search standard locations first
  62. string(REPLACE ":" ";" PATH_LIST "$ENV{PATH}")
  63. find_program(PYTHON_EXECUTABLE
  64. NAMES python313 python312 python311 python310 python39 python38 python37 python36 python35 python34 python33 python3 python
  65. NO_DEFAULT_PATH # Avoid searching non-standard locations first
  66. PATHS
  67. /bin
  68. /usr/bin
  69. /usr/local/bin
  70. ${PATH_LIST}
  71. )
  72. if (PYTHON_EXECUTABLE)
  73. set(PYTHONINTERP_FOUND ON)
  74. endif (PYTHON_EXECUTABLE)
  75. endif (WINDOWS)
  76. if (NOT PYTHONINTERP_FOUND)
  77. message(FATAL_ERROR "No compatible Python interpreter found !")
  78. endif (NOT PYTHONINTERP_FOUND)
  79. mark_as_advanced(PYTHON_EXECUTABLE)
  80. message("-- Using Python executable: ${PYTHON_EXECUTABLE}")