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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-12-08 20:57:55 +0100
committerMartin Hořeňovský2019-12-08 20:58:52 +0100
commit29b441949cc09f59a867972cbbac4b88f1a10843 (patch)
tree74c279661da73ae71338623f83b4d666faf390ed
parent70ef2f7f12c2c62714a2e926679172142ea150ff (diff)
downloadcatch3-29b441949cc09f59a867972cbbac4b88f1a10843.tar.gz
Port the last example
-rw-r--r--CMakeLists.txt3
-rw-r--r--examples/231-Cfg-OutputStreams.cpp6
-rw-r--r--examples/CMakeLists.txt7
-rw-r--r--src/CMakeLists.txt17
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()