Skip to content

cmake: Rework tests target for Coverage configuration and multi-config generators #1592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Aug 18, 2024

When using a multi-config generator, such as "Ninja Multi-Config", the build system still builds the tests binary for the "Coverage" configuration, which is meaningless:

$ cmake -B build -G "Ninja Multi-Config"
$ cmake --build build --config Coverage
[18/19] Building C object src/CMakeFiles/tests.dir/Coverage/tests.c.o
/home/hebasto/git/secp256k1/secp256k1/src/tests.c:18:13: note: ‘#pragma message: Defining VERIFY for tests being built for coverage analysis support is meaningless.’
   18 |     #pragma message("Defining VERIFY for tests being built for coverage analysis support is meaningless.")
      |             ^~~~~~~
[19/19] Linking C executable src/Coverage/tests

This PR fixes the issue.

It is an alternative to #1251 and #1291.

@real-or-random
Copy link
Contributor

@hebasto Can you summarize what this PR does and why is it preferable to #1291? The approach in #1291 seemed natural to me.

@hebasto hebasto changed the title cmake: Rework tests target for Coverage configuartion and multi-config generators cmake: Rework tests target for Coverage configuration and multi-config generators Aug 10, 2025
This change ensures the correct evaluation of `is_multi_config` when
printing the configure summary.
The initial idea was to place the desired default build configuration
first in `CMAKE_CONFIGURATION_TYPES`. The "Ninja Multi-Config" generator
treats the first configuration as the default, but this is not the case
for other generators.

This change uses the dedicated `CMAKE_DEFAULT_BUILD_TYPE` variable for
the same purpose, avoiding hard-coding `CMAKE_CONFIGURATION_TYPES` and
preserving users' settings, if any.
Only the "Ninja Multi-Config" generator supports an `EXCLUDE_FROM_ALL`
target property value that varies by configuration.
@hebasto hebasto marked this pull request as ready for review August 10, 2025 17:41
@hebasto
Copy link
Member Author

hebasto commented Aug 10, 2025

Rebased and reworked.

The following is an example workflow on Ubuntu 24.04:

cmake -B build -DCMAKE_GENERATOR="Ninja Multi-Config"
cmake --build build --config Coverage  # Ninja uses all available cores by default
ctest --test-dir build -j $(nproc) -C Coverage
mkdir -p build/coverage
gcovr --merge-mode-functions=separate --exclude 'src/bench*' --html --html-details -o build/coverage/coverage.html
firefox build/coverage/coverage.html

@hebasto
Copy link
Member Author

hebasto commented Aug 10, 2025

@hebasto Can you summarize what this PR does and why is it preferable to #1291? The approach in #1291 seemed natural to me.

Answered in #1716 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants