FindPythonInterp.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # - Find python interpreter
  2. # This module finds if Python interpreter is installed and determines where the
  3. # executables are. This code sets the following variables:
  4. #
  5. # PYTHONINTERP_FOUND - Was the Python executable found
  6. # PYTHON_EXECUTABLE - path to the Python interpreter
  7. # Python_ADDITIONAL_VERSIONS - list of additional Python versions to search for
  8. #
  9. #=============================================================================
  10. # Copyright 2005-2010 Kitware, Inc.
  11. #
  12. # Distributed under the OSI-approved BSD License (the "License");
  13. # see accompanying file Copyright.txt for details.
  14. #
  15. # This software is distributed WITHOUT ANY WARRANTY; without even the
  16. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. # See the License for more information.
  18. #=============================================================================
  19. # (To distribute this file outside of CMake, substitute the full
  20. # License text for the above reference.)
  21. find_program(PYTHON_EXECUTABLE NAMES python)
  22. # Set up the versions we know about, in the order we will search. Always add
  23. # the user supplied additional versions to the front.
  24. set(_Python_VERSIONS
  25. ${Python_ADDITIONAL_VERSIONS}
  26. 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
  27. # Run first with the Python version in the executable
  28. if(NOT PYTHON_EXECUTABLE)
  29. foreach(_CURRENT_VERSION ${_Python_VERSIONS})
  30. set(_Python_NAMES python${_CURRENT_VERSION})
  31. if(WIN32)
  32. list(APPEND _Python_NAMES python)
  33. endif()
  34. find_program(PYTHON_EXECUTABLE
  35. NAMES ${_Python_NAMES}
  36. PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]
  37. )
  38. endforeach()
  39. endif()
  40. # handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if
  41. # all listed variables are TRUE
  42. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  43. FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonInterp DEFAULT_MSG PYTHON_EXECUTABLE)
  44. mark_as_advanced(PYTHON_EXECUTABLE)