343 Commits
Author SHA1 Message Date
AJIOB 1d2f0120be Source: Reduce string allocations, part 3 2026-09-22 11:37:41 +03: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
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 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
AJIOB ce9ac00844 Source: reduce string reallocations 2026-07-08 09:40:55 -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 9883f84e8f Merge topic 'genex-list-sort-comparator'
4d86ef5e86 GenEx: add $<LIST:SORT,...,COMPARATOR,body> comparator
c418a3dc85 GenEx: factor out reusable SORT comparator and option-parsing helpers
e335872625 GenEx: generalize bound operands to a frame and add $<_1>

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12228
2026-07-01 09:46:35 -04:00
Brad King 68d210d6c1 Merge topic 'FILE_SET-properties-evaluate-genex'
7f71e58444 FILE_SET: fix genex evaluation of properties

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !12233
2026-07-01 09:17:33 -04:00
Mickaël Germain 4d86ef5e86 GenEx: add $<LIST:SORT,...,COMPARATOR,body> comparator
Add a COMPARATOR form to $<LIST:SORT> that orders the list by a caller-defined
rule: a <body> evaluated per comparison with the two elements bound to $<_0>
and $<_1>, yielding "1" when the first should sort before the second.  This
brings the custom ordering of list(SORT ... COMPARATOR) to generate time, so
elements can be ordered by target properties or any other generator expression.
CASE: and ORDER: still apply, while COMPARE: is rejected because the body
defines the ordering.

Fixes: #27892
2026-06-30 08:19:41 -07:00
Mickaël Germain c418a3dc85 GenEx: factor out reusable SORT comparator and option-parsing helpers
Prepare for a genex-driven SORT comparator without changing behavior: let
cmList::sort() accept a caller-supplied comparison function, and give the
$<LIST:SORT> COMPARE:/CASE:/ORDER: option parsing a single definition shared
with the canned handler.  The new feature can then reuse both rather than
duplicating the sort plumbing and the option syntax.

Issue: #27892
2026-06-30 08:19:41 -07:00
Mickaël Germain e335872625 GenEx: generalize bound operands to a frame and add $<_1>
Allow a binding operation to bind more than one operand at once, exposed as
$<_0>, $<_1>, ....  A single value remains the common case, but the upcoming
SORT COMPARATOR must bind the two elements being compared, so the binding
becomes an indexed frame and $<_1> is added.  Referencing an index the active
binding does not provide is reported as an error.

Issue: #27892
2026-06-30 08:19:41 -07:00
Marc Chevrier 7f71e58444 FILE_SET: fix genex evaluation of properties 2026-06-30 11:59:07 +02:00
Mickaël Germain 0b5a172c22 Help: hyperlink $<_0> and configure-time commands in $<LIST> docs
Several $<LIST> doc references appeared as plain literal text: the bound
operand $<_0>, the configure-time list(TRANSFORM ... APPLY) command (the
TRANSFORM APPLY action title and prose), and the $<LIST:TRANSFORM,...,APPLY,body>
example in the $<_0> definition.  Use the :genex: and :command: roles so they
hyperlink to their definitions, matching the sibling canned actions and the
rest of the manual.

Issue: #27892
2026-06-25 11:20:52 -04:00
Mickaël Germain 092edb6860 GenEx: add $<LIST:FILTER> PREDICATE filter and REGEX keyword
Let $<LIST:FILTER> select elements by an arbitrary condition: PREDICATE keeps or
drops each element according to a <body> evaluated with $<_0> bound,
complementing the existing regular-expression form.  Also accept an explicit
REGEX keyword before the pattern so the regex and predicate forms read
symmetrically; the bare pattern keeps working.

Issue: #27892
2026-06-23 21:31:49 -07:00
Mickaël Germain d2ad140ef9 GenEx: add PREDICATE selector to $<LIST:TRANSFORM>
Add a PREDICATE selector to $<LIST:TRANSFORM> that chooses which elements to
transform by evaluating a <body> per element (with $<_0> bound) and acting on
those for which it yields "1".  This selects by computed condition instead of
the fixed AT/FOR/REGEX positions, so any generator expression -- including
target queries -- can decide where an action applies.  It works with both the
canned actions and APPLY.

Issue: #27892
2026-06-23 21:31:20 -07:00
Mickaël Germain 6024f624b0 GenEx: factor TRANSFORM action descriptor lookup
Resolve each canned $<LIST:TRANSFORM> action to its cmList action and argument
count through a single table rather than an inline chain, so the PREDICATE
selector added next can reuse the same action metadata instead of duplicating
it.

Issue: #27892
2026-06-23 20:39:13 -07:00
Mickaël Germain 0f6e8ded1d GenEx: add $<LIST:TRANSFORM,...,APPLY,body> action
Add an APPLY action to $<LIST:TRANSFORM> that evaluates an arbitrary <body>
once per selected element, with $<_0> bound to the element, so a list can be
mapped through any generator expression at generate time.  Unlike the
configure-time list(TRANSFORM ... APPLY <function>) command, the genex form has
no side effects and returns the body's value directly, and a list-valued result
expands into multiple elements.

The body evaluates in its own binding scope, so nested APPLY actions can shadow
$<_0>, and context-sensitive state it observes (such as target dependencies)
still propagates to the enclosing expression.  APPLY accepts the same
AT/FOR/REGEX selectors as the canned actions.

Issue: #27892
2026-06-21 18:05:53 -07:00
Mickaël Germain c0a0b7fdd9 GenEx: add bound-operand binding mechanism and $<_0>
Introduce "binding operations": generator expressions that evaluate a <body>
once for each value they supply, with $<_0> expanding to that value.  This is
the foundation the $<LIST:TRANSFORM,...,APPLY> action and the predicate
selectors build on, letting a <body> refer to the element being processed.

Using $<_0> outside a binding operation is reported as an error rather than
silently expanding to nothing.

Issue: #27892
2026-06-20 12:32:30 -07:00
Mickaël Germain caa51f5689 GenEx: factor TRANSFORM selector parsing and selection
Give the AT/FOR/REGEX selector syntax shared by the $<LIST:TRANSFORM> actions a
single definition, so its diagnostics and index/REGEX semantics cannot drift
between actions.  Also let a caller learn which elements a selector picks
without running a transform, as groundwork for actions that drive their own
per-element loop.

Issue: #27892
2026-06-20 12:32:29 -07:00
Marc Chevrier 699f4d61a5 GenEx SOURCE_PROPERTY: fix evaluation of generation expressions 2026-06-03 15:44:16 +02: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
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 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
Kyle Edwards 987e0af366 GenEx: Add $<TARGET_OBJECTS:...> option to filter on source files
Fixes: #27675
2026-03-10 10:51:43 -04:00
Marc Chevrier 63775fe60f FILE_SET: add the support of properties for file set inspection 2026-02-28 13:46:57 +01:00
Marc Chevrier dee8799d16 FileSet management: Introduce dedicated classes for generation
To manage the generation step, introduce cmGeneratorFileSet and
cmGeneratorFileSets classes.
These reorganizations of the code are done in preparation of the
implementation of SOURCES file set type as well as user's file set types.

Issues: #27550, #27383
2026-02-19 17:35:56 +01:00
Marc Chevrier 209d86c5fe GenEx FILE_SET_PROPERTY 2026-01-28 16:57:35 +01:00
Marc Chevrier e2a38a3990 GenEx SOURCE_PROPERTY
This feature is required for the support of the future feature of
pattern rules (see #27383).

But it is also a valuable addition in the context of custom command and target.
2026-01-21 16:03:30 +01:00
Brad King 08e1d1001a Merge topic 'fix-cmp0199'
35d5a4fd6d GenEx: Partially restore pre-CMP0199 behavior of $<CONFIG>

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Acked-by: Matthew Woehlke <matthew.woehlke@kitware.com>
Merge-request: !11581
2026-01-13 11:05:11 -05:00
Matthew Woehlke 35d5a4fd6d GenEx: Partially restore pre-CMP0199 behavior of $<CONFIG>
Modify the implementation of policy CMP0199 to only remove the oddball
configuration map matching of `$<CONFIG>` in `NEW` mode, restoring the
old behavior of matching BOTH the consumer's configuration and the
selected configuration of the imported target. It turns out that users
are more dependent on the former than the latter, and while matching
more than one thing is still dodgy, we will likely need to introduce a
new generator expression to match the selected configuration of the
imported target.

Meanwhile, `$<CONFIG>` on targets imported from CPS still only matches
the selected configuration of the imported target, which is the behavior
specified by CPS. However, this can only happen for `$<CONFIG>`
expressions that were generated internally during import.

Update documentation and test cases accordingly.

Fixes: #27487
Fixes: #27495
2026-01-12 10:58:08 -05:00
AJIOB fe173b68f0 Source: Use cmStrCat in place of string addition 2025-12-09 11:06:59 -05:00
Ben Boeckel 514cbbc76e ast-grep: combine string literal arguments in cmStrCat 2025-11-20 12:14:13 -05:00
Marc Chevrier fd7e305097 GenEx: Add $<STRING> generator expression
Fixes: #27188
2025-11-14 16:44:29 +01:00
Marc Chevrier 7564cbae12 GenEx: add new expressions for string comparisons 2025-11-14 16:44:29 +01:00
Brad King 8832f78dd6 IWYU: Update for Debian 13 CI job
`include-what-you-use` diagnostics, in practice, are specific to
the environment's compiler and standard library.  Update includes
to satisfy IWYU for our CI job under Debian 13.  Some patterns:

* Types named in virtual `override` signatures no longer require
  includes since the overridden signature already names them.

* A function argument's type needs to be included even if its constructor
  is called only by implicit conversion.  For example, constructing a
  `std::function` from a lambda now requires `<functional>`.

* Some prior mysterious `<type_traits>` inclusions are no longer required.
2025-11-12 14:54:35 -05:00
Brad King f49b0e6759 IWYU: Update for Debian 13 CI job
`include-what-you-use` diagnostics, in practice, are specific to
the environment's compiler and standard library.  Update includes
to satisfy IWYU for our CI job under Debian 13.  Some patterns:

* Types named in virtual `override` signatures no longer require
  includes since the overridden signature already names them.

* A function argument's type needs to be included even if its constructor
  is called only by implicit conversion.  For example, constructing a
  `std::function` from a lambda now requires `<functional>`.

* Some prior mysterious `<type_traits>` inclusions are no longer required.
2025-11-12 14:54:16 -05:00
Martin Duffy f195c9ef2a genex: Add TARGET_INTERMEDIATE_DIR expression
Fixes: #27196
2025-10-09 08:07:20 -04:00
Martin Duffy 5c5634db52 cmGeneratorExpressionNode: Factor out HasKnownObjectFileLocation check 2025-10-08 17:34:02 -04:00
Craig Scott 1b764b6816 cmLinkItem: Remove redundant cmLinkImplItem class
The cmLinkImplItem class used to contain some additional members
to support the CMP0027 policy. Since the CMP0027 policy and those
associated members were removed, the cmLinkImplItem class has been
a plain wrapper around cmLinkItem with no additional members.
It is no longer needed and cmLinkItem can be used directly wherever
cmLinkImplItem was used previously.
2025-10-07 10:44:28 -04:00
Brad King 7d551a5d6b Merge topic 'genex-transitive-link-libraries'
e0bbe79cea CMP0189: Restore support for linking `$<TARGET_PROPERTY:tgt,LINK_LIBRARIES>`
cb69f750bf cmGeneratorTarget: Factor out helper to detect LINK_LIBRARIES evaluation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11262
2025-09-30 09:59:09 -04:00
Brad King e0bbe79cea CMP0189: Restore support for linking $<TARGET_PROPERTY:tgt,LINK_LIBRARIES>
In general we disallow references to transitive target properties, such
as `COMPILE_DEFINITIONS`, in `[INTERFACE_]LINK_LIBRARIES` properties,
because the latter establish the transitivity itself.  Prior to CMP0189,
the `[INTERFACE_]LINK_LIBRARIES` properties were not themselves transitive
in `$<TARGET_PROPERTY>` expressions, so existing projects have code like

    target_link_libraries(foo PRIVATE "$<TARGET_PROPERTY:tgt,LINK_LIBRARIES>")

Policy CMP0189's NEW behavior, introduced by commit b3da9c6d60 (GenEx:
Evaluate LINK_LIBRARIES target properties transitively, 2025-02-24,
v4.1.0-rc1~731^2), makes `$<TARGET_PROPERTY:tgt,LINK_LIBRARIES>`
transitive, causing the above to be rejected.  Since evaluation of a
target's link libraries can already encounter and handle other targets'
link libraries, allow it in this case.

Fixes: #27265
2025-09-29 10:51:01 -04:00
Brad King 6e1de32c9d Merge topic 'pdb-postfix'
7a154bf4fd GenEx: Add POSTFIX option to $<TARGET_PDB_FILE_BASE_NAME>
5654207925 PDB: Always add the target per-config POSTFIX to .pdb names

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11235
2025-09-26 09:26:49 -04:00
Marc Chevrier 7a154bf4fd GenEx: Add POSTFIX option to $<TARGET_PDB_FILE_BASE_NAME>
Extend commit 0b055a8893 (GenEx: add POSTFIX option to
$<TARGET_FILE_BASE_NAME>, 2025-09-07) to cover PDB names too.
2025-09-25 11:02:44 +02:00
Marc Chevrier 5654207925 PDB: Always add the target per-config POSTFIX to .pdb names
Manage the POSTFIX target property in the same way as other artifacts
names.  Add policy CMP0202 for compatibility.

Fixes: #27206
2025-09-25 11:00:39 +02:00
Brad King 26413a3e3d Merge topic 'file-GENERATE-CMP0189'
deb7b4b658 file(GENERATE): Record CMP0189 at each call site
9b862e7013 cmGeneratorTarget: Pass genex evaluation context to IsTransitiveProperty

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11234
2025-09-24 08:45:14 -04:00
Brad King 9b862e7013 cmGeneratorTarget: Pass genex evaluation context to IsTransitiveProperty 2025-09-23 10:57:22 -04:00
Marc Chevrier 0b055a8893 GenEx: add POSTFIX option to $<TARGET_FILE_BASE_NAME>
Fixes: #27189
2025-09-23 00:19:53 +02:00
Brad King 2a14338676 Merge branch 'backport-genex-refactor' into genex-refactor 2025-09-21 20:22:24 -04:00
Brad King e4708f007b GenEx: Factor out a dedicated evaluation Context structure
The context's local generator, configuration name, and language are
constant throughout evaluation.
2025-09-21 20:21:37 -04:00