Progmasoft Git

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

Port the last example

Commit
29b441949cc09f59a867972cbbac4b88f1a10843
Author
Martin Hořeňovský ·
Parents
70ef2f7f12c2

Files · Download .tar.gz

Changes

 CMakeLists.txt                     |  3 ++-
 examples/231-Cfg-OutputStreams.cpp |  6 ++++--
 examples/CMakeLists.txt            |  7 +++++--
 src/CMakeLists.txt                 | 17 +++++++++++++++++
 4 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c5d86c7f..4985beef 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,7 +34,8 @@ set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest)
 set(BENCHMARK_DIR ${CATCH_DIR}/tests/Benchmark)
 set(EXAMPLES_DIR ${CATCH_DIR}/examples)
 
-add_subdirectory(src)
+# We need to bring-in the variables defined there to this scope
+include(src/CMakeLists.txt)
 
 # Build tests only if requested
 if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
diff --git a/examples/231-Cfg-OutputStreams.cpp b/examples/231-Cfg-OutputStreams.cpp
index 2f42c297..8753fcf6 100644
--- a/examples/231-Cfg-OutputStreams.cpp
+++ b/examples/231-Cfg-OutputStreams.cpp
@@ -6,10 +6,12 @@
 // there is no important difference between having `std::cerr` buffered
 // or unbuffered.
 
-#define CATCH_CONFIG_NOSTDOUT
-#define CATCH_CONFIG_MAIN
+#include <catch2/catch_default_main.hpp>
+
 #include <catch2/catch.hpp>
 
+#include <sstream>
+#include <cstdio>
 
 class out_buff : public std::stringbuf {
     std::FILE* m_stream;
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 2fe5e688..b8612581 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -17,8 +17,11 @@ add_executable( 020-MultiFile
   020-TestCase-2.cpp
 )
 
-# TODO: How to handle differently configured libraries?
-#       Needed in 231-Cfg-OutputStreams
+add_executable(231-Cfg_OutputStreams
+    231-Cfg-OutputStreams.cpp
+)
+StampOutLibrary(231-Cfg_OutputStreams)
+target_compile_definitions(Catch2_231-Cfg_OutputStreams PUBLIC CATCH_CONFIG_NOSTDOUT)
 
 # These examples use the standard separate compilation
 set( SOURCES_IDIOMATIC_EXAMPLES
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3909d481..227943b7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -229,3 +229,20 @@ target_include_directories(Catch2
     $<BUILD_INTERFACE:${SOURCES_DIR}/..>
     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
 )
+
+function(StampOutLibrary target)
+    add_library(Catch2_${target} STATIC
+      ${REPORTER_FILES}
+      ${INTERNAL_FILES}
+      ${BENCHMARK_HEADERS}
+      ${BENCHMARK_SOURCES}
+    )
+
+    target_include_directories(Catch2_${target}
+      PUBLIC
+        $<BUILD_INTERFACE:${SOURCES_DIR}/..>
+        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+    )
+
+    target_link_libraries(${target} Catch2_${target})
+endfunction()