Skip to content

Commit e62c0e0

Browse files
Re-apply "Use standard CMake constructs to export the targets. (#260)" (#739)
Additionally, I have attempted to clean up some CMake issues to make the package's build interface cleaner, in particular, avoiding polluting the parent directory's include path with our config.h file (if PCRE2 is being included as a subdirectory). This re-adds changes from Theodore's commit: def175f and partially reverts changes from Carlo's commit: 92d56a1 --------- Co-authored-by: Theodore Tsirpanis <[email protected]>
1 parent c98e5d5 commit e62c0e0

21 files changed

+366
-211
lines changed

.github/workflows/build.yml

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,50 @@ jobs:
121121
../maint/RunManifestTest install-dir ../maint/manifest-cmakeinstall-macos
122122
../maint/RunSymbolTest install-dir/lib/ ../maint/
123123
124+
- name: Test CMake install interface
125+
run: |
126+
INSTALL_PREFIX=`pwd`/build/install-dir
127+
cd maint/cmake-tests/install-interface
128+
129+
for useStaticLibs in ON OFF; do
130+
echo "== Testing CMake install interface with PCRE2_USE_STATIC_LIBS=$useStaticLibs =="
131+
rm -rf build
132+
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$INSTALL_PREFIX" -DPCRE2_USE_STATIC_LIBS=$useStaticLibs -B build
133+
(cd build; make)
134+
./build/test_executable
135+
otool -L ./build/test_executable
136+
if [ $useStaticLibs = ON ]; then
137+
(otool -L ./build/test_executable | grep -q "pcre2") && (echo "Error: PCRE2 found in otool output" && exit 1)
138+
else
139+
# Test that the shared library is actually linked in
140+
(otool -L ./build/test_executable | grep -q "@rpath/libpcre2-8.0.dylib") || (echo "Error: Shared library not linked in" && exit 1)
141+
fi
142+
done
143+
144+
- name: Test CMake build interface
145+
run: |
146+
BUILD_DIR=`pwd`
147+
cp -rp maint/cmake-tests/build-interface ../cmake-tests-build-interface
148+
cd ../cmake-tests-build-interface
149+
ln -s "$BUILD_DIR" pcre2
150+
151+
for buildLibs in "ON;OFF" "OFF;ON"; do
152+
static=`echo $buildLibs | cut -d';' -f1`
153+
shared=`echo $buildLibs | cut -d';' -f2`
154+
echo "== Testing CMake build interface with BUILD_STATIC_LIBS=$static and BUILD_SHARED_LIBS=$shared =="
155+
rm -rf build
156+
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_STATIC_LIBS=$static -DBUILD_SHARED_LIBS=$shared -B build
157+
(cd build; make)
158+
./build/test_executable
159+
otool -L ./build/test_executable
160+
if [ $static = ON ]; then
161+
(otool -L ./build/test_executable | grep -q "pcre2") && (echo "Error: PCRE2 found in ldd output" && exit 1)
162+
else
163+
# Test that the shared library is actually linked in
164+
(otool -L ./build/test_executable | grep -q "@rpath/libpcre2-8.0.dylib") || (echo "Error: Shared library not linked in" && exit 1)
165+
fi
166+
done
167+
124168
windows:
125169
name: Windows
126170
runs-on: windows-latest
@@ -165,6 +209,66 @@ jobs:
165209
../maint/RunManifestTest.ps1 install-dir ../maint/manifest-cmakeinstall-windows
166210
../maint/RunSymbolTest.ps1 install-dir/bin ../maint/
167211
212+
- name: Test CMake install interface
213+
run: |
214+
$INSTALL_PREFIX = (pwd).Path + "\build\install-dir"
215+
cd maint/cmake-tests/install-interface
216+
217+
$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
218+
$dumpbin = & $vswhere -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -find VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe | Select-Object -First 1
219+
220+
foreach ($useStaticLibs in @("ON", "OFF")) {
221+
echo "== Testing CMake install interface with PCRE2_USE_STATIC_LIBS=$useStaticLibs =="
222+
if (Test-Path build) { rm -Recurse -Force build }
223+
cmake "-DCMAKE_PREFIX_PATH=$INSTALL_PREFIX" "-DPCRE2_USE_STATIC_LIBS=$useStaticLibs" -B build -A ${{ matrix.arch }}
224+
cmake --build build --config Release
225+
./build/Release/test_executable.exe
226+
& $dumpbin /dependents ./build/Release/test_executable.exe
227+
if ($useStaticLibs -eq "ON") {
228+
if ((& $dumpbin /dependents ./build/Release/test_executable.exe | Out-String).Contains("pcre2")) {
229+
Write-Error "Error: PCRE2 found in dumpbin output"
230+
exit 1
231+
}
232+
} else {
233+
# Test that the shared library is actually linked in
234+
if (-not ((& $dumpbin /dependents ./build/Release/test_executable.exe | Out-String).Contains("pcre2-8.dll"))) {
235+
Write-Error "Error: Shared library not linked in"
236+
exit 1
237+
}
238+
}
239+
}
240+
241+
- name: Test CMake build interface
242+
run: |
243+
$BUILD_DIR = (pwd).Path
244+
cp -Recurse -Path maint/cmake-tests/build-interface ../cmake-tests-build-interface
245+
cd ../cmake-tests-build-interface
246+
New-Item -ItemType SymbolicLink -Path "pcre2" -Target "$BUILD_DIR"
247+
248+
$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
249+
$dumpbin = & $vswhere -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -find VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe | Select-Object -First 1
250+
251+
foreach ($buildLibs in @(@{static="ON"; shared="OFF"}, @{static="OFF"; shared="ON"})) {
252+
echo "== Testing CMake build interface with BUILD_STATIC_LIBS=$($buildLibs.static) =="
253+
if (Test-Path build) { rm -Recurse -Force build }
254+
cmake "-DBUILD_STATIC_LIBS=$($buildLibs.static)" "-DBUILD_SHARED_LIBS=$($buildLibs.shared)" -B build -A ${{ matrix.arch }}
255+
cmake --build build --config Debug
256+
./build/Debug/test_executable.exe
257+
& $dumpbin /dependents ./build/Debug/test_executable.exe
258+
if ($buildLibs.static -eq "ON") {
259+
if ((& $dumpbin /dependents ./build/Debug/test_executable.exe | Out-String).Contains("pcre2")) {
260+
Write-Error "Error: PCRE2 found in dumpbin output"
261+
exit 1
262+
}
263+
} else {
264+
# Test that the shared library is actually linked in
265+
if (-not ((& $dumpbin /dependents ./build/Debug/test_executable.exe | Out-String).Contains("pcre2-8d.dll"))) {
266+
Write-Error "Error: Shared library not linked in"
267+
exit 1
268+
}
269+
}
270+
}
271+
168272
freebsd:
169273
name: FreeBSD
170274
runs-on: ubuntu-latest
@@ -206,7 +310,7 @@ jobs:
206310
echo "== CMake =="
207311
cd ../build-cmake
208312
209-
cmake -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -B build
313+
cmake -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
210314
cd build
211315
make -j3
212316
ctest -j3 --output-on-failure
@@ -288,7 +392,7 @@ jobs:
288392
echo "== CMake, 64-bit =="
289393
cd ../build-cmake-64
290394
291-
CC="cc -m64" cmake -DNCURSES_LIBRARY=termcap -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_SOLARIS_CC" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -B build
395+
CC="cc -m64" cmake -DNCURSES_LIBRARY=termcap -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_SOLARIS_CC" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
292396
cd build
293397
make
294398
ctest -j3 --output-on-failure

.github/workflows/dev.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
# Tests with: GCC, -O3, oldest supported Ubuntu (in non-extended support)
9393
name: GCC -O3
9494
runs-on: ubuntu-latest
95-
container: ubuntu:20.04
95+
container: ubuntu:22.04
9696
steps:
9797
- name: Setup
9898
run: |
@@ -121,11 +121,55 @@ jobs:
121121
../maint/RunManifestTest install-dir ../maint/manifest-cmakeinstall-linux
122122
../maint/RunSymbolTest install-dir/lib/ ../maint/
123123
124+
- name: Test CMake install interface
125+
run: |
126+
INSTALL_PREFIX=`pwd`/build/install-dir
127+
cd maint/cmake-tests/install-interface
128+
129+
for useStaticLibs in ON OFF; do
130+
echo "== Testing CMake install interface with PCRE2_USE_STATIC_LIBS=$useStaticLibs =="
131+
rm -rf build
132+
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$INSTALL_PREFIX" -DPCRE2_USE_STATIC_LIBS=$useStaticLibs -B build
133+
(cd build; make)
134+
./build/test_executable
135+
ldd ./build/test_executable
136+
if [ $useStaticLibs = ON ]; then
137+
(ldd ./build/test_executable | grep -q "pcre2") && (echo "Error: PCRE2 found in ldd output" && exit 1)
138+
else
139+
# Test that the shared library is actually linked in
140+
(ldd ./build/test_executable | grep -q "$INSTALL_PREFIX/lib/libpcre2-8.so.0") || (echo "Error: Shared library not linked in" && exit 1)
141+
fi
142+
done
143+
144+
- name: Test CMake build interface
145+
run: |
146+
BUILD_DIR=`pwd`
147+
cp -rp maint/cmake-tests/build-interface ../cmake-tests-build-interface
148+
cd ../cmake-tests-build-interface
149+
ln -s "$BUILD_DIR" pcre2
150+
151+
for buildLibs in "ON;OFF" "OFF;ON"; do
152+
static=`echo $buildLibs | cut -d';' -f1`
153+
shared=`echo $buildLibs | cut -d';' -f2`
154+
echo "== Testing CMake build interface with BUILD_STATIC_LIBS=$static and BUILD_SHARED_LIBS=$shared =="
155+
rm -rf build
156+
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_STATIC_LIBS=$static -DBUILD_SHARED_LIBS=$shared -B build
157+
(cd build; make)
158+
./build/test_executable
159+
ldd ./build/test_executable
160+
if [ $static = ON ]; then
161+
(ldd ./build/test_executable | grep -q "pcre2") && (echo "Error: PCRE2 found in ldd output" && exit 1)
162+
else
163+
# Test that the shared library is actually linked in
164+
(ldd ./build/test_executable | grep -q "`pwd`/build/pcre2/libpcre2-8.so.0") || (echo "Error: Shared library not linked in" && exit 1)
165+
fi
166+
done
167+
124168
dodo:
125169
# Tests with: Autconf on oldest supported Ubuntu (in non-extended support)
126170
name: GCC -Os, old Autotools
127171
runs-on: ubuntu-latest
128-
container: ubuntu:20.04
172+
container: ubuntu:22.04
129173
steps:
130174
- name: Setup
131175
run: |
@@ -200,7 +244,7 @@ jobs:
200244
run: |
201245
cd build
202246
cmake --install . --prefix install-dir
203-
../maint/RunManifestTest install-dir ../maint/manifest-cmakeinstall-linux
247+
../maint/RunManifestTest install-dir ../maint/manifest-cmakeinstall-linux minsizerel
204248
../maint/RunSymbolTest install-dir/lib/ ../maint/
205249
206250
bat:
@@ -372,7 +416,7 @@ jobs:
372416
# Not used by anyone yet, really, but potentially the "next big thing".
373417
- arch: "riscv64"
374418
distro: "ubuntu_latest"
375-
runs-on: ubuntu-22.04
419+
runs-on: ubuntu-latest
376420
permissions:
377421
contents: read
378422
packages: write # Necessary for uraimo/run-on-arch-action to use GitHub's Docker repository as a cache

0 commit comments

Comments
 (0)