diff --git a/CMake/CatchConfigOptions.cmake b/CMake/CatchConfigOptions.cmake new file mode 100644 index 00000000..54cf0ab9 --- /dev/null +++ b/CMake/CatchConfigOptions.cmake @@ -0,0 +1,78 @@ + +# Copyright Catch2 Authors +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# SPDX-License-Identifier: BSL-1.0 + +## +# This file contains options that are materialized into the Catch2 +# compiled library. All of them default to OFF, as even the positive +# forms correspond to the user _forcing_ them to ON, while being OFF +# means that Catch2 can use its own autodetection. +# +# For detailed docs look into docs/configuration.md + + +macro(AddOverridableConfigOption OptionBaseName) + option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF) + option(CATCH_CONFIG_NO_${OptionBaseName} "Read docs/configuration.md for details" OFF) +endmacro() + +macro(AddConfigOption OptionBaseName) + option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF) +endmacro() + +set(_OverridableOptions + "ANDROID_LOGWRITE" + "COUNTER" + "CPP11_TO_STRING" + "CPP17_BYTE" + "CPP17_OPTIONAL" + "CPP17_STRING_VIEW" + "CPP17_UNCAUGHT_EXCEPTIONS" + "CPP17_VARIANT" + "GLOBAL_NEXTAFTER" + "POSIX_SIGNALS" + "USE_ASYNC" + "WCHAR" + "WINDOWS_SEH" +) + +foreach(OptionName ${_OverridableOptions}) + AddOverridableConfigOption(${OptionName}) +endforeach() + +set(_OtherConfigOptions + "COLOUR_ANSI" + "COLOUR_NONE" + "COLOUR_WINDOWS" + "DISABLE_EXCEPTIONS" + "DISABLE_EXCEPTIONS_CUSTOM_HANDLER" + "DISABLE" + "DISABLE_STRINGIFICATION" + "ENABLE_ALL_STRINGMAKERS" + "ENABLE_OPTIONAL_STRINGMAKER" + "ENABLE_PAIR_STRINGMAKER" + "ENABLE_TUPLE_STRINGMAKER" + "ENABLE_VARIANT_STRINGMAKER" + "EXPERIMENTAL_REDIRECT" + "FAST_COMPILE" + "NOSTDOUT" + "PREFIX_ALL" + "WINDOWS_CRTDBG" +) + + +foreach(OptionName ${_OtherConfigOptions}) + AddConfigOption(${OptionName}) +endforeach() + +set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.") +set(CATCH_CONFIG_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.") + +# There is no good way to both turn this into a CMake cache variable, +# and keep reasonable default semantics inside the project. Thus we do +# not define it and users have to provide it as an outside variable. +#set(CATCH_CONFIG_FALLBACK_STRINGIFIER "" CACHE STRING "Read docs/configuration.md for details.") diff --git a/CMakeLists.txt b/CMakeLists.txt index fa8e4519..296ede56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ project(Catch2 LANGUAGES CXX VERSION 3.0.0) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") include(GNUInstallDirs) include(CMakePackageConfigHelpers) +include(CatchConfigOptions) if(CATCH_DEVELOPMENT_BUILD) include(CTest) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2e8ac73..4d0eb295 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,8 @@ set(BENCHMARK_SOURCES SOURCE_GROUP("benchmark" FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES}) set(INTERNAL_HEADERS + "${CMAKE_BINARY_DIR}/generated-includes/catch2/catch_user_config.hpp" + "${SOURCES_DIR}/catch_user_config.hpp.in" ${SOURCES_DIR}/catch_all.hpp ${SOURCES_DIR}/matchers/catch_matchers_all.hpp ${SOURCES_DIR}/generators/catch_generators_all.hpp @@ -282,9 +284,15 @@ target_compile_features(Catch2 cxx_variadic_macros ) +configure_file( + "${SOURCES_DIR}/catch_user_config.hpp.in" + "${CMAKE_BINARY_DIR}/generated-includes/catch2/catch_user_config.hpp" +) + target_include_directories(Catch2 PUBLIC $ + $ $ ) @@ -323,7 +331,15 @@ if (NOT_SUBPROJECT) ${CATCH_CMAKE_CONFIG_DESTINATION} ) # Install the headers - install(DIRECTORY ${SOURCES_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h*") + install( + DIRECTORY + "${SOURCES_DIR}" + "${CMAKE_BINARY_DIR}/generated-includes/catch2" # Also install the generated header + DESTINATION + "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING + PATTERN "*.hpp" + ) endif() # Some tests require a full recompilation of Catch2 lib with different @@ -342,6 +358,7 @@ if (CATCH_BUILD_EXAMPLES OR CATCH_BUILD_EXTRA_TESTS) target_include_directories(Catch2_buildall_interface INTERFACE $ + $ $ ) target_compile_features(Catch2_buildall_interface diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp index a8cdc48a..2795d42e 100644 --- a/src/catch2/catch_config.hpp +++ b/src/catch2/catch_config.hpp @@ -9,6 +9,7 @@ #define CATCH_CONFIG_HPP_INCLUDED #include +#include #include #include #include diff --git a/src/catch2/catch_user_config.hpp.in b/src/catch2/catch_user_config.hpp.in new file mode 100644 index 00000000..3cfbed4a --- /dev/null +++ b/src/catch2/catch_user_config.hpp.in @@ -0,0 +1,201 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * **AUTOGENERATED FROM CMAKE CONFIGURATION** + * + * Contains materialized compile-time configuration provided to Catch2's + * CMake configuration. All compile-time configuration options need to + * be here, and also documented in `docs/configuration.md`. + */ + +#ifndef CATCH_USER_CONFIG_HPP_INCLUDED +#define CATCH_USER_CONFIG_HPP_INCLUDED + + +// ------ +// Overridable compilation flags, +// these can have 3 "states": Force Yes, Force No, Use Default. +// Setting both Force Yes and Force No is an error +// ------ + +#cmakedefine CATCH_CONFIG_ANDROID_LOGWRITE +#cmakedefine CATCH_CONFIG_NO_ANDROID_LOGWRITE + +#if defined( CATCH_CONFIG_ANDROID_LOGWRITE ) && \ + defined( CATCH_CONFIG_NO_ANDROID_LOGWRITE ) +# error Cannot force ANDROID_LOGWRITE to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_COUNTER +#cmakedefine CATCH_CONFIG_NO_COUNTER + +#if defined( CATCH_CONFIG_COUNTER ) && \ + defined( CATCH_CONFIG_NO_COUNTER ) +# error Cannot force COUNTER to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_CPP11_TO_STRING +#cmakedefine CATCH_CONFIG_NO_CPP11_TO_STRING + +#if defined( CATCH_CONFIG_CPP11_TO_STRING ) && \ + defined( CATCH_CONFIG_NO_CPP11_TO_STRING ) +# error Cannot force CPP11_TO_STRING to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_CPP17_BYTE +#cmakedefine CATCH_CONFIG_NO_CPP17_BYTE + +#if defined( CATCH_CONFIG_CPP17_BYTE ) && \ + defined( CATCH_CONFIG_NO_CPP17_BYTE ) +# error Cannot force CPP17_BYTE to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_CPP17_OPTIONAL +#cmakedefine CATCH_CONFIG_NO_CPP17_OPTIONAL + +#if defined( CATCH_CONFIG_CPP17_OPTIONAL ) && \ + defined( CATCH_CONFIG_NO_CPP17_OPTIONAL ) +# error Cannot force CPP17_OPTIONAL to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_CPP17_STRING_VIEW +#cmakedefine CATCH_CONFIG_NO_CPP17_STRING_VIEW + +#if defined( CATCH_CONFIG_CPP17_STRING_VIEW ) && \ + defined( CATCH_CONFIG_NO_CPP17_STRING_VIEW ) +# error Cannot force CPP17_STRING_VIEW to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#cmakedefine CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS + +#if defined( CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS ) && \ + defined( CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS ) +# error Cannot force CPP17_UNCAUGHT_EXCEPTIONS to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_CPP17_VARIANT +#cmakedefine CATCH_CONFIG_NO_CPP17_VARIANT + +#if defined( CATCH_CONFIG_CPP17_VARIANT ) && \ + defined( CATCH_CONFIG_NO_CPP17_VARIANT ) +# error Cannot force CPP17_VARIANT to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_GLOBAL_NEXTAFTER +#cmakedefine CATCH_CONFIG_NO_GLOBAL_NEXTAFTER + +#if defined( CATCH_CONFIG_GLOBAL_NEXTAFTER ) && \ + defined( CATCH_CONFIG_NO_GLOBAL_NEXTAFTER ) +# error Cannot force GLOBAL_NEXTAFTER to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_POSIX_SIGNALS +#cmakedefine CATCH_CONFIG_NO_POSIX_SIGNALS + +#if defined( CATCH_CONFIG_POSIX_SIGNALS ) && \ + defined( CATCH_CONFIG_NO_POSIX_SIGNALS ) +# error Cannot force POSIX_SIGNALS to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_USE_ASYNC +#cmakedefine CATCH_CONFIG_NO_USE_ASYNC + +#if defined( CATCH_CONFIG_USE_ASYNC ) && \ + defined( CATCH_CONFIG_NO_USE_ASYNC ) +# error Cannot force USE_ASYNC to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_WCHAR +#cmakedefine CATCH_CONFIG_NO_WCHAR + +#if defined( CATCH_CONFIG_WCHAR ) && \ + defined( CATCH_CONFIG_NO_WCHAR ) +# error Cannot force WCHAR to both ON and OFF +#endif + + + +#cmakedefine CATCH_CONFIG_WINDOWS_SEH +#cmakedefine CATCH_CONFIG_NO_WINDOWS_SEH + +#if defined( CATCH_CONFIG_WINDOWS_SEH ) && \ + defined( CATCH_CONFIG_NO_WINDOWS_SEH ) +# error Cannot force WINDOWS_SEH to both ON and OFF +#endif + + +// ------ +// Simple toggle defines +// their value is never used and they cannot be overriden +// ------ + + +#cmakedefine CATCH_CONFIG_COLOUR_ANSI +#cmakedefine CATCH_CONFIG_COLOUR_NONE +#cmakedefine CATCH_CONFIG_COLOUR_WINDOWS +#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS +#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER +#cmakedefine CATCH_CONFIG_DISABLE +#cmakedefine CATCH_CONFIG_DISABLE_STRINGIFICATION +#cmakedefine CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS +#cmakedefine CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER +#cmakedefine CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER +#cmakedefine CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +#cmakedefine CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER +#cmakedefine CATCH_CONFIG_EXPERIMENTAL_REDIRECT +#cmakedefine CATCH_CONFIG_FAST_COMPILE +#cmakedefine CATCH_CONFIG_NOSTDOUT +#cmakedefine CATCH_CONFIG_PREFIX_ALL +#cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG + +// ------ +// "Variable" defines, these have actual values +// ------ + +#define CATCH_CONFIG_DEFAULT_REPORTER "@CATCH_CONFIG_DEFAULT_REPORTER@" +#define CATCH_CONFIG_CONSOLE_WIDTH @CATCH_CONFIG_CONSOLE_WIDTH@ + +// The logic here depends on CMake preprocessing of the file significantly. +// If CMake has CATCH_CONFIG_FALLBACK_STRINGIFIER it will be define below, +// and its value is written into the if. Thus, we undef the old placeholder +// and then define the macro to the actual CMake-provided value. +// +// We can't do it without this indirection, because it is a string-variable +// macro, so we need it's value, and there is no usable default value that +// would let us have it always defined the way the other two are. +#cmakedefine CATCH_CONFIG_FALLBACK_STRINGIFIER +#if defined( CATCH_CONFIG_FALLBACK_STRINGIFIER ) +# undef CATCH_CONFIG_FALLBACK_STRINGIFIER +# define CATCH_CONFIG_FALLBACK_STRINGIFIER @CATCH_CONFIG_FALLBACK_STRINGIFIER@ +#endif + +#endif // CATCH_USER_CONFIG_HPP_INCLUDED diff --git a/src/catch2/internal/catch_compiler_capabilities.hpp b/src/catch2/internal/catch_compiler_capabilities.hpp index 0684050b..a999ebbd 100644 --- a/src/catch2/internal/catch_compiler_capabilities.hpp +++ b/src/catch2/internal/catch_compiler_capabilities.hpp @@ -287,7 +287,9 @@ # define CATCH_CONFIG_NEW_CAPTURE #endif -#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#if !defined( CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED ) && \ + !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) && \ + !defined( CATCH_CONFIG_NO_DISABLE_EXCEPTIONS ) # define CATCH_CONFIG_DISABLE_EXCEPTIONS #endif diff --git a/src/catch2/internal/catch_config_android_logwrite.hpp b/src/catch2/internal/catch_config_android_logwrite.hpp index 199c9375..670af2d5 100644 --- a/src/catch2/internal/catch_config_android_logwrite.hpp +++ b/src/catch2/internal/catch_config_android_logwrite.hpp @@ -17,6 +17,8 @@ #ifndef CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED #define CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED +#include + #if defined(__ANDROID__) # define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE #endif diff --git a/tools/scripts/generateAmalgamatedFiles.py b/tools/scripts/generateAmalgamatedFiles.py index 9fc63a8f..812712a3 100755 --- a/tools/scripts/generateAmalgamatedFiles.py +++ b/tools/scripts/generateAmalgamatedFiles.py @@ -79,6 +79,15 @@ def concatenate_file(out, filename: str, expand_headers: bool) -> int: # hundred thousands lines (~300k as of preview3 :-) ) if next_header in concatenated_headers: continue + + # Skip including the auto-generated user config file, + # because it has not been generated yet at this point. + # The code around it should be written so that just not including + # it is equivalent with all-default user configuration. + if next_header == 'catch2/catch_user_config.hpp': + concatenated_headers.add(next_header) + continue + concatenated_headers.add(next_header) concatenated += concatenate_file(out, os.path.join(root_path, next_header), expand_headers)