Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 1 | # - Find pcre |
| 2 | # Find the native PCRE2 headers and libraries. |
| 3 | # |
| 4 | # PCRE2_INCLUDE_DIRS - where to find pcre.h, etc. |
| 5 | # PCRE2_LIBRARIES - List of libraries when using pcre. |
| 6 | # PCRE2_FOUND - True if pcre found. |
Michal Vasko | 57f8de6 | 2021-06-09 11:43:12 +0200 | [diff] [blame] | 7 | include(FindPackageHandleStandardArgs) |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 8 | |
Michal Vasko | 57f8de6 | 2021-06-09 11:43:12 +0200 | [diff] [blame] | 9 | if(PCRE2_LIBRARIES AND PCRE2_INCLUDE_DIRS) |
| 10 | # in cache already |
| 11 | set(PCRE2_FOUND TRUE) |
| 12 | else() |
| 13 | find_path(PCRE2_INCLUDE_DIR |
| 14 | NAMES |
| 15 | pcre2.h |
| 16 | PATHS |
| 17 | /usr/include |
| 18 | /usr/local/include |
| 19 | /opt/local/include |
| 20 | /sw/include |
| 21 | ${CMAKE_INCLUDE_PATH} |
| 22 | ${CMAKE_INSTALL_PREFIX}/include) |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 23 | |
Michal Vasko | 57f8de6 | 2021-06-09 11:43:12 +0200 | [diff] [blame] | 24 | # Look for the library. |
aPiecek | 0f58361 | 2023-05-30 11:28:36 +0200 | [diff] [blame] | 25 | if (WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") |
| 26 | # For the Debug build, the pcre2 library is called pcre2-8d. The Release build should be pcre2-8. |
| 27 | find_library(PCRE2_LIBRARY pcre2-8d) |
| 28 | else() |
| 29 | find_library(PCRE2_LIBRARY |
| 30 | NAMES |
aPiecek | 0f58361 | 2023-05-30 11:28:36 +0200 | [diff] [blame] | 31 | pcre2-8 |
| 32 | PATHS |
| 33 | /usr/lib |
| 34 | /usr/lib64 |
| 35 | /usr/local/lib |
| 36 | /usr/local/lib64 |
| 37 | /opt/local/lib |
| 38 | /sw/lib |
| 39 | ${CMAKE_LIBRARY_PATH} |
| 40 | ${CMAKE_INSTALL_PREFIX}/lib) |
| 41 | endif() |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 42 | |
Michal Vasko | 75518cf | 2021-06-10 16:07:12 +0200 | [diff] [blame] | 43 | if(PCRE2_INCLUDE_DIR AND PCRE2_LIBRARY) |
| 44 | # learn pcre2 version |
| 45 | file(STRINGS ${PCRE2_INCLUDE_DIR}/pcre2.h PCRE2_VERSION_MAJOR |
| 46 | REGEX "#define[ ]+PCRE2_MAJOR[ ]+[0-9]+") |
| 47 | string(REGEX MATCH " [0-9]+" PCRE2_VERSION_MAJOR ${PCRE2_VERSION_MAJOR}) |
| 48 | string(STRIP "${PCRE2_VERSION_MAJOR}" PCRE2_VERSION_MAJOR) |
| 49 | |
| 50 | file(STRINGS ${PCRE2_INCLUDE_DIR}/pcre2.h PCRE2_VERSION_MINOR |
| 51 | REGEX "#define[ ]+PCRE2_MINOR[ ]+[0-9]+") |
| 52 | string(REGEX MATCH " [0-9]+" PCRE2_VERSION_MINOR ${PCRE2_VERSION_MINOR}) |
| 53 | string(STRIP "${PCRE2_VERSION_MINOR}" PCRE2_VERSION_MINOR) |
| 54 | |
| 55 | set(PCRE2_VERSION ${PCRE2_VERSION_MAJOR}.${PCRE2_VERSION_MINOR}) |
Michal Vasko | 57f8de6 | 2021-06-09 11:43:12 +0200 | [diff] [blame] | 56 | endif() |
Radek Krejci | d9e68c4 | 2019-05-31 16:26:26 +0200 | [diff] [blame] | 57 | |
Michal Vasko | 57f8de6 | 2021-06-09 11:43:12 +0200 | [diff] [blame] | 58 | set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) |
| 59 | set(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) |
| 60 | mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES) |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 61 | |
Michal Vasko | 57f8de6 | 2021-06-09 11:43:12 +0200 | [diff] [blame] | 62 | # Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE. |
| 63 | find_package_handle_standard_args(PCRE2 FOUND_VAR PCRE2_FOUND |
| 64 | REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR |
| 65 | VERSION_VAR PCRE2_VERSION) |
| 66 | endif() |