Skip to content

Commit b0f27ec

Browse files
authored
Add some CMake fixes for z/OS (not previously tested with CMake) (#795)
- Added CMake on z/OS to CI builds - Added CMake module to enable _ALL_SOURCE if required for getrlimit(). This was already being done by Autoconf. - Excluded pcre2_grep_test on EBCDIC platforms. This was already being done for Autoconf builds. - Suppressed compiler warnings for UINT16_MAX. On most platforms it's the integer constant `65535` (a signed constant), but on z/OS and possibly AIX it's defined to `65535u` (an unsigned constant), which causes warnings about unexpected signedness in comparisons and arithmetic.
1 parent 7525365 commit b0f27ec

File tree

9 files changed

+89
-8
lines changed

9 files changed

+89
-8
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,18 +439,34 @@ jobs:
439439
export _TAG_REDIR_ERR=txt;
440440
export _TAG_REDIR_IN=txt;
441441
export _TAG_REDIR_OUT=txt;
442+
export PATH="/data/zopen/usr/local/bin:/data/zopen/usr/bin:/data/zopen/bin:/data/zopen/boot:/bin:/usr/lpp/IBM/cnw/v2r1/openxl/bin";
442443
. /data/zopen/etc/zopen-config;
443444
set -e;
444445
set -x;
445446
cd /data;
447+
448+
echo "== Autoconf, XLC compiler ==";
446449
rm -rf pcre2-build;
447450
mkdir pcre2-build;
448451
gtar xzf pcre2-build.tar.gz -C pcre2-build;
449452
cd pcre2-build;
450453
chtag -R -tc ISO8859-1 .;
451454
MAKE=gmake CC=xlc ./configure --enable-ebcdic --disable-unicode;
452455
gmake;
453-
gmake check'
456+
gmake check;
457+
458+
echo "== CMake, IBM-Clang -m64 compiler ==";
459+
cd ..;
460+
rm -rf pcre2-build;
461+
mkdir pcre2-build;
462+
gtar xzf pcre2-build.tar.gz -C pcre2-build;
463+
cd pcre2-build;
464+
chtag -R -tc ISO8859-1 .;
465+
cmake $CMAKE_FLAGS -G Ninja -DPCRE2_EBCDIC=ON -DPCRE2_SUPPORT_UNICODE=OFF -DCMAKE_C_COMPILER=ibm-clang -DCMAKE_C_FLAGS="-m64 $CFLAGS_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
466+
cd build;
467+
ninja;
468+
ctest -j3 --output-on-failure;
469+
'
454470
455471
distcheck:
456472
name: Build & verify distribution

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ include(CheckTypeSize)
163163
include(CMakePackageConfigHelpers)
164164
include(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR
165165
include(PCRE2CheckLinkerFlag)
166+
include(PCRE2UseSystemExtensions)
166167

167168
check_include_file(assert.h HAVE_ASSERT_H)
168169
check_include_file(dirent.h HAVE_DIRENT_H)
@@ -273,6 +274,11 @@ if(INTEL_CET_ENABLED)
273274
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mshstk")
274275
endif()
275276

277+
# Check whether any system-wide extensions need to be enabled, in order for
278+
# OS functionality to be exposed.
279+
280+
pcre2_use_system_extensions()
281+
276282
# User-configurable options
277283
#
278284
# Note: CMakeSetup displays these in alphabetical order, regardless of
@@ -1311,6 +1317,14 @@ if test \"$?\" != \"0\"; then exit 1; fi
13111317

13121318
if(UNIX)
13131319
add_test(pcre2_grep_test sh ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh)
1320+
1321+
if(PCRE2_EBCDIC)
1322+
# The grep tests currently fail in EBCDIC mode because the test data
1323+
# files are in ASCII. This could be fixed properly, but for now, we
1324+
# have very few EBCDIC users and the pcre2grep utility is hardly even
1325+
# part of the official project artifacts.
1326+
set_property(TEST pcre2_grep_test PROPERTY WILL_FAIL TRUE)
1327+
endif()
13141328
endif()
13151329
endif()
13161330

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ EXTRA_DIST += \
10141014
cmake/FindReadline.cmake \
10151015
cmake/pcre2-config.cmake.in \
10161016
cmake/PCRE2CheckLinkerFlag.cmake \
1017+
cmake/PCRE2UseSystemExtensions.cmake \
10171018
src/config-cmake.h.in \
10181019
CMakeLists.txt
10191020

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ The distribution should contain the files listed below.
972972
cmake/FindReadline.cmake
973973
cmake/pcre2-config.cmake.in
974974
cmake/PCRE2CheckLinkerFlag.cmake
975+
cmake/PCRE2UseSystemExtensions.cmake
975976
src/config-cmake.h.in
976977
CMakeLists.txt
977978

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This CMake module is supposed to give similar results to the
2+
# AC_USE_SYSTEM_EXTENSIONS Autoconf macro, which turns on a load of
3+
# system feature-check macros, including _ALL_SOURCE, _GNU_SOURCE,
4+
# _NETBSD_SOURCE, and many more.
5+
#
6+
# Because PCRE2 uses so few OS features, we don't seem to actually need to
7+
# enable many of these. Modern platforms with CMake users generally enable
8+
# all the basic POSIX features by default.
9+
#
10+
# So far, we know that we require:
11+
# - _ALL_SOURCE on IBM systems (z/OS, probably AIX) in order to call
12+
# getrlimit() in pcre2test.
13+
#
14+
# Autoconf enables this unconditionally. However, our CMake script potentially
15+
# supports *more* platforms than Autoconf, so we use a feature check.
16+
17+
function(pcre2_use_system_extensions)
18+
if (WIN32)
19+
return()
20+
endif()
21+
22+
include(CheckCSourceCompiles)
23+
24+
set(_pcre2_test_src "
25+
#include <sys/time.h>
26+
#include <sys/resource.h>
27+
28+
int main(void) {
29+
struct rlimit rlim;
30+
getrlimit(RLIMIT_STACK, &rlim);
31+
return 0;
32+
}
33+
")
34+
35+
check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT)
36+
37+
if (NOT HAVE_GETRLIMIT)
38+
# Try again with _ALL_SOURCE
39+
set(CMAKE_REQUIRED_DEFINITIONS "-D_ALL_SOURCE")
40+
check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT_ALLSOURCE)
41+
unset(CMAKE_REQUIRED_DEFINITIONS)
42+
43+
if (HAVE_GETRLIMIT_ALLSOURCE)
44+
add_compile_definitions(_ALL_SOURCE)
45+
endif()
46+
endif()
47+
endfunction()

doc/html/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ The distribution should contain the files listed below.
972972
cmake/FindReadline.cmake
973973
cmake/pcre2-config.cmake.in
974974
cmake/PCRE2CheckLinkerFlag.cmake
975+
cmake/PCRE2UseSystemExtensions.cmake
975976
src/config-cmake.h.in
976977
CMakeLists.txt
977978

maint/manifest-tarball

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ drwxr-xr-x tarball-dir/pcre2-SNAPSHOT/cmake
2727
-rw-r--r-- tarball-dir/pcre2-SNAPSHOT/cmake/FindEditline.cmake
2828
-rw-r--r-- tarball-dir/pcre2-SNAPSHOT/cmake/FindReadline.cmake
2929
-rw-r--r-- tarball-dir/pcre2-SNAPSHOT/cmake/PCRE2CheckLinkerFlag.cmake
30+
-rw-r--r-- tarball-dir/pcre2-SNAPSHOT/cmake/PCRE2UseSystemExtensions.cmake
3031
-rw-r--r-- tarball-dir/pcre2-SNAPSHOT/cmake/pcre2-config.cmake.in
3132
-rwxr-xr-x tarball-dir/pcre2-SNAPSHOT/compile
3233
-rwxr-xr-x tarball-dir/pcre2-SNAPSHOT/config.guess

src/pcre2_intmodedep.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ have 16-bit arguments in 8-bit and 16-bit modes, so we need no more than a
632632
#define CODE_BLOCKSIZE_TYPE PCRE2_SIZE
633633

634634
#undef LOOKBEHIND_MAX
635-
#define LOOKBEHIND_MAX UINT16_MAX
635+
#define LOOKBEHIND_MAX ((int)UINT16_MAX)
636636

637637
typedef struct pcre2_real_code {
638638
pcre2_memctl memctl; /* Memory control fields */

src/pcre2_study.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ for (;;)
138138
PCRE2_UCHAR op;
139139
PCRE2_SPTR cs, ce;
140140

141-
if (branchlength >= UINT16_MAX)
141+
if (branchlength >= (int)UINT16_MAX)
142142
{
143143
branchlength = UINT16_MAX;
144144
cc = nextbranch;
@@ -627,11 +627,11 @@ for (;;)
627627
break;
628628
}
629629

630-
/* Take care not to overflow: (1) min and d are ints, so check that their
631-
product is not greater than INT_MAX. (2) branchlength is limited to
632-
UINT16_MAX (checked at the top of the loop). */
630+
/* Take care not to overflow: (1) min and d are ints, so check that their
631+
product is not greater than INT_MAX. (2) branchlength is limited to
632+
UINT16_MAX (checked at the top of the loop). */
633633

634-
if ((d > 0 && (INT_MAX/d) < min) || UINT16_MAX - branchlength < min*d)
634+
if ((d > 0 && (INT_MAX/d) < min) || (int)UINT16_MAX - branchlength < min*d)
635635
branchlength = UINT16_MAX;
636636
else branchlength += min * d;
637637
break;
@@ -2063,7 +2063,7 @@ if ((re->flags & (PCRE2_MATCH_EMPTY|PCRE2_HASACCEPT)) == 0 &&
20632063
return 3; /* unrecognized opcode */
20642064

20652065
default:
2066-
re->minlength = (min > UINT16_MAX)? UINT16_MAX : min;
2066+
re->minlength = (min > (int)UINT16_MAX)? (int)UINT16_MAX : min;
20672067
break;
20682068
}
20692069
}

0 commit comments

Comments
 (0)