github的一些开源项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.1 KiB

  1. # pcre2-config.cmake
  2. # ----------------
  3. #
  4. # Finds the PCRE2 library, specify the starting search path in PCRE2_ROOT.
  5. #
  6. # Static vs. shared
  7. # -----------------
  8. # To make use of the static library instead of the shared one, one needs
  9. # to set the variable PCRE2_USE_STATIC_LIBS to ON before calling find_package.
  10. # Example:
  11. # set(PCRE2_USE_STATIC_LIBS ON)
  12. # find_package(PCRE2 CONFIG COMPONENTS 8BIT)
  13. #
  14. # This will define the following variables:
  15. #
  16. # PCRE2_FOUND - True if the system has the PCRE2 library.
  17. # PCRE2_VERSION - The version of the PCRE2 library which was found.
  18. #
  19. # and the following imported targets:
  20. #
  21. # PCRE2::8BIT - The 8 bit PCRE2 library.
  22. # PCRE2::16BIT - The 16 bit PCRE2 library.
  23. # PCRE2::32BIT - The 32 bit PCRE2 library.
  24. # PCRE2::POSIX - The POSIX PCRE2 library.
  25. set(PCRE2_NON_STANDARD_LIB_PREFIX @NON_STANDARD_LIB_PREFIX@)
  26. set(PCRE2_NON_STANDARD_LIB_SUFFIX @NON_STANDARD_LIB_SUFFIX@)
  27. set(PCRE2_8BIT_NAME pcre2-8)
  28. set(PCRE2_16BIT_NAME pcre2-16)
  29. set(PCRE2_32BIT_NAME pcre2-32)
  30. set(PCRE2_POSIX_NAME pcre2-posix)
  31. find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h DOC "PCRE2 include directory")
  32. if (PCRE2_USE_STATIC_LIBS)
  33. if (MSVC)
  34. set(PCRE2_8BIT_NAME pcre2-8-static)
  35. set(PCRE2_16BIT_NAME pcre2-16-static)
  36. set(PCRE2_32BIT_NAME pcre2-32-static)
  37. set(PCRE2_POSIX_NAME pcre2-posix-static)
  38. endif ()
  39. set(PCRE2_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
  40. set(PCRE2_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
  41. else ()
  42. set(PCRE2_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
  43. if (MINGW AND PCRE2_NON_STANDARD_LIB_PREFIX)
  44. set(PCRE2_PREFIX "")
  45. endif ()
  46. set(PCRE2_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
  47. if (MINGW AND PCRE2_NON_STANDARD_LIB_SUFFIX)
  48. set(PCRE2_SUFFIX "-0.dll")
  49. elseif(MSVC)
  50. set(PCRE2_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
  51. endif ()
  52. endif ()
  53. find_library(PCRE2_8BIT_LIBRARY NAMES ${PCRE2_PREFIX}${PCRE2_8BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_8BIT_NAME}d${PCRE2_SUFFIX} DOC "8 bit PCRE2 library")
  54. find_library(PCRE2_16BIT_LIBRARY NAMES ${PCRE2_PREFIX}${PCRE2_16BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_16BIT_NAME}d${PCRE2_SUFFIX} DOC "16 bit PCRE2 library")
  55. find_library(PCRE2_32BIT_LIBRARY NAMES ${PCRE2_PREFIX}${PCRE2_32BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_32BIT_NAME}d${PCRE2_SUFFIX} DOC "32 bit PCRE2 library")
  56. find_library(PCRE2_POSIX_LIBRARY NAMES ${PCRE2_PREFIX}${PCRE2_POSIX_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_POSIX_NAME}d${PCRE2_SUFFIX} DOC "8 bit POSIX PCRE2 library")
  57. unset(PCRE2_NON_STANDARD_LIB_PREFIX)
  58. unset(PCRE2_NON_STANDARD_LIB_SUFFIX)
  59. unset(PCRE2_8BIT_NAME)
  60. unset(PCRE2_16BIT_NAME)
  61. unset(PCRE2_32BIT_NAME)
  62. unset(PCRE2_POSIX_NAME)
  63. # Set version
  64. if (PCRE2_INCLUDE_DIR)
  65. set(PCRE2_VERSION "@PCRE2_MAJOR@.@PCRE2_MINOR@.0")
  66. endif ()
  67. # Which components have been found.
  68. if (PCRE2_8BIT_LIBRARY)
  69. set(PCRE2_8BIT_FOUND TRUE)
  70. endif ()
  71. if (PCRE2_16BIT_LIBRARY)
  72. set(PCRE2_16BIT_FOUND TRUE)
  73. endif ()
  74. if (PCRE2_32BIT_LIBRARY)
  75. set(PCRE2_32BIT_FOUND TRUE)
  76. endif ()
  77. if (PCRE2_POSIX_LIBRARY)
  78. set(PCRE2_POSIX_FOUND TRUE)
  79. endif ()
  80. # Check if at least one component has been specified.
  81. list(LENGTH PCRE2_FIND_COMPONENTS PCRE2_NCOMPONENTS)
  82. if (PCRE2_NCOMPONENTS LESS 1)
  83. message(FATAL_ERROR "No components have been specified. This is not allowed. Please, specify at least one component.")
  84. endif ()
  85. unset(PCRE2_NCOMPONENTS)
  86. # When POSIX component has been specified make sure that also 8BIT component is specified.
  87. set(PCRE2_8BIT_COMPONENT FALSE)
  88. set(PCRE2_POSIX_COMPONENT FALSE)
  89. foreach(component ${PCRE2_FIND_COMPONENTS})
  90. if (component STREQUAL "8BIT")
  91. set(PCRE2_8BIT_COMPONENT TRUE)
  92. elseif (component STREQUAL "POSIX")
  93. set(PCRE2_POSIX_COMPONENT TRUE)
  94. endif ()
  95. endforeach()
  96. if (PCRE2_POSIX_COMPONENT AND NOT PCRE2_8BIT_COMPONENT)
  97. message(FATAL_ERROR "The component POSIX is specified while the 8BIT one is not. This is not allowed. Please, also specify the 8BIT component.")
  98. endif()
  99. unset(PCRE2_8BIT_COMPONENT)
  100. unset(PCRE2_POSIX_COMPONENT)
  101. include(FindPackageHandleStandardArgs)
  102. set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
  103. find_package_handle_standard_args(PCRE2
  104. FOUND_VAR PCRE2_FOUND
  105. REQUIRED_VARS PCRE2_INCLUDE_DIR
  106. HANDLE_COMPONENTS
  107. VERSION_VAR PCRE2_VERSION
  108. CONFIG_MODE
  109. )
  110. set(PCRE2_LIBRARIES)
  111. if (PCRE2_FOUND)
  112. foreach(component ${PCRE2_FIND_COMPONENTS})
  113. if (PCRE2_USE_STATIC_LIBS)
  114. add_library(PCRE2::${component} STATIC IMPORTED)
  115. target_compile_definitions(PCRE2::${component} INTERFACE PCRE2_STATIC)
  116. else ()
  117. add_library(PCRE2::${component} SHARED IMPORTED)
  118. endif ()
  119. set_target_properties(PCRE2::${component} PROPERTIES
  120. IMPORTED_LOCATION "${PCRE2_${component}_LIBRARY}"
  121. IMPORTED_IMPLIB "${PCRE2_${component}_LIBRARY}"
  122. INTERFACE_INCLUDE_DIRECTORIES "${PCRE2_INCLUDE_DIR}"
  123. )
  124. if (component STREQUAL "POSIX")
  125. set_target_properties(PCRE2::${component} PROPERTIES
  126. INTERFACE_LINK_LIBRARIES "PCRE2::8BIT"
  127. LINK_LIBRARIES "PCRE2::8BIT"
  128. )
  129. endif ()
  130. set(PCRE2_LIBRARIES ${PCRE2_LIBRARIES} ${PCRE2_${component}_LIBRARY})
  131. mark_as_advanced(PCRE2_${component}_LIBRARY)
  132. endforeach()
  133. endif ()
  134. mark_as_advanced(
  135. PCRE2_INCLUDE_DIR
  136. )