627 Commits
Author SHA1 Message Date
Tyler Yankee 721eb8a5a2 cmCommonTargetGenerator: Improve launcher shell conversion
Encapsulate the shell escaping logic in `cmCommonTargetGenerator` and
represent launchers via a vector of strings (as is done with custom
commands, execute process commands, etc.) to make them easier to work
with.

This facilitates work in a future commit which will reuse this pathway.

Issue: #27598, #27402
2026-09-21 13:45:54 -04:00
Evan Wilde 23b33482f1 Swift: Refactor module / object builds
Splitting up the computation of common variables, module build
variables, and object build variables to make it a little easier to
focus on each one.

Updated tests to reflect updated flag order and updated object-build
description.
2026-08-14 17:02:20 -07:00
Brad King ca0ed0f66f Merge topic 'swift-cmp0215-update'
e4a37fbf15 Tests/RunCMake/Swift: Add CMP0195 behavior checks
b7a78568c3 CMP0215: Update NEW behavior to require CMP0157/CMP0195 to be NEW

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12407
2026-08-14 06:30:36 -04:00
Evan Wilde b7a78568c3 CMP0215: Update NEW behavior to require CMP0157/CMP0195 to be NEW
Update CMP0215 to avoid attempting to iterate through the flags
looking for `-emit-module-path` ins the user-specified flags. We don't
do this anywhere else in the code. The existing implementation didn't
handle correctly parsing the flag so `-I blah/my-emit-module-path/` and
`-Xcc -emit-module-path ...` would both trigger it, result in the
compiler not emitting any module. Furthermore, it didn't include the
user-specified module path as part of the build graph resulting in an
incorrect build graph that would never resolve.

The only two appropriate layouts for the module are either the flat
binary module file with the name `<module-name>.swiftmodule`, or the
nested form with
`<module-name>.swiftmodule/<module-triple>.swiftmodule`. The noted
Swift-Syntax situation passes the explicit `-emit-module-path` to get to
the latter form. This form is automatically emitted by CMake when
CMP0195 is `NEW`, removing the need for the flag. The Swift project
generally recommends the nested directory structure since it gathers all
of the generated interface outputs from the compiler (textual swift
interfaces, swiftdoc, sourceinfo, and the binary swiftmodule file) in a
single place, and since it uses the module triple in the filename,
cleanly allows fat mach-o binaries on Apple platforms.

Fixes: #28021
2026-08-13 10:14:16 -04:00
Vito Gamberini 00d8e23414 c++modules: use synthetic interface objects for import std
Fixes: #27999
2026-08-01 19:55:07 -04:00
Brad King 4cb791d4d0 Merge topic 'ninja-swift-cldeps-order'
9d7da095fd Ninja: Restore cmcldeps command-line ordering

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12270
2026-07-15 10:57:32 -04:00
Tyler Yankee 9d7da095fd Ninja: Restore cmcldeps command-line ordering
Restore the ordering before the refactoring in commit 0f20ba5b68
(Ninja: Swift: Extract helpers and reorder module flags, 2026-04-10,
v4.4.0-rc1~273^2~1) to ensure the correct precedence with launchers.
Add regression tests.

Fixes: #27931, #27934
2026-07-14 12:32:21 -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
Michael Kruse 0e142193ac Ninja: Honor Fortran_BUILDING_INTRINSIC_MODULES
In commit b65930a7a7 (Fortran: Add Fortran_BUILDING_INTRINSIC_MODULES
for building intrinsics, 2025-01-09, v4.0.0-rc1~223^2) we only
implemented the property for the Makefile generators.  Implement it
for the Ninja generators too.

Fixes: #26803
2026-06-17 10:47:10 -04:00
Marc Chevrier c06d409f12 FILE_SET: add SKIP_PRECOMPILE_HEADERS property support 2026-06-01 18:39:23 +02:00
Saleem Abdulrasool 404f6bac3c Swift: support PDB emission with Swift
Swift supports CodeView/PDB for Windows (with active development ongoing
to make it the default). It is currently usable but does not have the
same fidelity as DWARF, but can be sufficient for many use cases. The
user is able to control this via flags. Wire up the necessary support to
allow `TARGET_PDB_FILE` to be used with Swift/Swift-only targets.
2026-05-16 09:05:46 -04:00
Brad King bf3a43e4ad Merge topic 'JOB_POOL_COMPILE-FileSet-property'
8e6eec8125 FILE_SET: add JOB_POOL_COMPILE property support

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12005
2026-05-05 10:55:51 -04:00
Marc Chevrier 8e6eec8125 FILE_SET: add JOB_POOL_COMPILE property support 2026-05-04 11:10:01 +02:00
Marc Chevrier f18ba89862 FILE_SET: add SKIP_LINTING property support 2026-05-04 10:16:06 +02:00
Brad King 2d4f8cbb48 Merge topic 'swift-output-file-map-copy-if-different'
feb5275c7a Swift/Ninja: Set copy-if-different on output-file-map.json

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11990
2026-04-30 09:09:35 -04:00
Brad King b22659fa9d Merge topic 'swift-ninja-emit-module-ordering'
d741a4fb90 Swift/Ninja: Serialize compile edge after emit-module within target

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11989
2026-04-30 09:05:41 -04:00
Roman Lavrov d741a4fb90 Swift/Ninja: Serialize compile edge after emit-module within target
Since commit b6367f723b (Swift/Ninja: Emit modules separately from
compilation, 2026-04-10) the compile and emit-module edges share the
same -output-file-map, which references a single module-level
.swiftdeps file.  When ninja schedules both edges concurrently, both
swift invocations write that file and corrupt it.

Add the .swiftmodule output as an order-only dependency of the object
compile edge so the two edges within a target run sequentially.
Downstream targets are unaffected: they still unblock as soon as the
emit-module edge finishes, preserving cross-target parallelism.

Move the object-build WriteBuild call to after the emit-module block
so the order-only dep is added after modBuild is copied from objBuild,
avoiding a self-reference on the emit-module edge's own output.

Issue: #27748
2026-04-29 10:42:37 -04:00
Roman Lavrov b8fedb5979 Swift/Ninja: Add link edge dependency on emit-module output
Since commit b6367f723b (Swift/Ninja: Emit modules separately from
compilation, 2026-04-10) the .swiftmodule output moved from the
compile edge to a separate emit-module edge.  The link edge does not
depend on the emit-module output, so ninja never runs the emit-module
edge when no other target in the build imports the module (e.g.
install-only targets).

Store the declared .swiftmodule output path during Swift object
statement generation and add it as an implicit dependency of the link
edge.

Issue: #27748
2026-04-29 09:58:09 -04:00
Roman Lavrov feb5275c7a Swift/Ninja: Set copy-if-different on output-file-map.json
Avoid bumping the file's mtime on every configure when its content
hasn't changed.  Otherwise ninja sees it as modified and re-runs every
Swift compile edge that depends on it.

Observed in the Swift toolchain build (LLVM monorepo with swift as an
external project): a no-op reconfigure cascaded into hundreds of
unnecessary edges via per-target output-file-map.json mtime bumps.

Issue: #27748
2026-04-29 09:19:48 -04:00
Roman Lavrov 899f1496f8 Swift/Ninja: Fix emit-module-path clobbering on separate emit-module edge
Since commit b6367f723b (Swift/Ninja: Emit modules separately from
compilation, 2026-04-10) the compile edge still appends
-emit-module -emit-module-path when emitModuleSeparately is active,
duplicating the emit-module edge.  For targets with directory-style
module paths (CMP0195=NEW), this causes a file/directory conflict
that fails the build.

Guard -emit-module -emit-module-path on both the compile and
emit-module edges so they are not appended when the flags already
contain -emit-module-path (e.g. from the target's compile options).

Discovered building swift-syntax on Windows where the directory-style
path was overwritten by the flat path from the compile edge.

Issue: #27748
2026-04-27 18:57:47 -04:00
Roman Lavrov b6367f723b Swift/Ninja: Emit modules separately from compilation
Add policy CMP0215 to emit `.swiftmodule` from a dedicated `-emit-module`
build edge for importable Swift targets in the Ninja generator.
Downstream targets can begin compiling as soon as the module interface
is ready, overlapping with upstream object compilation and linking.

When CMP0215 is NEW and CMP0157 is NEW, separate module emission is
enabled by default.  The `Swift_SEPARATE_MODULE_EMISSION` target
property (initialized by the `CMAKE_Swift_SEPARATE_MODULE_EMISSION`
variable) can override this per target.

The compile edge still passes `-emit-module` so that swiftc continues
to produce `.swiftdoc`; only the `.swiftmodule` output moves to the new
edge.

Also fix swiftmodule dependency edges in cmNinjaNormalTargetGenerator
to use IsLanguageUsed instead of GetLinkerLanguage, so C/C++ targets
whose linker language propagated to Swift do not produce spurious
implicit dependencies.

Closes: #27748
2026-04-24 15:58:18 -04:00
Roman Lavrov 0f20ba5b68 Ninja: Swift: Extract helpers and reorder module flags
Extract SetupResponseFile and ExpandRuleCommands helpers from
WriteCompileRule to allow reuse by new rule types.

Reorder flag appending in WriteSwiftObjectBuildStatement so that
-module-name and -module-link-name precede -emit-module, preparing
for a separate emit-module edge that shares common flags.  Update
test regexes accordingly.

Issue: #27748
2026-04-24 10:17: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
Marc Chevrier bc7d8bd26f FILE_SET: Add INDEPENDENT_FILES property for Ninja order dependency control
Fixes: #25370
2026-04-12 15:00:03 +02:00
Marc Chevrier 5c5b68f44e FILE_SET: Add support for the SOURCES type
Fixes: #27550
2026-03-31 09:49:59 +02:00
Brad King 0e47cd8c7b Merge topic 'bmi-only-command-template'
7ebb5687ab cmGeneratorTarget: use typename for `flag`
4a4986d28a cxxmodules: support command templates for BMI compilation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11871
2026-03-27 07:36:26 -04:00
Ben Boeckel 4a4986d28a cxxmodules: support command templates for BMI compilation
Some compilers (Clang) warn when using their BMI-only flag with `-c`.
Support a complete template for BMI compilation rather than an
additional flag to support such toolchains.

Fixes: #27600
2026-03-26 13:20:19 -04:00
Brad King c68b587abe c++modules: Fully revert implementation of per-importer BMIs for 4.3
Since commit 5898c8d2e0 (cxxmodules: Generate per-importer BMIs for
native targets, 2025-12-29, v4.3.0-rc1~43^2~1) we use synthetic targets
to perform per-importer BMI-only compilation of modules even from
in-project targets.  However, our BMI-only compile lines are still
generated from the `CMAKE_CXX_COMPILE_OBJECT` rule variable, which
contains `-c` or equivalent.  Clang expects `-c` and `--precompile` to
be mutually exclusive, leading to warnings, or errors with `-Werror`.

Follow up commit e5b1a23f27 (c++modules: Revert partial implementation
of per-importer BMIs for 4.3, 2026-02-27, v4.3.0-rc2~9^2) by reverting
the rest of the implementation from the 4.3 release.  Work toward fixing
the implementation will proceed in post-4.3 development.

Issue: #25539
Issue: #27600
Issue: #27597
2026-03-24 11:13:05 -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
Brad King d32170a997 Merge topic 'c++modules-subdir-spaces'
443014b840 c++modules: Fix scanning with spaces in subdirectory name
2d262efd29 cmNinjaTargetGenerator: Factor out helper for shell path arguments

Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !11738
2026-02-26 09:17:24 -05:00
Brad King 443014b840 c++modules: Fix scanning with spaces in subdirectory name
If the path to a subdirectory inside the project has a space,
C++ module dependency scanning paths need quoting.

Fixes: #27647
2026-02-25 15:43:03 -05:00
Brad King 2d262efd29 cmNinjaTargetGenerator: Factor out helper for shell path arguments 2026-02-25 15:41:17 -05: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 c4c84ae0f7 cmFileSet: Enhance type management
Type management is now dynamic to ensure future support of user's types.
2026-02-19 17:03:45 +01:00
Daniel Tierney 5898c8d2e0 cxxmodules: Generate per-importer BMIs for native targets
C++ module importers may have specific usage requirements that differ from
other importers of the same module, potentially requiring separate Built Module
Interfaces (BMIs) for compatibility. CMake creates synthetic targets to
generate and link usage-specific BMIs. This change extends CMake's per-importer
BMI generation to native targets in addition to imported targets.
2026-02-09 14:16:17 -05:00
Ben Boeckel 366b25e62e ast-grep: simplify cmHasLiteral{Suf,Pre}fix with char literals 2025-11-20 12:14:14 -05: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
Alex Turbov 8de02a14c8 ci(pre-commit): version bump typos hook plus fix found typos 2025-10-23 21:14:25 +04:00
Martin Duffy 97adbc91fa instrumentation: Move target data into content files
Create a single place to store target data to prevent duplication.
This moves `targetType` and `targetLabels` out of the snippet files
and into a target map in the `cmakeContent` file referenced by each
snippet.

Fixes: #27244
2025-10-02 09:28:20 -04:00
Alex Turbov f100769d72 Add SKIP_LINTING target property and CMAKE_SKIP_LINTING variable
These offer target-wide settings to disable lints.

Closes: #27191
2025-09-09 09:56:35 -04:00
John Parent 851e07fda3 Ninja: support short object directories 2025-07-29 08:06:30 -04:00
Ben Boeckel dfba904178 Ninja: populate the TARGET_SUPPORT_DIR replacement variable 2025-07-28 12:01:27 -04:00
Bastien Montagne 3a9d56d2c7 Ninja: Add support for per-source JOB_POOL_COMPILE property
This commit allows to override a global or target-wide 'job pool'
property on a per-source basis.

It modifies the Ninja generator to first look into the source's
properties, and only use the target properties as a fallback.

The new `source` parameter to
`cmNinjaTargetGenerator::addPoolNinjaVariable` may be null, e.g. when
the function is called in context where there is no source (e.g. a
linking task).

Closes: #23994
2025-07-16 21:16:24 +02:00
Ben Boeckel a16566105b cmNinjaTargetGenerator: fix DependInfo.json generation location
Commit aafd771529 (cmNinjaTargetGenerator: use `GetObjectFileDir` where
possible, 2025-05-21) from !10812 accidentally converted the
`GetTargetDependInfoPath` from an always-absolute path to a
relative-for-ninja path. This works fine as everything ended up doing
`ConvertToNinjaPath` as necessary *except* the code which actually wrote
the file. That needs an absolute path in order to generate it in the
correct location.

Fixes: #26983
2025-06-09 21:58:32 +02:00
Ben Boeckel b82a74d918 generators: use GetSupportDirectory() in more places 2025-05-23 11:39:53 +02:00
Ben Boeckel aafd771529 cmNinjaTargetGenerator: use GetObjectFileDir where possible
Lots of code simplification.
2025-05-22 17:02:53 +02:00
Ben Boeckel ec85753502 cmNinjaTargetGenerator: convert linked target dirs to ninja paths 2025-05-22 17:02:53 +02:00
Ben Boeckel 557c44b93e cmStrCat: use character literals where possible
Found and replaced using the `cmstrcat-to-char-literal` rule for
`ast-grep`.
2025-05-15 19:12:04 +02:00
Ben Boeckel 23779057fd cmStrCat: combine neighboring arguments where possible
Found using the `cmstrcat-adjacent-literals` rule for `ast-grep`.
2025-05-15 19:11:41 +02:00
Kitware Robot 1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00