Commit Graph
1982 Commits
Author SHA1 Message Date
Brad King ec85176fbe Merge topic 'if-RULE-operator'
d4dc18c01b if() command: add RULE operator

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12529
2026-09-22 10:16:47 -04:00
Brad King 2020c66db9 Merge topic 'ctest-fixture-repeat'
5cced02b9d CTest: Repeat test fixtures with the tests that require them
4fcf3dd296 CTest: Ignore a checkpoint entry for a test that is not pending
32b25b94d6 CTest: Track one run number for a repeating test

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !11638
2026-09-22 10:01:43 -04:00
Marc Chevrier d4dc18c01b if() command: add RULE operator 2026-09-21 18:10:48 +02:00
Brad King c512ae97ce Merge topic 'custom-rule-support'
386d1d874c Add support of custom rules

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12361
2026-09-21 11:40:22 -04:00
Marc Chevrier 386d1d874c Add support of custom rules
Fixes: #27383
2026-09-20 11:43:10 +02:00
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
Brad King 670f62d10d Merge topic 'cmake_path-empty-prefix'
7192a2b798 cmake_path: An empty path is not a prefix of any path

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12493
2026-09-18 08:16:12 -04:00
Brad King ab46a992e5 Merge topic 'ctest-dashboard-preset-env'
27f28db197 Help: Clarify CTEST_NO_TESTS_ACTION support and interaction
a235560e53 Help: Clarify interaction between CTest parallelism toggles
f745dd11ab ctest: Respect test envvars set by CTEST_PRESET
277236a99a cmCTestTestCommand: Factor out preset resolution
81b46d87ba cmCTest: Factor out environment variable handling
4e81913645 Tests: Fix unset(ENV{...}) typos

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12495
2026-09-18 07:59:56 -04:00
Mickaël Germain 7192a2b798 cmake_path: An empty path is not a prefix of any path
cmake_path(IS_PREFIX) and $<PATH:IS_PREFIX> treated an empty path as a
prefix of every path, including another empty path, following
std::filesystem::path.  A prefix that is empty because a variable was
set to an empty value, or because a generator expression argument
expanded to nothing, therefore satisfied a check meant to reject it.

Return false for an empty prefix, in cmCMakePath::IsPrefix so that every
caller shares one implementation and both the plain and NORMALIZE forms
are covered.  Normalizing an empty path leaves it empty, so no separate
handling of NORMALIZE is needed.  Unlike the component comparison, which
follows std::filesystem::path deliberately, IsPrefix has no counterpart
in the standard: it borrows path iteration but the predicate itself is
defined by CMake, so an empty prefix is a gap to fill rather than a
standard answer to override.

Add policy CMP0223 and restore the old result behind it at the two
released surfaces.  The other callers of IsPrefix, source_group() and
the Makefile generator's source classification, take the new behavior
ungated: source_group() rejects an empty TREE argument before reaching
it, and the generator passes the source and binary directories.

The if(PATH_IS_PREFIX) operator, new in this same release, follows the
policy too rather than simply taking the new behavior, so that it agrees
with cmake_path(IS_PREFIX) in every policy state and the parity
assertions in its test hold unconditionally.

Fixes: #28077
2026-09-17 10:05:27 -04:00
Tyler Yankee 27f28db197 Help: Clarify CTEST_NO_TESTS_ACTION support and interaction 2026-09-16 09:51:11 -04:00
Tyler Yankee a235560e53 Help: Clarify interaction between CTest parallelism toggles 2026-09-16 09:51:10 -04:00
Matthew Woehlke 2673161b67 install: Improve documentation, argument parsing
Adjust documentation of `install(CODE|SCRIPT)` to more understandably
reflect how the subcommand actually operates. Adjust argument parsing of
the same to "accept" the `COMPONENT` argument being given more than
once, consistent with how single-valued arguments are usually parsed.
2026-09-11 12:22:25 -04:00
Brad King 34bbc91e3b Merge topic 'if-PATH_IS_PREFIX'
860583ceac if: Add PATH_IS_PREFIX operator
3d53f7901b Tests: Cover cmake_path(IS_PREFIX) path semantics
59a096f73b Tests: Detect a malformed genex in the PATH:IS_PREFIX test

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12427
2026-09-11 09:11:02 -04:00
Mickaël Germain 860583ceac if: Add PATH_IS_PREFIX operator
Testing whether one path is a prefix of another is possible today with
cmake_path(IS_PREFIX), but the idiom needs a separate statement plus a
scratch variable and takes the prefix as a variable name, so projects
reach for if(path MATCHES "^${prefix}") instead.  That is wrong whenever
the prefix contains a regex metacharacter, and it accepts siblings,
because '^/a/b' matches '/a/bc'.

Add a binary operator where the left operand is the candidate prefix and
the right is the path, matching the operand order of cmake_path(IS_PREFIX)
and $<PATH:IS_PREFIX> so that the same operation reads the same way on all
three surfaces.  Neither operand is normalized, matching the default of
cmake_path(IS_PREFIX) and the existing PATH_EQUAL operator, so '.' and
'..' are compared as ordinary components.  The test is non-strict, purely
lexical, and applies no relative-to-absolute reconciliation.

Add policy CMP0222 for compatibility, modeled on CMP0139.  The keyword
is consumed as an operator only when it appears in the second argument
slot, so a variable named PATH_IS_PREFIX keeps working in unary and
left-operand position.  What the policy covers is such a variable
appearing after another token, as in if(NOT PATH_IS_PREFIX AND other),
which becomes a configure error under NEW.

Since the operator is an if() spelling of cmake_path(IS_PREFIX) and shares
its implementation, test it by asserting the two agree over a corpus of
inputs rather than by restating expected values.  Those are pinned by the
cmake_path(IS_PREFIX) test, so the operator's tests stay limited to what
has no command equivalent, and no platform branching is needed because
parity holds whatever the host path model answers.

Fixes: #28040
2026-09-10 07:09:47 -04:00
Tyler Yankee 7350b58c16 Help: Move regex specification to cmake-language(7)
Many other places in CMake beyond the `string` command rely on our
regex syntax, so it should be documented in a more general location.

Fixes: #22270
2026-09-07 10:17:42 -04:00
Brad King 99079ccab6 Merge topic 'chsi-distrib-host-vs-target'
52c8b8104b cmake_host_system_information: select host vs sysroot for DISTRIB_*

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Alex Turbov <i.zaufi@gmail.com>
Merge-request: !12453
2026-09-03 09:04:03 -04:00
Daksh Mamodiya 52c8b8104b cmake_host_system_information: select host vs sysroot for DISTRIB_*
`DISTRIB_*` read os-release under `CMAKE_SYSROOT`, so cross builds got
the target distro from a host-oriented command, and a process-wide
static froze the first result.  Add a `FROM_SYSROOT <bool>` option and
policy `CMP0221` to default to the host, parse per call, and scope
`CMAKE_SYSROOT` so the fallback scripts follow the same choice.

Fixes: #27640
2026-09-02 14:48:36 +02:00
Alex Turbov 76a8381c98 ci(pre-commit): version bump typos hook + fix found typos 2026-08-29 05:26:37 +04:00
Brad King c23b537168 Merge topic 'instrumentation-proc-metrics'
5f222e8f3a Instrumentation: Add Process Resource Usage Metrics
7204679f48 Merge branch 'upstream-KWSys' into instrumentation-proc-metrics
431a794a66 KWSys 2026-08-27 (8f4afc3e)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12381
2026-08-28 09:17:39 -04:00
Martin Duffy 5f222e8f3a Instrumentation: Add Process Resource Usage Metrics
Issue: #26675, #27742
2026-08-27 10:24:25 -04:00
Brad King 1f40df769c Merge topic 'install-RUNTIME_DEPENDENCY_SET-note'
9057de7baf Help/install: Promote RUNTIME_DEPENDENCY_SET caveat to note

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12433
2026-08-25 09:34:09 -04:00
Brad King e903d46b9a Merge topic 'install-TARGETS-default-MODULE'
8072e80f4b install(TARGETS): Add default destination for MODULE libraries

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12403
2026-08-24 12:27:07 -04:00
Tyler Yankee 9057de7baf Help/install: Promote RUNTIME_DEPENDENCY_SET caveat to note
Amends the documentation update in commit 24b76eaa93 (Help: Improve
readability and accuracy of runtime deps-related content, 2021-07-03,
v3.21.0-rc3~16^2).

Until a new feature is (potentially) implemented offering projects more
flexibility in this regard, the semantics around installation of
internal build-tree dependencies should be clarified, as it has caused
confusion on multiple occasions.

Issue: #28048
2026-08-24 11:26:39 -04:00
Tyler Yankee 45a426a4e3 codespell: Fix some hyphenated spellings
These were surfaced by an updated `codespell` in the `spellcheck` CI
base image.
2026-08-21 09:43:48 -04:00
Tom Osika 8072e80f4b install(TARGETS): Add default destination for MODULE libraries
Installing a module target without a LIBRARY DESTINATION no longer
raises an error. On DLL platforms, the default destination is the
RUNTIME default. Otherwise, the LIBRARY default is used.

Closes: #27759
2026-08-13 10:55:07 -04:00
Brad King 9f73c35d67 Merge topic 'list-transform-shared-state'
3151f7824f cmList: Fix shared state across nested list(TRANSFORM) calls

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12390
2026-08-12 11:42:42 -04:00
Mickaël Germain 3151f7824f cmList: Fix shared state across nested list(TRANSFORM) calls
The TRANSFORM action registry held one live action instance per action for
the whole process, and each instance carried per-call state: a raw Selector
pointer, REPLACE's helper, APPEND/PREPEND's operands.  That was harmless
while every action ran to completion uninterrupted, but commit c7af6e94d8
(list(TRANSFORM): Add PREDICATE selector, 2026-04-08, v4.4.0-rc1) added a
selector that runs a user function once per element, interleaved with the
transform.  User code reentering list(TRANSFORM) with the same action now
rebinds the shared instance mid-flight.  That produces silently wrong
results, and a use-after-free once any element is transformed after the
reentering one.  It needs no unusual code to hit: a predicate calling
find_package(Python) reaches list(TRANSFORM ... REPLACE) inside FindPython's
own module.

Make action objects immutable and per-call.  Operands and the selector become
constructor arguments, Initialize is deleted, and the registry becomes a
constexpr table of metadata with a MakeTransformAction factory.  The
InSelection guard, duplicated in all eight actions, moves into the base class.

This also closes a second hole in the same machinery.  TransformActionApply
overrode only the vector form of Initialize, so transform(APPLY, "f",
selector) dispatched to the empty two-argument virtual in the base, left
Selector null, and dereferenced it.  With no virtual Initialize left to
inherit, an APPLY action without a cmMakefile is no longer constructible, so
the throwing stub that guarded the vector form is no longer needed.

Close a third, from commit 651f82642c (Add APPLY action for list(TRANSFORM),
2026-04-08, v4.4.0-rc1): the cmMakefile overload performs APPLY
unconditionally but validated only the arity of the action passed to it.
APPEND, PREPEND and APPLY all take one argument, so transform(APPEND, "x",
makefile) passed validation and then silently ran APPLY, calling "x" as a
function instead of appending it.  Reject any action but APPLY up front.
That path is unreachable from CMake code, since HandleTransformCommand only
selects the overload for APPLY, and Tests/CMakeLib has no cmMakefile to drive
it with, so it carries no test.

Document the predicate's evaluation order while here.  It runs once per
element, immediately before that element would be transformed.  The manual
did not state the timing, which matters precisely because a predicate that
reenters list(TRANSFORM) observes the outer call mid-flight.

Fixes: #28031
2026-08-11 11:36:08 -04:00
Tom Osika 2a2012e913 cmake_language: Add PRINT_PROPERTIES operation
Print CMake entities' properties in human-readable form for debugging.

Issue: #27513
2026-08-10 17:41:05 -04:00
Brad King fd093f59e7 Merge topic 'string-json-array-split'
7cca8540ca string(JSON): Add ARRAY_SPLIT mode for linear array iteration

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !12386
2026-08-08 10:49:20 -04:00
Brad King 628ceffe6b Merge topic 'enable-language-subdirectory'
86759dce81 enable_language: add support for usage in subdirectories
220fc8622d block: Fix incorrect policy scope creation order

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12222
2026-08-08 10:45:42 -04:00
Daksh Mamodiya 7cca8540ca string(JSON): Add ARRAY_SPLIT mode for linear array iteration
Iterating a JSON array with GET re-parses the entire string on every
call, so walking N elements is O(N^2).  ARRAY_SPLIT parses the array
once and returns its elements as a CMake list, letting each element be
queried individually in linear total time.

Each element is re-serialized as compact JSON and encoded to survive
CMake list parsing: '[' and ']' inside strings are emitted as \u005B
and \u005D, and ';' is escaped as '\;'.  Every element therefore stays
valid, re-queryable JSON.

Fixes: #27985
2026-08-07 17:45:50 +02: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
Tom Osika a06658b6d7 cmake_language: Add PRINT_VARIABLES operation
Print CMake variables in human-readable form for debugging.

Issue: #27513
2026-08-05 14:45:44 -04:00
Brad King 8a947d73d5 Merge topic 'warn-non-target-directives'
00959286b9 Diagnostics: Warn about non-target directives

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12172
2026-07-29 10:34:27 -04:00
Matthew Woehlke 00959286b9 Diagnostics: Warn about non-target directives
Introduce `CMD_STRICT` to act as a parent for warnings about allowed but
disrecommended usage. Introduce a warning that discourages use of
non-target directives (which modify the build environment for the entire
[sub]tree). Add notes to the official documentation recommending use of
target-specific alternatives. This has been accepted wisdom for quite
some time, but only some of the affected commands made any mention of
this in the documentation.
2026-07-28 11:38:20 -04:00
Brad King 4b88240b64 Merge topic 'ctest_test-label-and'
257865e1d4 CTest: Make ctest_test() label filters multi-value (AND)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12321
2026-07-28 09:50:30 -04:00
Brad King e7b32d14b9 Merge topic 'doc-FILE_SET-buildsystem'
c707fde0f2 Help: Move general FILE_SET info to cmake-buildsystem(7)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12309
2026-07-28 09:46:09 -04:00
Daksh Mamodiya 9d9733a7f5 Help: Clarify add_custom_command COMMENT display timing
The "before the commands are executed" wording predated the Ninja
generator; the native build tool controls when and how it is shown.

Fixes: #27991
2026-07-27 17:42:22 +02:00
Tyler Yankee c707fde0f2 Help: Move general FILE_SET info to cmake-buildsystem(7)
File sets have evolved to be more ubiquitous throughout a CMake build,
outside the scope of simply the target_sources command. Move general
information to the `cmake-buildsystem(7)` manual and keep only
reference information specific to the syntax of target_sources in its
command page. Sprinkle some more cross-references to the new location.

Fixes: #27900

Suggested-By: Marc Chevrier <marc.chevrier@gmail.com>
2026-07-27 09:01:37 -04:00
Daksh Mamodiya 257865e1d4 CTest: Make ctest_test() label filters multi-value (AND)
The ctest(1) command line allows repeating -L/-LE to form an AND
filter over test labels, but the ctest_test() and ctest_memcheck()
scripting commands accepted only a single INCLUDE_LABEL/EXCLUDE_LABEL
value, so a dashboard script could not express that filter.

The label-matching engine already stores the include/exclude
expressions as vectors and applies them with AND semantics; only the
command binding was single-value.  Change both keywords to multi-value
(NonEmpty<vector<string>>) and hand the collected list straight to the
engine.  ctest_memcheck() gains the same behavior for free, since it
inherits the option set.

Fixes : #27497
2026-07-24 21:27:58 +02:00
Tom Osika a09578ae84 Help/cmake_language: Fix PRINT_TARGETS signature rendering 2026-07-22 14:39:00 -04:00
Tom Osika f46a631f0c Help/cmake_language: Document print operation(s) last
Move documentation added by commit 45623dd5f6 (cmake_language: Add
PRINT_TARGETS operation, 2026-06-26) to the end of the signature list
to make room for more print signatures.

Issue: #27513
2026-07-22 14:38:41 -04:00
FeRD (Frank Dana) b3e1e07c67 Help: target_sources: Align descriptions with signatures
Recent changes to the `target_sources()` docs changed the `<items>`
placeholders to `<source>` or `<files>` (for `FILE_SET` commands),
but the documentation still used "items" frequently, and even
`<items>` once.

Change all mentions of "items" to use terms that match the
corresponding placeholders, for consistency.
2026-07-21 15:43:01 -04:00
FeRD (Frank Dana) 8df169ebe1 Help: target_sources: Align descriptions with signatures
Recent changes to the `target_sources()` docs changed the `<items>`
placeholders to `<source>` or `<files>` (for `FILE_SET` commands),
but the documentation still used "items" frequently, and even
`<items>` once.

Change all mentions of "items" to use terms that match the
corresponding placeholders, for consistency.
2026-07-21 15:42:13 -04:00
Brad King a6d2c60f73 Merge topic 'googletest_handle_newline_characters'
2c181bd60a GoogleTest: Drop newlines from test names
b464920acc string(STRIP): Document that it removes newlines

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12262
2026-07-20 09:58:38 -04:00
Brad King f890d7a75f Merge topic 'math-increment-decrement'
8cf21478ac math(): Add INCREMENT and DECREMENT modes

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !12280
2026-07-17 10:34:48 -04:00
Brad King 7991e0dc19 Merge topic 'alias-transparency-install'
77156c92eb ALIAS: Add support for install and export commands

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12260
2026-07-17 10:23:26 -04:00
Kyle Edwards 8cf21478ac math(): Add INCREMENT and DECREMENT modes 2026-07-15 11:40:07 -04:00
Arha Gatram 77156c92eb ALIAS: Add support for install and export commands
The install({TARGETS, EXPORT}) versions of the command now accept ALIAS
targets. The behavior is identical to what would happen if the name of
the target that the ALIAS references were put instead. The
export(TARGETS) command also has the same support and behavior for ALIAS
targets now.

Closes: #20979
2026-07-10 17:01:49 -07:00
Robert Maynard b464920acc string(STRIP): Document that it removes newlines 2026-07-10 14:34:10 -04:00