INCLUDE(FindPackageHandleStandardArgs)

IF (NOT PCRE_INCLUDE_DIR)
    FIND_PATH(PCRE_INCLUDE_DIR pcre.h HINTS $ENV{PCRE_DIR})
ENDIF()

IF (NOT PCRE_LIBRARIES)
    IF (NOT PCREPOSIX_LIBRARY)
        FIND_LIBRARY(PCREPOSIX_LIBRARY pcreposix HINTS $ENV{PCRE_DIR})
    ENDIF()

    IF (NOT PCRE_LIBRARY)
        FIND_LIBRARY(PCRE_LIBRARY pcre HINTS $ENV{PCRE_DIR})
    ENDIF()

    IF (PCRE_LIBRARY AND PCREPOSIX_LIBRARY)
        SET(PCRE_LIBRARIES ${PCREPOSIX_LIBRARY} ${PCRE_LIBRARY})
    ENDIF()
ENDIF()

MARK_AS_ADVANCED(PCRE_INCLUDE_DIR)
MARK_AS_ADVANCED(PCREPOSIX_LIBRARY)
MARK_AS_ADVANCED(PCRE_LIBRARY)
MARK_AS_ADVANCED(PCRE_LIBRARIES)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(
    PCRE
    DEFAULT_MSG
    PCRE_LIBRARIES
    PCRE_INCLUDE_DIR
)

