summaryrefslogtreecommitdiff
path: root/cmake/pcre.cmake
blob: 4c113929866574e121e619c8b0bb6f4be29e6449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
INCLUDE (CheckCSourceRuns)

SET(WITH_PCRE "auto" CACHE STRING
   "Which pcre to use (possible values are 'bundled', 'system', or 'auto')")

MACRO (CHECK_PCRE)
  IF(WITH_PCRE STREQUAL "system" OR WITH_PCRE STREQUAL "auto")
    CHECK_LIBRARY_EXISTS(pcre pcre_stack_guard "" HAVE_PCRE_STACK_GUARD)
    IF(NOT CMAKE_CROSSCOMPILING)
      SET(CMAKE_REQUIRED_LIBRARIES "pcre")
      CHECK_C_SOURCE_RUNS("
        #include <pcre.h>
        int main() {
        return -pcre_exec(NULL, NULL, NULL, -999, -999, 0, NULL, 0) < 256;
        }"  PCRE_STACK_SIZE_OK)
      SET(CMAKE_REQUIRED_LIBRARIES)
    ENDIF()
  ENDIF()
  IF(NOT HAVE_PCRE_STACK_GUARD OR NOT PCRE_STACK_SIZE_OK OR
     WITH_PCRE STREQUAL "bundled")
    IF (WITH_PCRE STREQUAL "system")
      MESSAGE(FATAL_ERROR "system pcre is not found or unusable")
    ENDIF()
    SET(PCRE_INCLUDES ${CMAKE_BINARY_DIR}/pcre ${CMAKE_SOURCE_DIR}/pcre)
    ADD_SUBDIRECTORY(pcre)
  ENDIF()
ENDMACRO()