catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Let an installed Catch3 link with -lCatch3 and -lCatch3Main in every build
- Commit
5da6bc7b6ab2f857d7be70d5ad966636b33d8164- Author
- Leitwolf11 ·
- Parents
2de8e46a15b2
Changes
.github/workflows/linux-builds.yml | 16 ++++++++++++++++ docs/progmasoft-catch3.md | 19 +++++++++++++++++++ premake5.lua | 2 ++ src/CMakeLists.txt | 10 ++++++++-- xmake.lua | 4 ++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux-builds.yml b/.github/workflows/linux-builds.yml index dd36df79..877b1501 100644 --- a/.github/workflows/linux-builds.yml +++ b/.github/workflows/linux-builds.yml @@ -67,6 +67,22 @@ 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 + clang++ -std=c++${{matrix.std}} -I"$prefix/include" "$RUNNER_TEMP/consumer/test.cpp" \ + -L"$prefix/lib" -lCatch3Main -lCatch3 -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" + 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..dbc1bded 100644 --- a/docs/progmasoft-catch3.md +++ b/docs/progmasoft-catch3.md @@ -179,6 +179,25 @@ 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, where a debug +build adds a `d`). `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..14cbce8f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -398,8 +398,9 @@ 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. set_target_properties(Catch3 PROPERTIES - DEBUG_POSTFIX "d" VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION} ) @@ -434,7 +435,12 @@ set_target_properties(Catch3WithMain VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION} ) -set_target_properties(Catch3WithMain PROPERTIES DEBUG_POSTFIX "d") +# A debug build of Windows links the debug C runtime, so its files carry a "d" +# and a debug and a release build can be installed side by side. Elsewhere +# the files have the same name in every configuration. +if(WIN32) + set_target_properties(Catch3 Catch3WithMain PROPERTIES DEBUG_POSTFIX "d") +endif() if(NOT_SUBPROJECT) # Create and install an export set for the targets as Catch3::Catch3 and 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})