FindPCRE2.cmake 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. FindPCRE2
  5. ---------
  6. Finds the PCRE2 library.
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. This module provides the following imported targets, if found:
  10. ``Pcre2::Pcre2``
  11. The PCRE2 library
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This will define the following variables:
  15. ``PCRE2_FOUND``
  16. True if the system has the PCRE2 library.
  17. ``PCRE2_VERSION``
  18. The version of the PCRE2 library which was found.
  19. ``PCRE2_INCLUDE_DIRS``
  20. Include directories needed to use PCRE2.
  21. ``PCRE2_LIBRARIES``
  22. Libraries needed to link to PCRE2.
  23. Cache Variables
  24. ^^^^^^^^^^^^^^^
  25. The following cache variables may also be set:
  26. ``PCRE2_INCLUDE_DIR``
  27. The directory containing ``pcre2.h``.
  28. ``PCRE2_LIBRARY``
  29. The path to the PCRE2 library.
  30. Hints
  31. ^^^^^
  32. ``PCRE2_ROOT_DIR``
  33. The path to the root directory of a PCRE2 installation.
  34. ``PCRE2_ROOT_INCLUDE_DIRS``
  35. The path to the include directory of a PCRE2 installation.
  36. ``PCRE2_ROOT_LIBRARY_DIRS``
  37. The path to the library directory of a PCRE2 installation.
  38. #]=======================================================================]#
  39. include(FindPackageHandleStandardArgs)
  40. find_package(PkgConfig QUIET)
  41. pkg_check_modules(PC_PCRE2 QUIET pcre2)
  42. find_path(PCRE2_INCLUDE_DIR
  43. NAMES pcre2.h
  44. HINTS
  45. ${PCRE2_ROOT_DIR}/include
  46. ${PCRE2_ROOT_INCLUDE_DIRS}
  47. PATHS
  48. ${PC_PCRE2_INCLUDE_DIRS}
  49. DOC "Specify the include directory containing pcre2.h"
  50. )
  51. find_library(PCRE2_LIBRARY
  52. NAMES pcre2-8
  53. HINTS
  54. ${PCRE2_ROOT_DIR}/lib
  55. ${PCRE2_ROOT_LIBRARY_DIRS}
  56. PATHS
  57. ${PC_PCRE2_LIBRARY_DIRS}
  58. DOC "Specify the lib directory containing pcre2"
  59. )
  60. set(PCRE2_VERSION ${PC_PCRE2_VERSION})
  61. find_package_handle_standard_args(PCRE2
  62. FOUND_VAR PCRE2_FOUND
  63. REQUIRED_VARS
  64. PCRE2_LIBRARY
  65. PCRE2_INCLUDE_DIR
  66. VERSION_VAR PCRE2_VERSION
  67. )
  68. if(PCRE2_FOUND)
  69. set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
  70. set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
  71. set(PCRE2_DEFINITIONS ${PC_PCRE2_CFLAGS_OTHER})
  72. endif()
  73. if(PCRE2_FOUND AND NOT TARGET Pcre2::Pcre2)
  74. add_library(Pcre2::Pcre2 UNKNOWN IMPORTED)
  75. set_target_properties(Pcre2::Pcre2 PROPERTIES
  76. IMPORTED_LOCATION "${PCRE2_LIBRARY}"
  77. INTERFACE_COMPILE_OPTIONS "${PC_PCRE2_CFLAGS_OTHER}"
  78. INTERFACE_INCLUDE_DIRECTORIES "${PCRE2_INCLUDE_DIR}"
  79. )
  80. endif()
  81. mark_as_advanced(
  82. PCRE2_INCLUDE_DIR
  83. PCRE2_LIBRARY
  84. )