Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 90 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
# Applied to all CMake files using:
# > pip3 install gersemi
# > gersemi --in-place --line-length 120 --indent 2 \
# ./CMakeLists.txt ./cmake/*.cmake ./cmake/*.cmake.in
# --definitions cmake/*.cmake \
# -- ./CMakeLists.txt ./cmake/*.cmake ./cmake/*.cmake.in
################################################################################

# Increased minimum to 3.15 to allow use of string(REPEAT).
Expand All @@ -123,10 +124,12 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
# recently added to CMake for the `cc` compiler (Oracle Developer Studio). The
# CMake version from OpenCSW and Oracle's package repository is too old and
# requires this fix.
if (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND
CMAKE_VERSION VERSION_LESS 3.31 AND
CMAKE_C_COMPILER_ID STREQUAL "SunPro" AND
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.15)
if(
CMAKE_SYSTEM_NAME STREQUAL "SunOS"
AND CMAKE_VERSION VERSION_LESS 3.31
AND CMAKE_C_COMPILER_ID STREQUAL "SunPro"
AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.15
)
set(CMAKE_C_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
endif()

Expand Down Expand Up @@ -158,6 +161,7 @@ include(CheckSymbolExists)
include(CheckIncludeFile)
include(CheckTypeSize)
include(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR
include(PCRE2CheckLinkerFlag)

check_include_file(assert.h HAVE_ASSERT_H)
check_include_file(dirent.h HAVE_DIRENT_H)
Expand Down Expand Up @@ -200,6 +204,12 @@ check_c_source_compiles(
HAVE_VISIBILITY
)

if(HAVE_VISIBILITY)
set(PCRE2_EXPORT [=[__attribute__ ((visibility ("default")))]=])
else()
set(PCRE2_EXPORT)
endif()

set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})

check_c_source_compiles("int main(void) { __assume(1); return 0; }" HAVE_BUILTIN_ASSUME)
Expand All @@ -217,11 +227,33 @@ check_c_source_compiles(
HAVE_BUILTIN_UNREACHABLE
)

if(HAVE_VISIBILITY)
set(PCRE2_EXPORT [=[__attribute__ ((visibility ("default")))]=])
else()
set(PCRE2_EXPORT)
# Detect support for linker scripts.

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test-map-file.sym "PCRE2_10.00 { global: main; };")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test-map-file-broken.sym "PCRE2_10.00 { global: main; }; {")
pcre2_check_linker_flag(C -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/test-map-file.sym HAVE_VSCRIPT_GNU)
pcre2_check_linker_flag(C -Wl,-M,${CMAKE_CURRENT_BINARY_DIR}/test-map-file.sym HAVE_VSCRIPT_SUN)
if(HAVE_VSCRIPT_GNU)
set(VSCRIPT_FLAG --version-script)
set(HAVE_VSCRIPT TRUE)
elseif(HAVE_VSCRIPT_SUN)
set(VSCRIPT_FLAG -M)
set(HAVE_VSCRIPT TRUE)
endif()
if(HAVE_VSCRIPT)
# Perform the same logic as ax_check_vscript.m4, to test whether the linker
# silently ignores (and overwrites) linker scripts it doesn't understand.
pcre2_check_linker_flag(
C
-Wl,${VSCRIPT_FLAG},${CMAKE_CURRENT_BINARY_DIR}/test-map-file-broken.sym
HAVE_VSCRIPT_BROKEN
)
if(HAVE_VSCRIPT_BROKEN)
set(HAVE_VSCRIPT FALSE)
endif()
endif()
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/test-map-file.sym)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/test-map-file-broken.sym)

# Check whether Intel CET is enabled, and if so, adjust compiler flags. This
# code was written by PH, trying to imitate the logic from the autotools
Expand Down Expand Up @@ -272,7 +304,12 @@ set(

set(PCRE2_EBCDIC_NL25 OFF CACHE BOOL "Use 0x25 as EBCDIC NL character instead of 0x15; implies EBCDIC.")

set(PCRE2_EBCDIC_IGNORING_COMPILER OFF CACHE BOOL "Force EBCDIC 1047 using numeric literals rather than C character literals; implies EBCDIC.")
set(
PCRE2_EBCDIC_IGNORING_COMPILER
OFF
CACHE BOOL
"Force EBCDIC 1047 using numeric literals rather than C character literals; implies EBCDIC."
)

option(PCRE2_REBUILD_CHARTABLES "Rebuild char tables" OFF)

Expand Down Expand Up @@ -388,6 +425,10 @@ if(MSVC)
option(INSTALL_MSVC_PDB "ON=Install .pdb files built by MSVC, if generated" OFF)
endif()

if(HAVE_VSCRIPT)
option(PCRE2_SYMVERS "Enable library symbol versioning" ON)
endif()

# bzip2 lib
if(BZIP2_FOUND)
option(PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON)
Expand Down Expand Up @@ -705,9 +746,17 @@ if(REBUILD_CHARTABLES)
elseif(NOT PCRE2_EBCDIC)
configure_file(${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.dist ${PROJECT_BINARY_DIR}/pcre2_chartables.c COPYONLY)
elseif(PCRE2_EBCDIC_NL25)
configure_file(${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.ebcdic-1047-nl25 ${PROJECT_BINARY_DIR}/pcre2_chartables.c COPYONLY)
configure_file(
${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.ebcdic-1047-nl25
${PROJECT_BINARY_DIR}/pcre2_chartables.c
COPYONLY
)
else()
configure_file(${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.ebcdic-1047-nl15 ${PROJECT_BINARY_DIR}/pcre2_chartables.c COPYONLY)
configure_file(
${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.ebcdic-1047-nl15
${PROJECT_BINARY_DIR}/pcre2_chartables.c
COPYONLY
)
endif()

# Source code
Expand Down Expand Up @@ -882,6 +931,10 @@ if(PCRE2_BUILD_PCRE2_8)
if(REQUIRE_PTHREAD)
target_link_libraries(pcre2-8-shared Threads::Threads)
endif()
if(HAVE_VSCRIPT AND PCRE2_SYMVERS)
target_link_options(pcre2-8-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-8.sym)
set_target_properties(pcre2-8-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-8.sym)
endif()
set(TARGETS ${TARGETS} pcre2-8-shared)
set(DLL_PDB_FILES $<TARGET_PDB_FILE_DIR:pcre2-8-shared>/pcre2-8.pdb ${DLL_PDB_FILES})
set(DLL_PDB_DEBUG_FILES $<TARGET_PDB_FILE_DIR:pcre2-8-shared>/pcre2-8d.pdb ${DLL_PDB_DEBUG_FILES})
Expand All @@ -898,6 +951,10 @@ if(PCRE2_BUILD_PCRE2_8)
SOVERSION ${LIBPCRE2_POSIX_SOVERSION}
OUTPUT_NAME pcre2-posix
)
if(HAVE_VSCRIPT AND PCRE2_SYMVERS)
target_link_options(pcre2-posix-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-posix.sym)
set_target_properties(pcre2-posix-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-posix.sym)
endif()
set(PCRE2POSIX_CFLAG "-DPCRE2POSIX_SHARED")
target_compile_definitions(pcre2-posix-shared PUBLIC ${PCRE2POSIX_CFLAG})
target_link_libraries(pcre2-posix-shared pcre2-8-shared)
Expand Down Expand Up @@ -971,6 +1028,10 @@ if(PCRE2_BUILD_PCRE2_16)
if(REQUIRE_PTHREAD)
target_link_libraries(pcre2-16-shared Threads::Threads)
endif()
if(HAVE_VSCRIPT AND PCRE2_SYMVERS)
target_link_options(pcre2-16-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-16.sym)
set_target_properties(pcre2-16-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-16.sym)
endif()
set(TARGETS ${TARGETS} pcre2-16-shared)
set(DLL_PDB_FILES $<TARGET_PDB_FILE_DIR:pcre2-16-shared>/pcre2-16.pdb ${DLL_PDB_FILES})
set(DLL_PDB_DEBUG_FILES $<TARGET_PDB_FILE_DIR:pcre2-16-shared>/pcre2-16d.pdb ${DLL_PDB_DEBUG_FILES})
Expand Down Expand Up @@ -1039,6 +1100,10 @@ if(PCRE2_BUILD_PCRE2_32)
if(REQUIRE_PTHREAD)
target_link_libraries(pcre2-32-shared Threads::Threads)
endif()
if(HAVE_VSCRIPT AND PCRE2_SYMVERS)
target_link_options(pcre2-32-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-32.sym)
set_target_properties(pcre2-32-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-32.sym)
endif()
set(TARGETS ${TARGETS} pcre2-32-shared)
set(DLL_PDB_FILES $<TARGET_PDB_FILE_DIR:pcre2-32-shared>/pcre2-32.pdb ${DLL_PDB_FILES})
set(DLL_PDB_DEBUG_FILES $<TARGET_PDB_FILE_DIR:pcre2-32-shared>/pcre2-32d.pdb ${DLL_PDB_DEBUG_FILES})
Expand Down Expand Up @@ -1372,9 +1437,9 @@ if(PCRE2_SHOW_REPORT)
else()
message(STATUS " Build type ........................ : ${CMAKE_BUILD_TYPE}")
endif()
message(STATUS " Build 8 bit PCRE2 library ......... : ${PCRE2_BUILD_PCRE2_8}")
message(STATUS " Build 16 bit PCRE2 library ........ : ${PCRE2_BUILD_PCRE2_16}")
message(STATUS " Build 32 bit PCRE2 library ........ : ${PCRE2_BUILD_PCRE2_32}")
message(STATUS " Build 8 bit pcre2 library ......... : ${PCRE2_BUILD_PCRE2_8}")
message(STATUS " Build 16 bit pcre2 library ........ : ${PCRE2_BUILD_PCRE2_16}")
message(STATUS " Build 32 bit pcre2 library ........ : ${PCRE2_BUILD_PCRE2_32}")
message(STATUS " Include debugging code ............ : ${PCRE2_DEBUG}")
message(STATUS " Enable JIT compiling support ...... : ${PCRE2_SUPPORT_JIT}")
message(STATUS " Use SELinux allocator in JIT ...... : ${PCRE2_SUPPORT_JIT_SEALLOC}")
Expand All @@ -1397,18 +1462,24 @@ if(PCRE2_SHOW_REPORT)

message(STATUS " Internal link size ................ : ${PCRE2_LINK_SIZE}")
message(STATUS " Maximum variable lookbehind ....... : ${PCRE2_MAX_VARLOOKBEHIND}")
message(STATUS " Parentheses nest limit ............ : ${PCRE2_PARENS_NEST_LIMIT}")
message(STATUS " Nested parentheses limit .......... : ${PCRE2_PARENS_NEST_LIMIT}")
message(STATUS " Heap limit ........................ : ${PCRE2_HEAP_LIMIT}")
message(STATUS " Match limit ....................... : ${PCRE2_MATCH_LIMIT}")
message(STATUS " Match depth limit ................. : ${PCRE2_MATCH_LIMIT_DEPTH}")
message(STATUS " Build shared libs ................. : ${BUILD_SHARED_LIBS}")
if(NOT HAVE_VSCRIPT)
message(STATUS " with symbol versioning ........ : n/a")
else()
message(STATUS " with symbol versioning ........ : ${PCRE2_SYMVERS}")
endif()
message(STATUS " Build static libs ................. : ${BUILD_STATIC_LIBS}")
message(STATUS " with PIC enabled ............... : ${PCRE2_STATIC_PIC}")
message(STATUS " with PIC enabled .............. : ${PCRE2_STATIC_PIC}")
message(STATUS " Build pcre2grep ................... : ${PCRE2_BUILD_PCRE2GREP}")
message(STATUS " Enable JIT in pcre2grep ........... : ${PCRE2GREP_SUPPORT_JIT}")
message(STATUS " Enable callouts in pcre2grep ...... : ${PCRE2GREP_SUPPORT_CALLOUT}")
message(STATUS " Enable callout fork in pcre2grep .. : ${PCRE2GREP_SUPPORT_CALLOUT_FORK}")
message(STATUS " Buffer size for pcre2grep ......... : ${PCRE2GREP_BUFSIZE}")
message(STATUS " Initial buffer size for pcre2grep . : ${PCRE2GREP_BUFSIZE}")
message(STATUS " Maximum buffer size for pcre2grep . : ${PCRE2GREP_MAX_BUFSIZE}")
message(STATUS " Build tests (implies pcre2test .... : ${PCRE2_BUILD_TESTS}")
message(STATUS " and pcre2grep)")
if(ZLIB_FOUND)
Expand All @@ -1431,7 +1502,7 @@ if(PCRE2_SHOW_REPORT)
else()
message(STATUS " Link pcre2test with libreadline ... : Library not found")
endif()
message(STATUS " Support Valgrind .................. : ${PCRE2_SUPPORT_VALGRIND}")
message(STATUS " Enable Valgrind support ........... : ${PCRE2_SUPPORT_VALGRIND}")
if(PCRE2_DISABLE_PERCENT_ZT)
message(STATUS " Use %zu and %td ................... : OFF")
else()
Expand Down
13 changes: 12 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ EXTRA_DIST =
# These files contain additional m4 macros that are used by autoconf.

EXTRA_DIST += \
m4/ax_pthread.m4 m4/pcre2_visibility.m4
m4/ax_check_vscript.m4 \
m4/ax_pthread.m4 \
m4/pcre2_visibility.m4 \
m4/pcre2_zos.m4

# These files contain maintenance information

Expand Down Expand Up @@ -885,6 +888,13 @@ pkgconfig_DATA += libpcre2-32.pc
endif


# Symbol version files for use with GNU and Sun ld.

EXTRA_DIST += \
src/libpcre2-8.sym src/libpcre2-16.sym src/libpcre2-32.sym \
src/libpcre2-posix.sym


# gcov/lcov code coverage reporting
#
# Coverage reporting targets:
Expand Down Expand Up @@ -992,6 +1002,7 @@ EXTRA_DIST += \
cmake/FindReadline.cmake \
cmake/pcre2-config-version.cmake.in \
cmake/pcre2-config.cmake.in \
cmake/PCRE2CheckLinkerFlag.cmake \
src/config-cmake.h.in \
CMakeLists.txt

Expand Down
8 changes: 8 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ library. They are also documented in the pcre2build man page.
versions of all the relevant libraries are available for linking. See also
"Shared libraries" below.

Shared libraries are compiled with symbol versioning enabled on platforms that
support this, but this can be disabled by adding --disable-symvers.

. By default, only the 8-bit library is built. If you add --enable-pcre2-16 to
the "configure" command, the 16-bit library is also built. If you add
--enable-pcre2-32 to the "configure" command, the 32-bit library is also
Expand Down Expand Up @@ -956,6 +959,10 @@ The distribution should contain the files listed below.
testdata/testoutput* expected test results
testdata/grep* input and output for pcre2grep tests
testdata/* other supporting test files
src/libpcre2-8.sym )
src/libpcre2-16.sym ) symbol version scripts for the GNU and Sun linkers
src/libpcre2-32.sym )
src/libpcre2-posix.sym )

(D) Auxiliary files for CMake support

Expand All @@ -964,6 +971,7 @@ The distribution should contain the files listed below.
cmake/FindReadline.cmake
cmake/pcre2-config-version.cmake.in
cmake/pcre2-config.cmake.in
cmake/PCRE2CheckLinkerFlag.cmake
src/config-cmake.h.in
CMakeLists.txt

Expand Down
25 changes: 25 additions & 0 deletions cmake/PCRE2CheckLinkerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include(CheckLinkerFlag OPTIONAL)

# This file can be removed once the minimum CMake version is increased to 3.18
# or higher. Calls to pcre2_check_linker_flag can be changed to the built in
# check_linker_flag.

if(COMMAND check_linker_flag)
macro(pcre2_check_linker_flag)
check_linker_flag(${ARGN})
endmacro()
else()
# Fallback for versions of CMake older than 3.18.

include(CheckCCompilerFlag)

function(pcre2_check_linker_flag lang flag out_var)
cmake_policy(PUSH)
cmake_policy(SET CMP0056 NEW)
set(_CMAKE_EXE_LINKER_FLAGS_SAVE ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
check_c_compiler_flag("" ${out_var})
set(CMAKE_EXE_LINKER_FLAGS ${_CMAKE_EXE_LINKER_FLAGS_SAVE})
cmake_policy(POP)
endfunction()
endif()
Loading