FindPythonInterp.cmake 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # Set up the versions we know about, in the order we will search. Always add
  22. # the user supplied additional versions to the front.
  23. set(_Python_VERSIONS
  24. ${Python_ADDITIONAL_VERSIONS}
  25. 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
  26. # Run first with the Python version in the executable
  27. foreach(_CURRENT_VERSION ${_Python_VERSIONS})
  28. set(_Python_NAMES python${_CURRENT_VERSION})
  29. if(WIN32)
  30. list(APPEND _Python_NAMES python)
  31. endif()
  32. find_program(PYTHON_EXECUTABLE
  33. NAMES ${_Python_NAMES}
  34. PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]
  35. )
  36. endforeach()
  37. # Now without any version if we still haven't found it
  38. if(NOT PYTHON_EXECUTABLE)
  39. find_program(PYTHON_EXECUTABLE NAMES python)
  40. endif()
  41. # handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if
  42. # all listed variables are TRUE
  43. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  44. FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonInterp DEFAULT_MSG PYTHON_EXECUTABLE)
  45. mark_as_advanced(PYTHON_EXECUTABLE)