Commit Graph
1205 Commits
Author SHA1 Message Date
Taylor Braun-JonesandTyler Yankee 5cced02b9d CTest: Repeat test fixtures with the tests that require them
When ctest repeats tests with its --repeat option, it repeats each test
on its own.  A fixture's setup and cleanup tests therefore run all of
their repetitions back to back, and the tests they bracket repeat inside
a single setup/cleanup pair:

  setup -> setup -> test -> test -> cleanup -> cleanup

Add a FIXTURE_REPEAT_MODE test property to select how a fixture behaves
when its tests are repeated:

* AROUND_ALL_REPEATS: the fixture runs once, around all repetitions of
  the tests requiring it.
* AROUND_EACH_REPEAT: the fixture and the tests requiring it repeat
  together, so every repetition gets a fresh setup and its own cleanup.
* EACH_TEST_SEPARATELY: every test repeats on its own, as before.

The property describes the fixture rather than the test carrying it, so
setting it on any one of a fixture's setup or cleanup tests is enough.

In AROUND_EACH_REPEAT mode the tests of a fixture form a repeat group that
ctest re-queues as a whole once every test in it has finished.  The --repeat
condition then applies to the group the way it applies to an individual
test: until-fail repeats while the whole group passes, until-pass repeats
while any of it does not, and after-timeout repeats while any of it times
out.  Fixtures that share a test repeat together, so a test requiring two of
them still runs once per repetition.

A group is recorded the way a repeating test is: only once it stops
repeating, and with the results of its last repetition.  A group that
until-pass makes pass therefore reports a pass rather than the failure that
made it repeat, a test that DEPENDS on one of the group's tests waits for
the last repetition rather than the first, and `ctest -F` resumes an
interrupted group by running it again from the beginning.

Fixtures that repeat together have to agree on the mode: a test cannot
repeat with one fixture but not with another it takes part in, and a fixture
whose setup and cleanup tests disagree has no coherent behavior.  Report an
error and run nothing in those cases rather than pick an order in which a
test repeats after a fixture it requires has been cleaned up.

Add policy CMP0224 to select AROUND_EACH_REPEAT as the default for fixtures
whose setup and cleanup tests choose no mode themselves.  Record the mode
the policy chose in the generated test file under its own
_CMAKE_DEFAULT_FIXTURE_REPEAT_MODE keyword, so that ctest reads a mode
rather than the policy settings behind it, and so that a mode requested on
one of a fixture's tests wins over the default recorded for its siblings.
Only NEW needs recording: with nothing recorded, ctest already uses the
behavior of CMake 4.4 and below.  Fixtures are common, and the choice of
mode matters only to those who run ctest --repeat, so warn about the unset
policy only when the CMAKE_POLICY_WARNING_CMP0224 variable asks for it.

discover_tests() and gtest_discover_tests() create their tests while ctest
runs or at build time, too late for the policy to reach them, so carry the
setting in effect at their call sites through to the tests they create.

Report the repetition a grouped test belongs to in the "(run N/M)" suffix
of its "Start" line, as ctest already does for a test repeating on its own.

Co-authored-by: Tyler Yankee <tyler.yankee@kitware.com>
Fixes: #21438
2026-09-18 08:29:28 -04:00
Marc Chevrier a53691b73a cmCustomCommand: reduce raw pointer usage 2026-09-14 18:24:48 +02:00
Tyler Yankee f460a199e3 Source: Add and use CM_UNREACHABLE macro
In debug builds, we assert and abort to give more useful crashes for
development (i.e., instead of triggering UB). Otherwise, we get the
optimization benefits of `unreachable()` (or the older
platform-specific fallbacks per `cm/utility`).
2026-08-26 13:24:34 -04:00
Arha Gatram 86759dce81 enable_language: add support for usage in subdirectories
Propagates variables set in enable_language() logic up variable scopes
so that the language can be used by targets in the ancestor directories.
Works through block() and function() scopes as well. The
add_subdirectory() call can be thought of as the effective call site for
enabling the language. The same holds for endblock() and the actual
function call.

Adds a policy CMP0220 to control this behavior. As the language is
"enabled" at each ancestor scope, the policy is checked. If OLD, the
language is not enabled at this scope and the ones above.

Closes: #27881 #27508 #27389
Related: #26751 #27564
2026-08-07 11:05:57 -04:00
Vito Gamberini ab1bd6f6c6 c++modules: Remove CXX_MODULE_STD and CMAKE_CXX_COMPILER_IMPORT_STD
Fixes: #27966, #27992, #28000
2026-08-03 10:05:34 -04:00
Aiden Woodruff 7bc37a0561 CMAKE_TOOLCHAIN_FILE: Avoid excess reconfigures from relative paths
Save original input value of CMAKE_TOOLCHAIN_FILE also before
normalization or relative searching to avoid reconfiguring because the
full path doesn't match the input. Tests correct behavior avoiding
reconfigures and ensuring reconfigure on toolchain change from preset.

Fixes: #24942
2026-07-22 11:53:05 -04:00
Brad King 1ddfd11b3d Merge topic 'try_compile-enabled-languages'
39cc425791 try_compile: Restore toleration of toolchain file setting internal variable

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12300
2026-07-21 10:07:56 -04:00
Brad King 39cc425791 try_compile: Restore toleration of toolchain file setting internal variable
Prior to commit 243462fafe (try_compile: Tolerate compile features from
non-enabled languages, 2026-05-18, v4.4.0-rc1~84^2) we accidentally
tolerated toolchain files setting `CMAKE_<LANG>_COMPILER_LOADED`.
Meson accidentally relied on this, so restore toleration of it.

Fixes: #27971
2026-07-20 14:52:47 -04:00
Brad King b4f942a873 Merge topic 'few-optimizations'
ce9ac00844 Source: reduce string reallocations
b3dd0aa7c8 Source: remove useless copies & reallocations
1482795668 FASTBuild: fix typo in IDE target log message

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12246
2026-07-08 09:49:21 -04:00
AJIOB ce9ac00844 Source: reduce string reallocations 2026-07-08 09:40:55 -04:00
AJIOB b3dd0aa7c8 Source: remove useless copies & reallocations 2026-07-08 09:40:54 -04:00
Brad King e55cf93295 Merge topic 'remove-vs14-generator'
5b0aee4961 Drop Visual Studio 14 2015 generator

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12245
2026-07-08 09:29:06 -04:00
Brad King 04b2dfd8be Merge topic 'changing-toolchain-recover'
ca3d1007f0 Tests: Simplify RunCMake.CompilerChange
ca0bf9848d cmake: Retain cache from presets and command line before re-configure
ee6bfdc1f3 CMAKE_TOOLCHAIN_FILE: Improve recovery from changed compiler or toolchain file

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12241
2026-07-07 11:12:13 -04:00
Brad King 5b0aee4961 Drop Visual Studio 14 2015 generator
This generator has been deprecated since CMake 4.2.  Remove it.
2026-07-03 11:53:32 -04:00
Aiden Woodruff ee6bfdc1f3 CMAKE_TOOLCHAIN_FILE: Improve recovery from changed compiler or toolchain file
Replace __CMAKE_DELETE_CACHE_CHANGE_VARS_ with a set of changed
variables in cmState to avoid interference from scripts and simplify
handling of changed variables.

Errors during configure step will block re-configure when the toolchain
file has changed. Downstream errors can be caused by failing in
EnableLanguage without an error, behavior introduced in 7a989ed58a
(CMAKE_TOOLCHAIN_FILE: Detect path changes and reset cache, 2026-06-24).
Errors directly related to a changed toolchain file should be fixed by
using the new one.

Trigger a fatal error when the toolchain file change is detected to
avoid wasteful configure that will be reset anyway, then re-configure
only for that specific case. Avoid re-configuring multiple times.

Fixes: #27867
2026-07-03 09:25:33 -04:00
Matthew Woehlke a5a9ec9113 TargetTypes: Extract target-related types to dedicated header
Move some target related enumeration types from `cmStateTypes.h` to a
new header, as these really aren't "state" types. Also, make
`TargetType` a strongly-typed enumeration.
2026-07-01 14:44:11 -04:00
Brad King 28ce1b8bc3 Merge topic 'test-out-of-date'
e11b5827c3 ctest: Add --out-of-date option for running out of date tests

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12180
2026-07-01 09:45:18 -04:00
Martin Duffy e11b5827c3 ctest: Add --out-of-date option for running out of date tests
Add an --out-of-date option to ctest which runs only those tests with
recorded build dependencies whose timestamps are newer than the timestamp
at which the test last finished.

Fixes: #27614
2026-06-30 11:31:35 -04:00
Brad King be33dbe421 Merge topic 'changing-toolchain'
7a989ed58a CMAKE_TOOLCHAIN_FILE: Detect path changes and reset cache

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12211
2026-06-30 11:08:58 -04:00
Aiden Woodruff 7a989ed58a CMAKE_TOOLCHAIN_FILE: Detect path changes and reset cache
If the path to the toolchain file changes then anything in the cache
that's derived from the toolchain may need to be recomputed.  Detect
this case and start a fresh build.

Issue: #27867
Signed-off-by: Aiden Woodruff <aiden.woodruff@kitware.com>
2026-06-29 12:09:16 -04:00
Daksh Mamodiya 503bdb9777 Makefile: Generate test_prep targets for CMAKE_TEST_BUILD_DEPENDS
Extend the test_prep/<test> and test_prep/all build targets, generated
from add_test(BUILD_DEPENDS) when CMAKE_TEST_BUILD_DEPENDS is enabled, to
the Makefile generators.  Previously only the Ninja and FASTBuild
generators provided them.

Resolve each test's dependencies in a shared layer so all command-line
generators consume one result.  cmTestGenerator now filters target
dependencies to build-system targets and records, for each file
dependency, the single target that produces it as a primary
custom-command output (cmGlobalGenerator::FindOutputOwningTarget).  The
Makefile generators emit phony rules in CMakeFiles/Makefile2 depending on
<target>.dir/all, with top-level forwarding rules.  Sharing the
resolution also stops Ninja and FASTBuild from emitting a dead test_prep
edge for a non-buildable (e.g. INTERFACE) BUILD_DEPENDS target.

On the Makefile generators a file dependency that no single target
produces, and a test whose name contains ':', cannot be expressed as a
recursive-make rule and are reported with a warning and skipped.

Fixes: #27879
2026-06-24 17:24:54 +02:00
Marc Chevrier 6043014d1d source_group(): Add file set support 2026-06-23 14:55:26 +02:00
Brad King dfd1cf8d87 Merge topic 'import-std-refactor'
42d2d63235 c++modules: Copy props from BMI consumers more correctly
6d3e9d8220 c++modules: single import std target

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Reviewed-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !12193
2026-06-22 18:21:02 -04:00
Vito Gamberini 6d3e9d8220 c++modules: single import std target 2026-06-18 15:20:54 -04:00
Taylor Sasser 32af67dc72 cmSbom: Add genex support for configurations 2026-06-08 20:54:59 -04:00
Brad King 5636aa7740 Merge topic 'cxx-module-usage-effects'
2049419196 c++modules: document BMI compatibility changes
bfba7f68af c++modules: Correctly calculate and apply usage effects

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12116
2026-06-03 10:01:51 -04:00
Vito Gamberini bfba7f68af c++modules: Correctly calculate and apply usage effects
Usage effects describe the relationship between a provider and a
consumer of C++ module interface units. They encompass the flags and
features used to construct BMIs for those units. If the usage effects of
a provider and consumer match, then the provider's BMI may be reused
as-is. If they do not match, then a synthetic target describing the
interface units with the consumer's usage effects applied must be
created.

This commit makes three major changes to how usage effects are reified
in CMake. The first is simple, usage effect hashes now use compile
options and features as the input to their hash instead of the consumer
name. A simply warning flag filter is also applied, mostly to
demonstrate the mechanism. This is the "correct calculation" for usage
effects.

The second is more impactful, usage effects now entirely replace the
compile options of providers with those of consumers if unmatched.
Compile definitions, includes, and links remain unchanged. This is
necessary to ensure successful builds, but is a tricky semantic change.

The third is mostly source-facing, the discovery model for CxxModule
synthetic targets is no longer the global target namespace. Instead,
non-synthetic targets manage their synthetic derivatives. Every target
maintains a usage effect-keyed cache of synthetic targets. When
determining if a synthetic target is necessary, a given provider checks
for compatibility with itself, then for presence in the cache, and if
the cache misses a new synthetic target is created.

Fixes: #27597
2026-06-02 15:41:40 -04:00
Brad King f4c858d328 Merge topic 'multi_export_sbom'
2900aa2911 SBOM: Update experimental UUID
273fc4cc49 SBOM: Support multi export set SBOMs
9669829573 Install: Refactor ResolveTargetsInGeneratorExpression
7c31cbf9ae SBOM: Handle PACKAGE_URL argument

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12080
2026-06-02 09:15:40 -04:00
Tom Osika 273fc4cc49 SBOM: Support multi export set SBOMs 2026-06-01 12:27:13 -04:00
Brad King d0deabd995 Merge topic 'try_compile-enabled-languages'
243462fafe try_compile: Tolerate compile features from non-enabled languages
bbab63839b cmGlobalGenerator: Clarify name of try_compile-specific member

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12083
2026-05-27 11:47:09 -04:00
Joseph Snyder 243462fafe try_compile: Tolerate compile features from non-enabled languages
Do not copy the list of enabled languages from the outer generator.
It is populated as languages are enabled inside the test project.

Fixes: #27684
2026-05-26 20:17:27 -04:00
Brad King bbab63839b cmGlobalGenerator: Clarify name of try_compile-specific member 2026-05-26 20:16:44 -04:00
Brad King 22c962a406 Merge topic 'build-databases-support-empty-configs'
575c3dd990 builddb: support builds with empty configuration
3469cc0a46 Tests/CXXModulesCompile: add a test for builddb with empty config
bf442e9deb Tests/CXXModulesCompile: fix `exp-builddb` name references in check scripts

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12101
2026-05-26 16:20:21 -04:00
Ben Boeckel 575c3dd990 builddb: support builds with empty configuration
Rotates the UUID to indicate changed behavior.

See: https://discourse.cmake.org/t/15654
2026-05-22 13:51:06 -04:00
Matthew Woehlke a7415d243a Diagnostics: Simplify issuing policy warnings
Add and use a couple helper functions for issuing policy warnings. This
improves consistency and allows some simplification of many call sites.
(One or two instances in particular are greatly simplified.)
2026-05-20 11:55:13 -04:00
Brad King afad360df9 Merge topic 'cmake-more-diagnostics'
028d3183ad Diagnostics: Add POLICY, EXPERIMENTAL
92e0ca9046 Diagnostics: Show author message for all descendants

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12034
2026-05-16 09:53:27 -04:00
Matthew Woehlke 028d3183ad Diagnostics: Add POLICY, EXPERIMENTAL
Add new diagnostic categories CMD_POLICY and CMD_EXPERIMENTAL, both as
children of CMD_AUTHOR. Use the former when issuing policy warnings. Use
the latter when issuing experimental feature warnings.
2026-05-15 09:57:23 -04:00
Matthew Woehlke 727e32ff48 Extra Generators: Always warn
Issue a warning message rather than a deprecation diagnostic when 'extra
generators' are used. This prevents `-Wno-author` suppressing the
message, which really isn't a diagnostic for authors as it relates to
how CMake was invoked.
2026-05-12 13:01:21 -04:00
Brad King 0bbc2c0e9a Merge topic 'cmp0171-diagnostic-context'
556bd0d722 CMP0171: Improve diagnostic context

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12043
2026-05-12 10:42:38 -04:00
Matthew Woehlke 556bd0d722 CMP0171: Improve diagnostic context
When issuing the policy warning that `codegen` is a reserved target
name, use the diagnostic context in which the target was declared,
rather than the root context (which cannot be affected in script).
2026-05-11 15:02:49 -04:00
Matthew Woehlke 5ed6b90a31 Diagnostics: Capture install state
Modify `cmInstallGenerator` to have a `cmDiagnosticContext` instead of
just a `cmListFileBacktrace`. Create helpers to obtain a state capture
that includes `CMD_INSTALL_ABSOLUTE_DESTINATION`. Modify most subclasses
(namely, ones that have a `DESTINATION`) to use this new state capture.

This fixes a limitation identified when 39a56136a3 (Diagnostic: Add warn
or error on absolute install paths, 2026-03-25) added the aforementioned
diagnostic, that the install generator(s) no longer have access to the
diagnostic state as of the `install` invocation which ultimately caused
the diagnostic if that scope is not the top-most scope of the current
subdirectory.

Note that some of the generators which capture context have not actually
implemented the diagnostic yet.
2026-05-08 11:23:11 -04:00
Matthew Woehlke 1309532390 Diagnostics: Use new methods
Find places that are currently relying on diagnostic-specific message
types to issue diagnostics and replace these with calls to the new
diagnostic methods.
2026-04-16 15:10:35 -04:00
Baudouin Feildel 881faf67e5 Rust: Switch to building .rs files to .rlib instead of native object files
Each Rust source file given to a target is considered a separate crate
root. There's a concept of a "main crate root", which is the `.rs` file
that is given to the final linker phase in CMake. Other Rust source file
in a target are built as rlib separately.

The project can still build `.rs` files into object files by setting the
Rust_EMIT property on the desired source file.
2026-03-20 09:42:44 -04:00
Alex Overchenko 70b35324ec Source: Reduce const char* to std::string conversions 2026-03-10 11:45:36 -04:00
Tyler Yankee 8b350fae71 CMP0210: Warn at most once per CMAKE_<LANG>_LINK_FLAGS variable
Additionally, add more testing for the warning case.

Issue: #21934
2026-02-18 11:44:07 -05:00
Brad King b0bcc6c7c0 Merge topic 'UseMoreStringViews'
70509802f5 cmSystemTools: Fix clang tidy warning else after return
d932b6fb8d Prefer cmHasSuffix for specific extension checks
35af170961 cmSystemTools: Take view instead of ref as parameter
9daa1012d4 cmGlobalGenerator: Avoid string copies by returning view
e531e7420d Reduce string copies by using View function alternatives
62a4099fd2 cmGeneratorTarget: Cache GetAllConfigCompileLanguages
6ed75b1fe6 cmGlobalGenerator: Use transparent comparator to avoid string copies
9a575a835f cmPropertyDefinition: Avoid string copies for Property lookups
...

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11634
2026-02-07 09:33:34 -05:00
John Franklin Rickard 9daa1012d4 cmGlobalGenerator: Avoid string copies by returning view 2026-02-06 12:27:23 -05:00
John Franklin Rickard e531e7420d Reduce string copies by using View function alternatives 2026-02-06 12:27:13 -05:00
John Franklin Rickard 6ed75b1fe6 cmGlobalGenerator: Use transparent comparator to avoid string copies 2026-02-06 12:27:13 -05:00
John Franklin Rickard c3c3b10d60 cmGlobalGenerator: Change parameter to string_view 2026-02-06 12:27:12 -05:00