FindPerl.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #.rst:
  2. # FindPerl
  3. # --------
  4. #
  5. # Find perl
  6. #
  7. # this module looks for Perl
  8. #
  9. # ::
  10. #
  11. # PERL_EXECUTABLE - the full path to perl
  12. # PERL_FOUND - If false, don't attempt to use perl.
  13. # PERL_VERSION_STRING - version of perl found (since CMake 2.8.8)
  14. #=============================================================================
  15. # Copyright 2001-2009 Kitware, Inc.
  16. #
  17. # Distributed under the OSI-approved BSD License (the "License");
  18. # see accompanying file Copyright.txt for details.
  19. #
  20. # This software is distributed WITHOUT ANY WARRANTY; without even the
  21. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # See the License for more information.
  23. #=============================================================================
  24. # (To distribute this file outside of CMake, substitute the full
  25. # License text for the above reference.)
  26. include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
  27. set(PERL_POSSIBLE_BIN_PATHS
  28. ${CYGWIN_INSTALL_PATH}/bin
  29. )
  30. if(WIN32)
  31. get_filename_component(
  32. ActivePerl_CurrentVersion
  33. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl;CurrentVersion]"
  34. NAME)
  35. set(PERL_POSSIBLE_BIN_PATHS ${PERL_POSSIBLE_BIN_PATHS}
  36. "C:/Perl/bin"
  37. [HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\${ActivePerl_CurrentVersion}]/bin
  38. )
  39. endif()
  40. find_program(PERL_EXECUTABLE
  41. NAMES perl
  42. PATHS ${PERL_POSSIBLE_BIN_PATHS}
  43. )
  44. if(PERL_EXECUTABLE)
  45. ### PERL_VERSION
  46. execute_process(
  47. COMMAND
  48. ${PERL_EXECUTABLE} -V:version
  49. OUTPUT_VARIABLE
  50. PERL_VERSION_OUTPUT_VARIABLE
  51. RESULT_VARIABLE
  52. PERL_VERSION_RESULT_VARIABLE
  53. ERROR_QUIET
  54. OUTPUT_STRIP_TRAILING_WHITESPACE
  55. )
  56. if(NOT PERL_VERSION_RESULT_VARIABLE AND NOT PERL_VERSION_OUTPUT_VARIABLE MATCHES "^version='UNKNOWN'")
  57. string(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION_STRING ${PERL_VERSION_OUTPUT_VARIABLE})
  58. else()
  59. execute_process(
  60. COMMAND ${PERL_EXECUTABLE} -v
  61. OUTPUT_VARIABLE PERL_VERSION_OUTPUT_VARIABLE
  62. RESULT_VARIABLE PERL_VERSION_RESULT_VARIABLE
  63. ERROR_QUIET
  64. OUTPUT_STRIP_TRAILING_WHITESPACE
  65. )
  66. if(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl.*[ \\(]v([0-9\\._]+)[ \\)]")
  67. set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
  68. elseif(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl, version ([0-9\\._]+) +")
  69. set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
  70. endif()
  71. endif()
  72. endif()
  73. # Deprecated settings for compatibility with CMake1.4
  74. set(PERL ${PERL_EXECUTABLE})
  75. # handle the QUIETLY and REQUIRED arguments and set PERL_FOUND to TRUE if
  76. # all listed variables are TRUE
  77. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  78. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Perl
  79. REQUIRED_VARS PERL_EXECUTABLE
  80. VERSION_VAR PERL_VERSION_STRING)
  81. mark_as_advanced(PERL_EXECUTABLE)