Commit Graph

408 Commits

Author SHA1 Message Date
Brad King
ba3ad7c9e3 Merge topic 'ninja-acc-target-comments'
0122e02293 Ninja: Add COMMENT to custom command and target descriptions
30fb5b1b22 Ninja: add COMMENT to build statement descriptions

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9484
2025-03-05 08:31:31 -05:00
Ben Boeckel
30fb5b1b22 Ninja: add COMMENT to build statement descriptions
This allows users to recognize that something more than the basic action
is happening.

See: https://groups.google.com/g/ninja-build/c/Tv4wu2IBMdo
Issue: #15461
2025-03-03 11:58:13 -05: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
Martin Duffy
9689155a05 instrumentation: Add Config value to snippet data 2025-02-09 12:29:09 -05:00
Kitware Robot
0b96ae1f6a Revise C++ coding style using clang-format with "east const"
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`, now with "east const" enforcement.
Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Issue: #26123
2025-01-23 13:09:50 -05:00
Martin Duffy
9d34069ca8 instrumentation: Add targetLabels field to link snippets
Adds a new data field `targetLabels` to link snippets which contains a list of
text labels from the LABELS target property.
2025-01-17 11:07:30 -05:00
Alex Turbov
bc8621d999
Fix: A lot of typos in code found by typos
Yet another great code spellchecker: https://github.com/crate-ci/typos/

(Will be added later as a `pre-commit` hook)
2025-01-12 18:49:34 +04:00
Brad King
129c87fb09 Merge topic 'fileapi-no-link-dependency-file'
1a04515a47 fileapi: Do not expose flags for linker-generated dependencies

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10061
2024-12-04 08:53:54 -05:00
Brad King
1a04515a47 fileapi: Do not expose flags for linker-generated dependencies
In commit 375e6fdbbe (Link step: use linker dependency linker file,
2023-04-19, v3.27.0-rc1~126^2) we added the `-Wl,--dependency-file,...`
flag for the Ninja generator in a code path shared with the file-api.
This flag is a build system implementation detail and should not be
exposed to file-api clients.  Move it to a Ninja-specific code path.

Fixes: #26498
2024-12-03 13:48:57 -05:00
Marc Chevrier
8bcf9c7a3e Add support of "LINKER:" prefix for artifact creation flags
The following variables now support the LINKER: prefix:
    * CMAKE_SHARED_LIBRARY_CREATE_<LANG>_FLAGS
    * CMAKE_SHARED_MODULE_CREATE_<LANG>_FLAGS
    * CMAKE_<LANG>_LINK_FLAGS
2024-11-04 17:08:03 +01:00
Marc Chevrier
2bd4c06c26 Refactoring cmRulePlaceHolderExpander: propagate cmBuildStep information 2024-11-04 17:08:02 +01:00
Aditya Vidyadhar Kamath
6c12e0758b Ninja: Fix AIX shared library archiving
Extend commit d27fe9dfba (AIX: Add option to archive shared libraries,
2024-06-18) to update the Ninja generator to support the new
`AIX_SHARED_LIBRARY_ARCHIVE` feature.

Fixes: #26332
2024-09-27 17:53:59 -04:00
Brad King
ad66be9943 cmNinjaTargetGenerator: Factor out helper to add depfile bindings 2024-09-12 12:24:48 -04:00
Aditya Vidyadhar Kamath
d27fe9dfba AIX: Add option to archive shared libraries
Add option `CMAKE_AIX_SHARED_LIBRARY_ARCHIVE`.

There will no versions for the shared objects when this option is used.

Closes: #26033
2024-07-17 11:52:09 -04:00
Dave Abrahams
5bb7f8a4dd Swift: Use per-config module file locations in multi-config generators
Place `.swiftmodule` files a subdirectory named after the configuration.

Fixes: #25864
Fixes: #25997

- Swift/RunCMakeTest.cmake:
  - CMP0157-OLD was enabled for Xcode, where it works.
  - A test was added that verifies .swiftmodule's are generated into
    separate directories with multi-config generators.

- Tests/SwiftOnly/CMakeLists.txt: tests were added that validate that
  cross-subdirectory module dependencies (via target_link_libraries)
  work.
2024-05-24 15:23:41 -07:00
Dave Abrahams
b2e042d77a cmGeneratorTarget: Adopt Swift-related methods from the Ninja generator
They will see more use as Swift bugs are fixed in the
Ninja Multi-Config generator.
2024-05-24 15:20:08 -07:00
Evan Wilde
a6a5c43300
Swift/Ninja: Add support for response files
Adding support for `CMAKE_NINJA_FORCE_RESPONSE_FILE` with Swift.

Issue: #25490
Fixes: #25563
2024-01-08 09:11:27 -08:00
Evan Wilde
9bed4f4d81
Swift/Ninja: Split compilation model
Splitting the Swift build into an object build and a separate link step,
instead of building and linking in one step. The immediate benefit is
LSP support because we are able to emit compile-commands for Swift files
now. Additionally, it is possible to specify flags to the compile step,
enabling folks to emit C and C++ headers from their Swift builds for
C/C++ interop, without needing custom commands. Eventually, this gives
us a path toward working object libraries.

Object Libraries:
 - Object libraries don't work today because CMake doesn't emit targets
   for object libraries into the Ninja build file.
 - tl;dr: Object libraries work if they aren't WMO. Still need work to
   make WMO'd object libraries work.

   Object libraries still don't completely work with this patch because,
   while we emit the targets, the `TARGET_OBJECTS` generator expression
   expansion has a separate mechanism for determining what the names of
   the objects are based on the input source files, so targets that
   depend on an object library built with a whole-module optimization
   will depend on objects based on the name of the source file instead
   of the actual emitted object file.

These features require being able to accurately model wholemodule builds
though, because we actually need to track object files and WMO affects
what objects are emitted. For that, we require CMP0157 use the NEW
policy. When it's OLD, we have to fall back on the old behavior and
cannot provide object libraries or the compile-commands for LSP.

Issue: #25308
2023-12-15 05:51:13 -08:00
Marc Chevrier
96a953b1ed Add options to specify linker tool
Offer the capability, through variable `CMAKE_LINKER_TYPE`, as well as
the target property `LINKER_TYPE` to specify which linker must be used.

The implementation of this capability is specified by variables specific
to the language and linker type: `CMAKE_<LANG>_USING_LINKER_<TYPE>`.
Some definitions are provided as part of `CMake`.

For example, to select the `LLVM` linker rather than the standard one,
the type `LLD` should be specified through the variable `CMAKE_LINKER_TYPE`.
And, on `Apple`, `Linux` and some environments on `Windows`, the variable
`CMAKE_<LANG>_USING_LINKER_LLD` has value `-fuse-ld=lld`. And for `Windows`
environments  based on `MSVC`, where the linker is used directly, the tool
`lld-link.exe` will be used rather than `link.exe`.

Fixes: #19174, #24254, #24990
2023-10-13 11:52:35 +02:00
Ben Boeckel
9b9ec70b54 Ninja: generate scanning and build rules for C++20 module synthetic targets 2023-08-17 14:42:54 -04:00
Craig Scott
84eae7aeda
OPTIMIZE_DEPENDENCIES: Skip order-only deps for non-linking targets
Fixes: #21517
2023-08-10 09:17:56 +10:00
Brad King
241ee252ce IWYU: Update for Debian 12 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 12.
2023-07-28 09:14:08 -04:00
Marc Chevrier
3c685a578a LINK_OPTIONS: ensure correct dollar escaping
Ensure correct escaping for Ninja and Makefile generators.

Fixes: #25049
2023-07-17 15:55:58 +02:00
Marc Chevrier
72faa9a017 CreateRulePlaceholderExpander(): enhance memory management
This method returns now a std::unique_ptr instance rather than a raw pointer.
2023-05-04 19:34:36 +02:00
Marc Chevrier
375e6fdbbe Link step: use linker dependency linker file
Based on work done by @ben.boeckel (!8051)

Fixes: #22217
2023-05-03 17:08:07 +02:00
Marc Chevrier
241304190f CMake code rely on cmList class for CMake lists management (part. 2) 2023-04-29 09:54:31 +02:00
Brad King
827d5b75d4 Merge topic 'CMake-uses-cmList-class'
e08ba229ee CMake code rely on cmList class for CMake lists management (part. 1)
51b0d45d91 cmExpandList and cmExpandLists rely on cmList class

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8423
2023-04-25 09:52:40 -04:00
Marc Chevrier
e08ba229ee CMake code rely on cmList class for CMake lists management (part. 1) 2023-04-24 10:41:10 +02:00
Matthieu Ribiere
e0364eb20d Add support of CMAKE_<LANG>_USE_RESPONSE_FILE_FOR_LIBRARIES variable.
We add a function in cmNinjaNormalTargetGenerator.cxx to check for the state of the option (as it was done for Makefile). This will be checked to add or not the `$LINK_PATH` and `$LINK_LIBRARIES` to the Ninja file.
The default behavior is adding those libraries.
Fixes: #24681
2023-04-13 11:10:00 +02:00
Marc Chevrier
ede33f30cf Apple: Handle generation and comsuption of text-based stubs (.tbd files)
Fixes: #24123
2023-03-01 12:23:28 +01:00
Kyle Edwards
78cf427157 RULE_LAUNCH_*: Add support for generator expressions 2023-02-03 11:23:32 -05:00
Evan Wilde
bf3a8ef6d5
Ninja: Swift: Add dependency edge to swiftmodule file
Swiftmodules act like headers for Swift, but are generated by the
compiler while building the module. Unlike headerfiles in a pure C/C++
world, where the compiler generates the appropriate depfile. We don't
have We're
already adding the swiftmodule as an output from swift-linked targets,
but aren't using that on inputs.

This dependency edge is most important for static libraries in
incremental builds. Suppose we have two static libraries, A, and B, and
an executable E. B "links" against A, and E links against B. In a C/C++
environment, the library link dependency edge will run from E to both A
and B, but there won't be an edge from B to A. If A is changed, the only
way this should affect B is if the public interface changes, in which
case, the headers will also change. The dep file contains the header
link, so Ninja will rebuild B when appropriate. With Swift in an
incremental build, B sees the order-dependency on A, but A already
exists. If A is changed in a way that changes the public interface, the
swiftmodule will change, but since we don't track it, we don't rebuild
B, resulting in the final executable to fail to link.
2023-01-21 10:37:09 -08:00
Evan Wilde
d0b469b7e0
Ninja: NFC: refactor swift module name computations
In order to handle determining the swiftmodule name to add to the ninja
dependency graph, we'll need to be able to compute the swiftmodule name
for the dependency target, not just the current target. This patch
refactors the computation of the module name out of inaccessible lambdas
and into static functions that can compute the swiftmodule name from the
generator and the target.
2023-01-21 10:37:09 -08:00
Brad King
1d52007564 Merge topic 'ninja-swift-exported-executables'
4165eb3d0b Ninja: Emit swiftmodule from executable with exports

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8048
2023-01-20 09:36:00 -05:00
Evan Wilde
4165eb3d0b
Ninja: Emit swiftmodule from executable with exports
This patch adds support for tracking the swiftmodules for executables
exporting symbols.

This fixes a bug in the earlier implementation around emitting the
swiftmodule. Previously, the code would use
`CMAKE_EXE_EXPORTS_Swift_FLAG` to inject the `-emit-module`, and module
path information into the `CMAKE_Swift_LINK_EXECUTABLE` rule. Because
Swift skips the build step and only runs during the link phase, these
flags were injected in `cmNinjaNormalTargetGenerator::ComputeLinkCmd`
instead of `cmLocalGenerator::GetTargetFlags` where it is done normally.

Unfortunately, injecting in `ComputeLinkCmd` didn't do anything because
we have a `linkCmd` so `ComputeLinkCmd` exits early, before the
EXE_EXPORT flags get added to the link command.

Instead of playing with that flag, CMake checks
`CMAKE_Swift_LINK_EXECUTABLE_WITH_EXPORTS` and uses that as the link
rule if it exists and falls back on `CMAKE_Swift_LINK_EXECUTABLE`. I've
defined that variable in terms of `CMAKE_Swift_LINK_EXECUTABLE` with the
necessary additional flags for emitting the swift module instead. This
has the same end effect as the desired behavior, but simplifies things a
bit.

Since we're generating the swiftmodule for executables with exports,
I've also updated the dependency graph to include the swiftmodule as an
output in the build dependency graph if the executable has exports.

Tests updated:
 - RunCMake/NoWorkToDo:
   Ensure that the build graph does not result in unnecessary rebuilds
   with exporting executables.

 - SwiftOnly:
   Ensure that we can consume functions defined in the executable by a
   library getting linked into said executable.
2023-01-19 11:49:24 -08:00
Pierre Testart
a525f5f1bf cmGeneratorTarget: Cache full name components
Cache the result of cmGeneratorTarget::GetFullNameInternalComponents
to improve performance.
2023-01-18 09:12:17 -05:00
Ben Boeckel
a971fcfde7 cmNinjaNormalTargetGenerator: use cmStrCat 2022-11-21 17:12:18 -05:00
Ben Boeckel
b7509d6bf8 cmNinjaNormalTargetGenerator: fix grammar in verbose comment 2022-11-21 17:09:33 -05:00
Evan Wilde
38c8807c5a Ninja: Avoid re-linking a Swift executable on every build
Swift doesn't emit swiftmodules for executables, so we shouldn't put it
in dependency graph.  Ninja sees the "missing" dependency and always
tries to rebuild/re-link the target.
2022-11-17 13:05:22 -05:00
Evan Wilde
e88509d0e8
Swift: Omit output-file-map when used as a linker
Swift is used as the linker for non-swift files because it needs to pull
files like swiftrt.o in when swift symbols are present to ensure that
the swift runtime is linked.

The swift driver uses clang as the underlying linker, which pulls in
crtbegin.o and friends when appropriate, so using Swift as a linker for
C/C++ libraries is fine.

The output-file-map was getting passed to all Swift invocations,
regardless of whether or not we generated one. This patch changes it so
that we only include the output-file-map in the Swift compiler
invocation if we have actually generated the file.
2022-10-28 16:44:26 -07:00
Evan Wilde
a9509cec7e Ninja: Fix mixed Swift/CXX library target generation
With how things were before, mixed Swift/C++ libraries would result in a
broken ninja file.  `cpp.cpp.o` was emitted by the compiler, but was
also being included in the `linkBuild.Outputs` list, so it was being
emitted by multiple targets.

The fix checks that the source language is Swift before adding it to the
list of additional outputs. If it is Swift, this isn't a problem. If it
isn't Swift, we don't include it in the list of outputs.

On the other side, the C++ file was also being passed as a source file,
which the Swift compiler can't compile. So we add the C++ object file as
an explicit dependency and the object file is then added to the list of
Swift sources.
2022-09-16 10:41:39 -04:00
Robert Maynard
6eda92d037 remove unused variable 2022-07-13 10:25:10 -04:00
Brad King
6cc417586e Ninja: Avoid duplicating /DEF: linker flag with MSVC tools
In commit 9a0d5a828a (Ninja: add /DEF: flag to linker call, 2012-03-10,
v2.8.8~22^2~7) the logic should have been added to `GetTargetFlags` in
place of the older logic in that method from commit 7cef36c628 (ENH: add
the ability to generate custom commands for a language that is not
supported by an IDE, 2004-10-21, v2.4.0~2655).

Fixes: #23570
2022-05-31 15:40:58 -04:00
Brad King
39dba8a244 cmLocalGenerator: Adopt AppendModuleDefinitionFlag method
Migrate from `cmCommonTargetGenerator::AddModuleDefinitionFlag`.
2022-05-31 15:40:35 -04:00
Robert Maynard
627ef4c1d0 Provide guidance when trying to use non-enabled language
Fixes #23463
2022-05-04 09:33:35 -04:00
Raul Tambre
4707ecbe6f CUDA: Support CMP0105 on Clang
Add link flags during the "device compile" step.

Enabled the relevant tests. The disable reasons regarding separable compilation
were outdated and the actual failure case was device link flags support.
2021-11-08 21:26:00 +02:00
Raul Tambre
15fde4c420 CUDA: Use local shorthands for variables in Clang device link code
Helps reduce wrapping of lines making code more readable.
2021-11-07 21:28:08 +02:00
Raul Tambre
cf7e68087d CUDA: Avoid unnecessary allocation and GetLinkLanguage()
There's no reason to allocate the cmNinjaLinkLineDeviceComputer on the heap.
We can also assume the link language as CUDA in cmLocalGenerator::GetDeviceLinkFlags().
2021-11-07 21:28:08 +02:00
Raul Tambre
5b0693411e CUDA: Ignore USE_WATCOM_QUOTE for device link rules
It's useless as the Watcom compiler isn't supported by NVCC.
2021-11-07 21:28:08 +02:00
Brad King
73b84db62d Ninja: Fix creation of Windows import library directory
Call `EnsureParentDirectoryExists` with our internal representation
of the path, not the representation quoted/encoded for Ninja.

Fixes: #22841
2021-11-03 10:08:48 -04:00