FindPerl.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindPerl
  5. --------
  6. Find perl
  7. this module looks for Perl
  8. ::
  9. PERL_EXECUTABLE - the full path to perl
  10. PERL_FOUND - If false, don't attempt to use perl.
  11. PERL_VERSION_STRING - version of perl found (since CMake 2.8.8)
  12. #]=======================================================================]
  13. include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
  14. set(PERL_POSSIBLE_BIN_PATHS
  15. ${CYGWIN_INSTALL_PATH}/bin
  16. )
  17. if(WIN32)
  18. get_filename_component(
  19. ActivePerl_CurrentVersion
  20. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl;CurrentVersion]"
  21. NAME)
  22. set(PERL_POSSIBLE_BIN_PATHS ${PERL_POSSIBLE_BIN_PATHS}
  23. "C:/Perl/bin"
  24. "C:/Strawberry/perl/bin"
  25. [HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\${ActivePerl_CurrentVersion}]/bin
  26. )
  27. endif()
  28. find_program(PERL_EXECUTABLE
  29. NAMES perl
  30. PATHS ${PERL_POSSIBLE_BIN_PATHS}
  31. )
  32. if(PERL_EXECUTABLE)
  33. ### PERL_VERSION
  34. execute_process(
  35. COMMAND
  36. ${PERL_EXECUTABLE} -V:version
  37. OUTPUT_VARIABLE
  38. PERL_VERSION_OUTPUT_VARIABLE
  39. RESULT_VARIABLE
  40. PERL_VERSION_RESULT_VARIABLE
  41. ERROR_QUIET
  42. OUTPUT_STRIP_TRAILING_WHITESPACE
  43. )
  44. if(NOT PERL_VERSION_RESULT_VARIABLE AND NOT PERL_VERSION_OUTPUT_VARIABLE MATCHES "^version='UNKNOWN'")
  45. string(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION_STRING ${PERL_VERSION_OUTPUT_VARIABLE})
  46. else()
  47. execute_process(
  48. COMMAND ${PERL_EXECUTABLE} -v
  49. OUTPUT_VARIABLE PERL_VERSION_OUTPUT_VARIABLE
  50. RESULT_VARIABLE PERL_VERSION_RESULT_VARIABLE
  51. ERROR_QUIET
  52. OUTPUT_STRIP_TRAILING_WHITESPACE
  53. )
  54. if(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl.*[ \\(]v([0-9\\._]+)[ \\)]")
  55. set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
  56. elseif(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl, version ([0-9\\._]+) +")
  57. set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
  58. endif()
  59. endif()
  60. endif()
  61. # Deprecated settings for compatibility with CMake1.4
  62. set(PERL ${PERL_EXECUTABLE})
  63. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  64. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Perl
  65. REQUIRED_VARS PERL_EXECUTABLE
  66. VERSION_VAR PERL_VERSION_STRING)
  67. mark_as_advanced(PERL_EXECUTABLE)