FindPCRE2.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #
  2. #
  3. # Locate pcre2
  4. #
  5. # This module accepts the following environment variables:
  6. #
  7. # PCRE2_DIR or PCRE2_ROOT - Specify the location of PCRE2
  8. #
  9. # This module defines the following CMake variables:
  10. #
  11. # PCRE2_FOUND - True if libpcre2 is found
  12. # PCRE2_LIBRARY - A variable pointing to the PCRE2 library
  13. # PCRE2_INCLUDE_DIR - Where to find the headers
  14. #=============================================================================
  15. # Inspired by FindGDAL
  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 COPYING-CMAKE-SCRIPTS for more information.
  23. #=============================================================================
  24. # This makes the presumption that you are include pcre2.h like
  25. #
  26. #include "pcre2.h"
  27. if (DEFINED PCRE2_ROOT AND NOT PCRE2_ROOT)
  28. set (PCRE2_LIBRARY "" CACHE INTERNAL "")
  29. set (PCRE2_INCLUDE_DIR "" CACHE INTERNAL "")
  30. return ()
  31. endif (DEFINED PCRE2_ROOT AND NOT PCRE2_ROOT)
  32. if (UNIX AND NOT PCRE2_FOUND)
  33. # Use pcre2-config to obtain the library location and name, something like
  34. # -L/sw/lib -lpcre2-8)
  35. find_program (PCRE2_CONFIG pcre2-config
  36. HINTS
  37. ${PCRE2_DIR}
  38. ${PCRE2_ROOT}
  39. $ENV{PCRE2_DIR}
  40. $ENV{PCRE2_ROOT}
  41. PATH_SUFFIXES bin
  42. PATHS
  43. /sw # Fink
  44. /opt/local # DarwinPorts
  45. /opt/csw # Blastwave
  46. /opt
  47. /usr/local
  48. )
  49. if (PCRE2_CONFIG)
  50. execute_process (COMMAND ${PCRE2_CONFIG} --cflags
  51. ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
  52. OUTPUT_VARIABLE PCRE2_CONFIG_CFLAGS)
  53. if (PCRE2_CONFIG_CFLAGS)
  54. string (REGEX MATCHALL "-I[^ ]+" _pcre2_dashI ${PCRE2_CONFIG_CFLAGS})
  55. string (REGEX REPLACE "-I" "" _pcre2_includepath "${_pcre2_dashI}")
  56. string (REGEX REPLACE "-I[^ ]+" "" _pcre2_cflags_other ${PCRE2_CONFIG_CFLAGS})
  57. endif (PCRE2_CONFIG_CFLAGS)
  58. execute_process (COMMAND ${PCRE2_CONFIG} --libs8
  59. ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
  60. OUTPUT_VARIABLE PCRE2_CONFIG_LIBS)
  61. if (PCRE2_CONFIG_LIBS)
  62. string (REGEX MATCHALL "-l[^ ]+" _pcre2_dashl ${PCRE2_CONFIG_LIBS})
  63. string (REGEX REPLACE "-l" "" _pcre2_lib "${_pcre2_dashl}")
  64. string (REGEX MATCHALL "-L[^ ]+" _pcre2_dashL ${PCRE2_CONFIG_LIBS})
  65. string (REGEX REPLACE "-L" "" _pcre2_libpath "${_pcre2_dashL}")
  66. endif (PCRE2_CONFIG_LIBS)
  67. endif (PCRE2_CONFIG)
  68. endif (UNIX AND NOT PCRE2_FOUND)
  69. find_path (PCRE2_INCLUDE_DIR pcre2.h
  70. HINTS
  71. ${_pcre2_includepath}
  72. ${PCRE2_DIR}
  73. ${PCRE2_ROOT}
  74. $ENV{PCRE2_DIR}
  75. $ENV{PCRE2_ROOT}
  76. PATH_SUFFIXES
  77. include/pcre2
  78. include/PCRE2
  79. include
  80. PATHS
  81. ~/Library/Frameworks/pcre2.framework/Headers
  82. /Library/Frameworks/pcre2.framework/Headers
  83. /sw # Fink
  84. /opt/local # DarwinPorts
  85. /opt/csw # Blastwave
  86. /opt
  87. /usr/local
  88. )
  89. find_library (PCRE2_LIBRARY
  90. NAMES ${_pcre2_lib} pcre2-8 PCRE2
  91. HINTS
  92. ${PCRE2_DIR}
  93. ${PCRE2_ROOT}
  94. $ENV{PCRE2_DIR}
  95. $ENV{PCRE2_ROOT}
  96. ${_pcre2_libpath}
  97. PATH_SUFFIXES lib
  98. PATHS
  99. ~/Library/Frameworks/pcre2.framework
  100. /Library/Frameworks/pcre2.framework
  101. /sw
  102. /opt/local
  103. /opt/csw
  104. /opt
  105. /usr/local
  106. )
  107. include (FindPackageHandleStandardArgs)
  108. find_package_handle_standard_args (PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)
  109. set (PCRE2_LIBRARIES ${PCRE2_LIBRARY})
  110. set (PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})