Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLeitwolf2026-11-18 03:25:17 +0300
committerGitHub2026-11-18 03:25:17 +0300
commite69ece56074c7a1a96d8db3b6b5a76ac2d872adc (patch)
treecc8794e66f77845d52b63584ad03baf2f4cab038
parentd06447420eca086cc8838f1bf5a5c5479226b252 (diff)
parentde44c381e2577155617053077c01e47e1148f785 (diff)
downloadcatch3-e69ece56074c7a1a96d8db3b6b5a76ac2d872adc.tar.gz
Merge pull request #58 from Progmasoft/build/catch3-link-names
Let an installed Catch3 link with -lCatch3 and -lCatch3Main
-rw-r--r--.github/workflows/linux-builds.yml21
-rw-r--r--docs/progmasoft-catch3.md21
-rw-r--r--premake5.lua2
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--xmake.lua4
5 files changed, 52 insertions, 0 deletions
diff --git a/.github/workflows/linux-builds.yml b/.github/workflows/linux-builds.yml
index dd36df79..16be72a1 100644
--- a/.github/workflows/linux-builds.yml
+++ b/.github/workflows/linux-builds.yml
@@ -67,6 +67,27 @@ jobs:
-GNinja -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_PREFIX_PATH="$RUNNER_TEMP/catch3"
+ - name: Link the installed library with -lCatch3, and through pkg-config
+ run: |
+ prefix="$RUNNER_TEMP/catch3"
+ cat > "$RUNNER_TEMP/consumer/test.cpp" <<'EOF'
+ #include <Progmasoft/Catch3.hpp>
+ TEST_CASE("an installed Catch3 links by its name") { REQUIRE(1 + 1 == 2); }
+ EOF
+ # A debug build is named apart with a "d".
+ d=""
+ if [ "$BUILD_TYPE" = Debug ]; then d=d; fi
+ clang++ -std=c++${{matrix.std}} -I"$prefix/include" "$RUNNER_TEMP/consumer/test.cpp" \
+ -L"$prefix/lib" "-lCatch3Main$d" "-lCatch3$d" -o "$RUNNER_TEMP/consumer/by-name"
+ "$RUNNER_TEMP/consumer/by-name"
+ export PKG_CONFIG_PATH="$prefix/share/pkgconfig"
+ # shellcheck disable=SC2046 # pkg-config prints several flags.
+ clang++ -std=c++${{matrix.std}} "$RUNNER_TEMP/consumer/test.cpp" \
+ $(pkg-config --cflags --libs catch3-with-main) -o "$RUNNER_TEMP/consumer/by-pkg-config"
+ "$RUNNER_TEMP/consumer/by-pkg-config"
+ env:
+ BUILD_TYPE: ${{matrix.build_type}}
+
thread-sanitizer:
name: Ubuntu 26.04, C++17, ThreadSanitizer and UBSan
runs-on: ubuntu-26.04
diff --git a/docs/progmasoft-catch3.md b/docs/progmasoft-catch3.md
index 05948fd4..fadff6aa 100644
--- a/docs/progmasoft-catch3.md
+++ b/docs/progmasoft-catch3.md
@@ -179,6 +179,27 @@ find_package(Catch3 0.3 CONFIG REQUIRED)
target_link_libraries(MyTests PRIVATE Catch3::Catch3WithMain)
```
+Without a build system, an installed Catch3 links by its name: the library is
+`Catch3` and the one that brings `main` is `Catch3Main`, as `libCatch3.a` and
+`libCatch3Main.a` (`Catch3.lib` and `Catch3Main.lib` on Windows). The released
+archives and packages hold these release builds; a debug build made with
+CMake is named apart, `Catch3d` and `Catch3Maind`. `Catch3Main` comes first,
+since it uses `Catch3`:
+
+```sh
+c++ -std=c++17 tests.cpp -lCatch3Main -lCatch3
+```
+
+When Catch3 is installed outside the compiler's search paths, pkg-config
+gives the same flags with the include and library directories:
+
+```sh
+c++ -std=c++17 tests.cpp $(pkg-config --cflags --libs catch3-with-main)
+```
+
+The pkg-config modules are `catch3` and `catch3-with-main`. CMake, Meson,
+Xmake and Premake build the files under the same names.
+
In the Bazel Central Registry, from 0.5.0 on, the module is
`progmasoft_catch3`, for Bazel 8 and later:
diff --git a/premake5.lua b/premake5.lua
index 8903ac8d..9404eba8 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -63,6 +63,8 @@ project "Catch3"
project "Catch3WithMain"
kind "StaticLib"
+ -- The file is Catch3Main, as in CMake and Meson, for -lCatch3Main.
+ targetname "Catch3Main"
language "C++"
cppdialect "C++17"
-- Visual Studio injects UNICODE for Windows projects, which would select
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fac2fb62..f0de95b4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -398,6 +398,10 @@ target_link_libraries(Catch3
$<BUILD_INTERFACE:Catch3Pugixml>
)
+# The files are libCatch3 and libCatch3Main (Catch3.lib and Catch3Main.lib on
+# Windows), so that an installed Catch3 links with -lCatch3 and -lCatch3Main.
+# A debug build is not the same library and is named apart with a "d"; the
+# released archives and packages hold release builds.
set_target_properties(Catch3 PROPERTIES
DEBUG_POSTFIX "d"
VERSION ${PROJECT_VERSION}
diff --git a/xmake.lua b/xmake.lua
index 5a95e50f..7e7fdaa4 100644
--- a/xmake.lua
+++ b/xmake.lua
@@ -18,6 +18,9 @@ includes("third_party/yyjson", "third_party/pugixml")
-- library and the code that includes it need C++17.
target("catch3")
set_kind("static")
+ -- The files are Catch3 and Catch3Main, as in CMake and Meson, so that an
+ -- installed Catch3 links with -lCatch3 and -lCatch3Main.
+ set_basename("Catch3")
on_load(function(target)
-- File I/O is restricted to Xmake's script domain, so generate here
-- rather than while the declarative project file is being evaluated.
@@ -45,6 +48,7 @@ target("catch3")
target("catch3_main")
set_kind("static")
+ set_basename("Catch3Main")
add_files("src/Progmasoft/Catch3/Internal/Main.cpp")
add_deps("catch3")
add_includedirs("src", generated_include, {public = true})