Files
shadowsocks-libev/cmake/FindPCRE2.cmake
Max LvandClaude Opus 4.6 e36d03b5f6 Migrate from PCRE to PCRE2
Replace legacy PCRE (libpcre3) with PCRE2 (libpcre2-8). PCRE1 has been
end-of-life since 2021.

- src/rule.h: use pcre2_code and pcre2_match_data types
- src/rule.c: pcre_compile -> pcre2_compile, pcre_exec -> pcre2_match,
  pcre_free -> pcre2_code_free, with proper error message retrieval
- cmake/FindPCRE.cmake -> cmake/FindPCRE2.cmake: find libpcre2-8 via
  pkg-config, pcre2-config, or manual search
- Update all CMakeLists.txt, config.h.cmake, configure.cmake, README.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 16:40:27 +08:00

64 lines
1.7 KiB
CMake

# FindPCRE2.cmake - Find PCRE2 library (8-bit)
#
# Sets:
# PCRE2_FOUND
# PCRE2_INCLUDE_DIRS
# PCRE2_LIBRARIES
include(FindPkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(_PCRE2 QUIET libpcre2-8)
endif()
if(_PCRE2_FOUND)
set(PCRE2_INCLUDE_DIRS ${_PCRE2_INCLUDE_DIRS})
set(PCRE2_LIBRARIES ${_PCRE2_LIBRARIES})
set(PCRE2_FOUND TRUE)
else()
# Try pcre2-config
find_program(PCRE2_CONFIG pcre2-config)
if(PCRE2_CONFIG)
execute_process(COMMAND ${PCRE2_CONFIG} --cflags
OUTPUT_VARIABLE PCRE2_CFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PCRE2_CONFIG} --libs8
OUTPUT_VARIABLE PCRE2_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "-I" "" PCRE2_INCLUDE_DIRS "${PCRE2_CFLAGS}")
set(PCRE2_LIBRARIES ${PCRE2_LDFLAGS})
set(PCRE2_FOUND TRUE)
else()
# Manual search
find_path(PCRE2_INCLUDE_DIR
NAMES pcre2.h
HINTS
/opt/homebrew/include
/usr/local/include
/usr/include
)
find_library(PCRE2_LIBRARY
NAMES pcre2-8
HINTS
/opt/homebrew/lib
/usr/local/lib
/usr/lib
)
if(PCRE2_INCLUDE_DIR AND PCRE2_LIBRARY)
set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
set(PCRE2_FOUND TRUE)
else()
set(PCRE2_FOUND FALSE)
endif()
endif()
endif()
if(PCRE2_FOUND)
message(STATUS "Found PCRE2: ${PCRE2_LIBRARIES}")
else()
message(FATAL_ERROR "Could not find PCRE2 library. Install libpcre2-dev or equivalent.")
endif()