2017-10-04 20:31:35 -07:00
# PCRE2 needs some settings.
2020-03-14 16:11:35 -07:00
set ( PCRE2_WIDTH ${ WCHAR_T_BITS } )
set ( PCRE2_BUILD_PCRE2_8 OFF CACHE BOOL "Build 8bit PCRE2 library" )
set ( PCRE2_BUILD_PCRE2_ ${ PCRE2_WIDTH } ON CACHE BOOL "Build ${PCRE2_WIDTH}bit PCRE2 library" )
set ( PCRE2_SHOW_REPORT OFF CACHE BOOL "Show the final configuration report" )
set ( PCRE2_BUILD_TESTS OFF CACHE BOOL "Build tests" )
set ( PCRE2_BUILD_PCRE2GREP OFF CACHE BOOL "Build pcre2grep" )
2017-10-04 20:31:35 -07:00
2022-07-10 12:44:35 -07:00
set ( PCRE2_MIN_VERSION 10.21 )
2020-04-28 13:07:03 -07:00
# Look for a system-installed PCRE2.
find_library ( SYS_PCRE2_LIB pcre2- ${ PCRE2_WIDTH } )
find_path ( SYS_PCRE2_INCLUDE_DIR pcre2.h )
# We can either use the system-installed PCRE or our bundled version.
# This is controlled by the cache variable FISH_USE_SYSTEM_PCRE2.
# Here we compute the default value for that variable.
if ( ( APPLE ) AND ( MAC_CODESIGN_ID ) )
# On Mac, a codesigned fish will refuse to load a non-codesigned PCRE2
# (e.g. from Homebrew) so default to bundled PCRE2.
set ( USE_SYS_PCRE2_DEFAULT OFF )
elseif ( ( NOT SYS_PCRE2_LIB ) OR ( NOT SYS_PCRE2_INCLUDE_DIR ) )
# We did not find system PCRE2, so default to bundled.
set ( USE_SYS_PCRE2_DEFAULT OFF )
else ( )
# Default to using the system PCRE2, which was found.
set ( USE_SYS_PCRE2_DEFAULT ON )
2020-03-14 16:11:35 -07:00
endif ( )
2020-04-28 13:07:03 -07:00
set ( FISH_USE_SYSTEM_PCRE2 ${ USE_SYS_PCRE2_DEFAULT } CACHE BOOL
2021-10-16 23:04:23 -07:00
" U s e P C R E 2 f r o m t h e s y s t e m , i n s t e a d o f f e t c h i n g a n d b u i l d i n g i t " )
2020-04-28 13:07:03 -07:00
if ( FISH_USE_SYSTEM_PCRE2 )
set ( PCRE2_LIB "${SYS_PCRE2_LIB}" )
set ( PCRE2_INCLUDE_DIR "${SYS_PCRE2_INCLUDE_DIR}" )
message ( STATUS "Using system PCRE2 library ${PCRE2_INCLUDE_DIR}" )
2020-03-14 16:11:35 -07:00
else ( )
2021-10-16 23:04:23 -07:00
include ( FetchContent RESULT_VARIABLE HAVE_FetchContent )
if ( ${ HAVE_FetchContent } STREQUAL "NOTFOUND" )
message ( FATAL_ERROR "Please install PCRE2 headers, or CMake >= 3.11 so I can download PCRE" )
endif ( )
set ( CMAKE_TLS_VERIFY true )
2022-10-14 21:38:01 -05:00
set ( PCRE2_REPO "https://github.com/PCRE2Project/pcre2.git" )
2021-10-16 23:04:23 -07:00
message ( STATUS "Fetching and configuring PCRE2 from ${PCRE2_REPO}" )
Set ( FETCHCONTENT_QUIET FALSE )
FetchContent_Declare (
p c r e 2
G I T _ R E P O S I T O R Y $ { P C R E 2 _ R E P O }
2022-10-28 17:59:08 -05:00
G I T _ T A G " 7 2 6 6 9 1 9 0 c b 9 4 7 f 0 c a c 1 d 0 3 8 a 8 b b 1 8 2 0 d a 5 9 e f 4 4 7 " # tag: pcre2-10.36
2022-10-28 13:58:59 -05:00
G I T _ S H A L L O W O N
2021-10-16 23:04:23 -07:00
G I T _ P R O G R E S S T R U E
)
# Don't try FetchContent_MakeAvailable, there's no way to add EXCLUDE_FROM_ALL
# so we end up installing all of PCRE2 including its headers, man pages, etc.
FetchContent_GetProperties ( pcre2 )
if ( NOT pcre2_POPULATED )
2022-08-06 12:52:11 -07:00
# If GIT_WORK_TREE is set (by user or by git itself with e.g. git rebase), it
# will override the git directory which CMake tries to apply in FetchContent_Populate,
# resulting in a failed checkout.
# Ensure it is not set.
unset ( ENV{GIT_WORK_TREE} )
unset ( ENV{GIT_DIR} )
2021-10-16 23:04:23 -07:00
FetchContent_Populate ( pcre2 )
add_subdirectory ( ${ pcre2_SOURCE_DIR } ${ pcre2_BINARY_DIR } EXCLUDE_FROM_ALL )
endif ( )
set ( PCRE2_INCLUDE_DIR ${ pcre2_BINARY_DIR } )
2020-03-14 16:11:35 -07:00
set ( PCRE2_LIB pcre2- ${ PCRE2_WIDTH } )
2021-10-16 13:48:57 -07:00
# Disable -Wunused-macros inside PCRE2, as it is noisy.
get_target_property ( PCRE2_COMPILE_OPTIONS ${ PCRE2_LIB } COMPILE_OPTIONS )
list ( REMOVE_ITEM PCRE2_COMPILE_OPTIONS "-Wunused-macros" )
set_property ( TARGET ${ PCRE2_LIB } PROPERTY COMPILE_OPTIONS ${ PCRE2_COMPILE_OPTIONS } )
2020-04-28 13:07:03 -07:00
endif ( FISH_USE_SYSTEM_PCRE2 )
2020-03-14 16:11:35 -07:00
include_directories ( ${ PCRE2_INCLUDE_DIR } )