Port the last example

This commit is contained in:
Martin Hořeňovský 2019-12-08 20:57:55 +01:00
parent 70ef2f7f12
commit 29b441949c
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
4 changed files with 28 additions and 5 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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

View File

@ -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()