Commit Graph

49 Commits

Author SHA1 Message Date
Martin Hořeňovský
2a8a8a7210 Add configuration option to make assertions thread-safe
All the previous refactoring to make the assertion fast paths
smaller and faster also allows us to implement the fast paths
just with thread-local and atomic variables, without full mutexes.

However, the performance overhead of thread-safe assertions is
still significant for single threaded usage:

|  slowdown |  Debug  | Release |
|-----------|--------:|--------:|
| fast path |   1.04x |   1.43x |
| slow path |   1.16x |   1.22x |

Thus, we don't make the assertions thread-safe by default, and instead
provide a build-time configuration option that the users can set to get
thread-safe assertions.

This commit is functional, but it still needs some follow-up work:
 * We do not need full seq_cst increments for the atomic counters,
   and using weaker ones can be faster.
 * We brute-force updating the reporter-friendly totals from internal
   atomic counters by doing it everywhere. We should properly trace
   where this is needed instead.
 * Message macros (`INFO`, `UNSCOPED_INFO`, `CAPTURE`, etc) are not
   made thread safe in this commit, but they can be made thread safe
   in the future, by building on top of this work.
 * Add more tests, including with thread-sanitizer, and compiled
   examples to the repository. Right now, these changes have been
   compiled with tsan manually, but these tests are not added to CI.

Closes #2948
2025-07-24 10:10:00 +02:00
Martin Hořeňovský
8c3ffe05e1 Skeleton for applying deprecation warnings 2025-07-21 21:50:43 +02:00
Martin Hořeňovský
3839e27f05 Generate pkg-config files at install time
This enables us to generate pkg-config with proper paths if the
installation prefix is decided at install time, e.g. with
```
cmake --install build-dir --prefix /path/to/somewhere
```

It also means that we can use CMake's generator expression to get
the _real_ final name of the libraries, e.g. including debug postfix.

Closes #2979
2025-07-10 16:39:46 +02:00
Chris Thrasher
8cfca70ae8 Fix formatting of CMake files
2 spaces seems to be the more common indentation level so that's what
I unified around.
2025-04-26 10:38:36 -06:00
Martin Hořeňovský
e260288807 Allow disabling use of __builtin_constant_p in internal macros
Turns out that even in GCC, the expression in `__builtin_cosntant_p`
can end up evaluated and side-effects executed. To allow users to
work around this bug, I added a configuration option to disable its
use in internal macros.

Related to #2925
2024-10-27 20:27:03 +01:00
Martin Hořeňovský
fa5a53df17 Explicitly silence Wnon-virtual-dtor in Decomposer and MatchExpr
Closes #2854
2024-04-30 23:51:36 +02:00
Martin Hořeňovský
6ebdd8fac2 Add Wsubobject-linkage to warning flags 2024-01-14 21:22:09 +01:00
Chris Thrasher
a8cf3e6710 Mark CATCH_CONFIG_ options as advanced
These options are rather low-level and don't need to be seen in the
CMake cache unless you opt into seeing all other advanced options.

This removes a lot of cache entries from the screen when using a GUI
or TUI to view the cache thus making it easier for users to focus on
the cache variables they're more likely to change on a frequent
basis.
2023-10-31 17:27:46 -06:00
Martin Hořeňovský
79d39a1954 Fix tests for C++23's multi-arg index operator
Closes #2744
2023-10-28 21:49:58 +02:00
Riom
4acc51828f Introduce CATCH_CONFIG_PREFIX_MESSAGES to only prefix a few logging related macros. (#2544)
* Add missing include for VxWorks build.

std::min is defined in algorithm provides std::min. It appears to be transitively included for most platforms. For VxWorks however this explicit include is required.

* Add option CATCH_CONFIG_PREFIX_MESSAGES to selectively prefix message macros only.

In contrast to CATCH_CONFIG_PREFIX_ALL, this will only prefix the following macros:
I.e. INFO, UNSCOPED_INFO, WARN and CATCH_CAPTURE

This is mainly useful for codebases that use INFO or WARN for their own logging macros.
2023-07-19 17:04:43 +02:00
Martin Hořeňovský
dba9197ec7 Add new config option: STATIC_ANALYSIS_SUPPORT 2023-05-29 00:55:20 +02:00
Yaroslav
5a40b2275c Update CatchConfigOptions.cmake
Fix CMake warning

CMake Warning (dev) at catch2-src/CMake/CatchConfigOptions.cmake:71 (set):
  uninitialized variable 'BUILD_SHARED_LIBS'
2023-05-12 13:52:45 +02:00
Martin Hořeňovský
598895d048 Fix Wredundant-decls
Closes #2682
2023-05-12 09:51:13 +02:00
Holger Kaelberer
897fe2a01b cmake: Improve unreachable-code warnings
Enable CI to report -Wunreachable-code-aggressive warnings in clang
builds which covers all,  -Wunreachable-code, -code-break,
-code-return.
2023-04-20 14:53:03 +02:00
Masashi Fujita
b7f4a2efb8 Add support for PlayStation platforms (#2562)
* Add new `CATCH_CONFIG` option for using `std::getenv`, because PS does not support env vars
* Add PS to platforms that have disabled posix signals.
* Small workaround for PS toolchain bug that prevents it from compiling `std::set` with lambda based comparator.
2022-11-09 14:47:55 +01:00
Lars Toenning
f1084fb309 Fix references to license file
The license file was renamed with 6a502cc2f5
2022-10-28 11:30:15 +02:00
autoantwort
8ce92d2c72 CatchMiscFunctions.cmake: Use PRIVATE for target_compile_options (#2553)
With the changes to how `-ffile-prefix-map` is detected, Catch2 started propagating the flag to its dependents, which isn't the desired behaviour, the normalization should only apply to Catch2's impl.
2022-10-24 18:26:40 +02:00
Tim Blechmann
728de353be improve -ffile-prefix-map detection (#2517)
the current implementation has two problems:
  * `clang-cl` does not know `-ffile-prefix-map`, but in CMake it is
    reported as "Clang", so the compiler will warn about an unknown
    compiler option.
  * XCode's clang in CMake is reported as "AppleClang", so it is not picked
    up as "Clang", so it is not passed `-ffile-prefix-map`, even though
    it supports it.

Also changed the map so that the normalized `__FILE__` paths are the same
as what the approval tests normalize paths into.

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2022-10-04 15:55:50 +02:00
Dimitrij Mijoski
c0e582e659 Fix building as shared library with MSVC. 2022-09-24 15:15:50 +02:00
Martin Hořeňovský
fc3d11b1d1 Add Wfloat-equal to default-enabled warnings
This is kinda messy, because there is no good way to signal to
the compiler that some code uses direct comparison of floating
point numbers intentionally, so instead we have to use diagnostic
pragmas.

We also have to over-suppress the test files, because Clang (and
possibly GCC) still issue warnings from template instantiation
even if the instantion site is under warning suppression, so the
template definition has to be under warning suppression as well.

Closes #2406
2022-05-14 15:47:20 +02:00
Martin Hořeňovský
91ea25e51a Fix use of u8-literal that would break in C++20 2022-05-03 13:54:07 +02:00
Martin Hořeňovský
e2d07d35f4 Add -Wmissing-prototypes to common warnings 2022-05-03 13:54:05 +02:00
Martin Hořeňovský
d2cb934d28 Add -Wmissing-variable-declarations to common warnings 2022-05-03 13:54:03 +02:00
Martin Hořeňovský
7752229105 Add -Wsuggest-destructor-override to enabled warnings 2022-05-03 13:54:02 +02:00
Martin Hořeňovský
722c197855 Enable a bunch of extra warnings 2022-05-03 13:54:00 +02:00
Martin Hořeňovský
c410e2596c Add some extra warnings 2022-04-28 14:56:31 +02:00
Martin Hořeňovský
4c1cf4aa67 Sorted and removed duplicates from the compiler warning list
The duplicates were '-Wreturn-std-move' and '-Wunreachable-code'.
2022-04-28 11:06:53 +02:00
Lukasz Okraszewski
cb551b4f6d Add default reporter for Bazel integration (#2399)
When the added Bazel configuration flag is enabled,
a default JUnit reporter will be added if the XML
envrioment variable is defined.
Fix include paths for generated config header.
Enable Bazel config by default when building with
Bazel.


Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2022-04-08 18:01:59 +02:00
Martin Hořeňovský
1a8a793178 Refactor colour handling to prepare for per-reporter colour modes
This includes always compiling the ANSI and None colour
implementations, as they don't need to touch any platform
specific APIs, and removing their respective compile-time
configuration options.

Because the Win32 colour implementation requires Win32-specific
APIs, it is still hidden behind a compile-time toggle,
`CATCH_CONFIG_COLOUR_WIN32` (renamed from `..._COLOUR_WINDOWS`).

The commandline options for colours were also changed. The
option now uses different name, and allows to select between
different implementations, rather than changing whether
the compiled-in colour implementation is used through
"yes/no/default" options.
2022-03-28 13:10:13 +02:00
Joel Uckelman
2ebc041903 Fix name of with-main library. 2022-03-04 00:40:55 +01:00
Martin Hořeňovský
33ffc3b6fc Allow passing compile-time configuration options through CMake 2022-02-18 11:15:08 +01:00
Martin Hořeňovský
a9ed2c235d Rename MiscFunctions.cmake -> CatchMiscFunctions.cmake 2022-02-07 00:05:11 +01:00
Martin Hořeňovský
a1e5934aa9 Add licence header to MiscFunctions.cmake 2022-02-06 23:59:15 +01:00
Biswapriyo Nath
efd8cc8777 pkgconfig: Add missing entries
This adds prefix and exec_prefix fields
2021-09-11 19:02:21 +02:00
Martin Hořeňovský
432d03d1aa Use -Wextra-semi instead of -Wextra-semi-stmt for stricter warnings 2021-09-02 11:04:55 +02:00
Martin Hořeňovský
d4a3cd9992 Make the static library build reproducible with supported compilers
This is based on bed285af07 from
`v2.x` branch, but done properly for the build in v3 branch,
effectively porting #2141 to devel.
2021-05-09 18:05:34 +02:00
Roman Proskuryakov
0acb371b92 Fix Wold-style-cast error (#2125)
* Add Wold-style-cast to cmake flags
* Fix old style cast in catch_stats.hpp
* Fix old style cast in catch_stats.cpp
2020-12-28 14:00:19 +01:00
Martin Hořeňovský
cc18bd719d Sweep out Wshadow
Most of the changes are completely pointless renaming of constructor
arguments so that they do not use the same name as the type members,
but 🤷

Closes #2015
2020-09-06 13:11:42 +02:00
Martin Hořeňovský
29d4b3768c Add Wsuggest-override to warning flags 2020-05-13 16:09:34 +02:00
Martin Hořeňovský
ae0ba81423 Use more warnings for develoment builds 2020-05-12 23:56:51 +02:00
Martin Hořeňovský
e78b4f6be7 Remove file list checking from CMake
I do not think we need a safeguard against not including files in
CMake anymore, and as it is, it caused annoying false positive about
the default main implementation.
2020-05-06 21:23:13 +02:00
Martin Hořeňovský
19ecad6f68 Rename CMake/pkg-config target Catch2Main to Catch2WithMain
This describes the reality better, as it also links in the rest
of Catch2.

The on-disk name of the static library remains just `Catch2Main`,
as that is what it is -- single main function -- and on-disk artifacts
cannot describe link dependencies.
2020-05-03 18:54:38 +02:00
Martin Hořeňovský
121f04ffcf Update Catch2-provided pkg-config
Also fixes an installation issue, where some installation steps
would not properly pick up `CMAKE_INSTALL_PREFIX` when set.
2020-03-18 10:51:35 +01:00
Martin Hořeňovský
6e270958a2 Add development build option to CMake and enable it on CI
Development build enables warnings and and `Werror` or equivalent.
2020-02-26 16:07:26 +01:00
Ryan Pavlik
edde6f4736 Fix typos identified by codespell.
Self test baselines also modified accordingly, due to
one typo found in a string in test code.
2019-04-10 09:42:11 +02:00
Martin Hořeňovský
1af60ef5ab Separate Catch2Config from targets
This lets us add the installed helper scripts to the cmake module
path, letting CMake users just include them after requiring Catch2
package.
2018-06-24 12:32:22 +02:00
Martin Hořeňovský
6c1145d922 Improve pkg-config integration a bit 2018-06-24 12:32:22 +02:00
Martin Hořeňovský
44722f9ed3 Integrate CMake with <catch2/catch.hpp> include paths
This also goes for pkg-config installed by our CMake installation.

This includes

* Updating CMake version on Travis
* Adding a `Catch2` subfolder to the `single_include/` folder to
provide this include path both _inside_ the repository, and _outside_.
* Updated examples to build with the new paths
* Other general CMake cleanup
2018-06-24 12:32:22 +02:00
Martin Hořeňovský
e344984a1b Add codecov.io coverage tracking
* Every Linux build tracks coverage when running Debug mode
* OS X not supported yet (Future WIP)
* Our own unit tests, non-default reporters and Clara are ignored
2017-11-27 20:13:47 +01:00