1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-06-16 08:53:56 +08:00

244 Commits

Author SHA1 Message Date
scivision
6ebf0e1a46 Ninja: Use absolute path to COMSPEC if possible
If the COMSPEC is set to an absolute path, use it instead of just
`cmd.exe`.  This avoids searching for the tool in the current working
directory and the `PATH`.  If COMSPEC is not set to an absolute path,
fall back to the existing behavior.

Issue: #18350
2023-09-11 08:47:09 -04: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
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
24a3e5cda0 cmLocalGenerator::MayBeRelativeToWorkDir: take care of all cases 2023-05-02 17:47:04 +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
Marc Chevrier
e08ba229ee CMake code rely on cmList class for CMake lists management (part. 1) 2023-04-24 10:41:10 +02:00
Nicolas van Kempen
426f3295f6 Ninja: Use more efficient data structures to collect outputs 2023-03-28 17:53:18 -04:00
Brad King
ca8c171021 Merge topic 'clang-windows-cxx-modules'
1b7c26da49 Ninja: Wrap rules using '>' shell redirection with 'cmd /C' on Windows
ffd8537acf Clang: Record Clang 16.0 C++ modules flags only for GNU-like front-end
6013227230 cmGlobalNinjaGenerator: Use forward slashes in clang modmap format on Windows
d9d74b5e8a cmDyndepCollation: Drop outdated mentions of CXX_MODULE_INTERNAL_PARTITIONS
edab56d29a cmLocalNinjaGenerator: De-duplicate condition for using 'cmd /C' on Windows
8ebe3f92b3 cmGlobalNinjaGenerator: Detect GNU-like command-line for dyndep collator
f3ca199c9b cmGlobalNinjaGenerator: Factor out GNU-like command-line detection on Windows
f79817fcf0 cmCxxModuleMapper: Use value semantics in path conversion callback
...

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8346
2023-03-21 08:58:43 -04:00
Brad King
1b7c26da49 Ninja: Wrap rules using '>' shell redirection with 'cmd /C' on Windows
This is needed for the clang-scan-deps rule added by commit 0e21e55fc5
(Clang: Record Clang 16.0 C++ modules flags only for GNU-like front-end,
2023-03-16).

Fixes: #24611
2023-03-20 13:13:30 -04:00
Brad King
edab56d29a cmLocalNinjaGenerator: De-duplicate condition for using 'cmd /C' on Windows 2023-03-18 11:52:41 -04:00
Abdelmaged Khalifa
082ccd7530 add_custom_command: Add DEPENDS_EXPLICIT_ONLY option for Ninja
Add option `DEPENDS_EXPLICIT_ONLY` to `add_custom_command` to indicate
that implicit dependencies coming from users of the output are not
needed, and only consider dependencies explicitly specified in the
custom command.

Fixes: #17097
2023-02-14 08:56:59 -05:00
Kyle Edwards
09d7f947d6 cmGeneratorExpression: Require cmake instance 2022-11-11 12:29:41 -05:00
Brad King
2e5af30ce0 Ninja: Match showIncludes dependencies using console output code page
Generalize the fix from commit 37a279f8d1 (Ninja: Write msvc_deps_prefix
as UTF-8 when console codepage is UTF-8, 2020-07-31, v3.19.0-rc1~349^2).
`cl /showIncludes` output is encoded using the console output code page,
so this is the byte sequence that Ninja must use to match its lines.

Fixes: #24068
2022-10-30 08:29:55 -04:00
Brad King
94a58e502b cmLocalGenerator: Remove unused IncludePathStyle infrastructure
It is unused since commit c564a3e3ff (Ninja: Always compile sources
using absolute paths, 2021-05-19, v3.21.0-rc1~129^2), which left
behind a FIXME comment to eventually remove it.
2021-12-01 11:33:30 -05:00
Brad King
3c855b167f Merge topic 'fix-ifdef-windows'
40e73c5ac4 Source: Fix typo in _WIN32 preprocessor checks

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6631
2021-10-18 09:29:20 -04:00
Brad King
40e73c5ac4 Source: Fix typo in _WIN32 preprocessor checks
Since CMake's default compiler flags with MSVC include `-DWIN32` for
historical reasons, a few preprocessor conditions were accidentally
checking for `WIN32` instead of `_WIN32`.  The corresponding blocks
were left out when compiling official binaries for `cmake.org` because
we hard-code compiler flags without `-DWIN32`.

Fixes: #22764
2021-10-15 11:39:04 -04:00
Sean McBride
37859e3244 Source: Fix clang -Wimplicit-fallthrough warnings 2021-09-28 10:53:54 -04:00
Marc Chevrier
cc56dc7468 Rename cmProp in cmValue 2021-09-21 17:14:04 +02:00
NAKAMURA Takumi
61a737b088 cmGlobalNinjaGenerator: Rename SupportsConsolePool to SupportsDirectConsole
Use a name that is not ninja-specific.
2021-06-29 10:36:03 -04:00
Brad King
a6de8ec51b cmTransformDepfile: Make directory for transformed depfile automatically 2021-06-09 10:09:58 -04:00
Brad King
c564a3e3ff Ninja: Always compile sources using absolute paths
The Ninja generator traditionally referenced source files and include
directories using paths relative to the build directory if they could be
expressed without a `../` sequence that leaves the build and source
directories.  For example, when using a `build/` directory inside the
source tree, sources would be compiled as `-c ../src.c` and include
directories would be referenced as `-I ../include`.  This approach
matches the traditional Ninja convention of using relative paths
whenever possible, but has undesirable side effects such as:

* Compiler diagnostic messages may not use absolute paths, making it
  harder for IDEs/editors to find the referenced sources or headers.

* Debug symbols may not use absolute paths, making it harder for
  debuggers to find the referenced sources or headers.

* Different results depending on the path to the build tree relative
  to the source tree.

* Inconsistent with the Makefile generators, which use absolute paths.

Switch to always using absolute paths to reference source files and
include directories on compiler command lines.  While alternative
solutions for diagnostic messages and debug symbols may exist with
specific tooling, this is the simplest and most consistent approach.

Note that a previous attempt to do this in commit 955c2a630a (Ninja: Use
full path for all source files, 2016-08-05, v3.7.0-rc1~275^2) was
reverted by commit 666ad1df2d (Revert "Ninja: Use full path for all
source files", 2017-02-24, v3.8.0-rc2~9^2) due to problems hooking up
depfile dependencies on generated files.  This time, the changes in
commit 2725ecff38 (Ninja: Handle depfiles with absolute paths to
generated files, 2021-05-19) should avoid those problems.

Fixes: #13894, #17450
2021-05-25 10:48:26 -04:00
Brad King
51116c3ea9 cmLocalNinjaGenerator: Remove unnecessary CollapseFullPath call
`ConvertToIncludeReference` is only called with absolute paths.
One branch already assumed this.
2021-05-25 10:48:25 -04:00
Brad King
2725ecff38 Ninja: Handle depfiles with absolute paths to generated files
Ninja treats every (normalized) path as its own node.  It does not
recognize `/abs/path/to/file` in a depfile as matching `path/to/file`
even when `build.ninja` and the working directory are in `/abs/`.
See Ninja Issue 1251.  In cases where we pass absolute paths to the
compiler, it will write a depfile containing absolute paths.  If those
files are generated in the build tree by custom commands, `build.ninja`
references them by relative path in build statement outputs, so Ninja
does not hook up the dependency and rebuild the project correctly.

Add infrastructure to work around this problem by adding implicit
outputs to custom command build statements that reference the main
outputs by absolute path.  Use a `${cmake_ninja_workdir}` placeholder
to avoid repeating the base path.  For example:

    build out.txt | ${cmake_ninja_workdir}out.txt: CUSTOM_COMMAND ...

Ninja will create two nodes for the output file, one with a relative
path and one with an absolute path.  A depfile may then mention either
form of the path and Ninja will hook up the dependency.  Unfortunately
Ninja will also stat the file twice.

Issue: #13894
Fixes: #21865
2021-05-19 13:28:14 -04:00
Brad King
68e5f92cad cmGlobalNinjaGenerator: Factor out custom command output collection
De-duplicate code paths calling ConvertToNinjaPath and
SeenCustomCommandOutput on custom command outputs and custom target
byproducts.
2021-05-19 12:07:58 -04:00
Brad King
c5195193d3 cmGlobalNinjaGenerator: Reduce string copies in WriteCustomCommandBuild
Re-order arguments to group those with similar roles.
Use move semantics to avoid copying vectors of strings.
2021-05-19 12:07:58 -04:00
Brad King
ceb82752ef cmLocalNinjaGenerator: Use variable for main custom command output path 2021-05-19 12:07:58 -04:00
Brad King
d346805e41 cmLocalCommonGenerator: Select work directory semantically 2021-05-13 12:48:22 -04:00
Brad King
15fa320071 cmLocalGenerator: Factor out relative path conversion helpers
Most calls to `MaybeConvertToRelativePath` use one of our common work
directories (e.g. top of the build tree) as the local path.  Add helpers
for each of the common cases to simplify and clarify call sites.
2021-05-13 12:47:25 -04:00
Brad King
4419b944fd Merge topic 'ninja-multi-long-command-line-config'
ad08f93ee4 Ninja Multi-Config: Split long command lines by config

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6067
2021-05-03 10:53:50 -04:00
Kyle Edwards
ad08f93ee4 Ninja Multi-Config: Split long command lines by config
Fixes: #22123
2021-04-30 14:46:21 -04:00
Marc Chevrier
0c47b91fcc Genex: add_custom_command: DEPFILE supports genex
This facility is very useful for 'Ninja Multi-Config' and required
as well for future support of DEPFILE in 'Xcode' and 'Visual Studio'
generators (#20286).
2021-04-12 13:06:49 +02:00
Brad King
efcdec9a19 Merge topic 'nmc-cc-no-output'
6dd89529e8 Ninja Multi-Config: Fix crash on custom command config with no output
e21a80e97d Tests: Teach RunCMake to ignore incidental 'Recompacting log' ninja output

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kyle Edwards <kyle.edwards@kitware.com>
Merge-request: !5950
2021-03-30 09:50:48 -04:00
Brad King
6dd89529e8 Ninja Multi-Config: Fix crash on custom command config with no output
With generator expressions in a custom command's `OUTPUT` and
`BYPRODUCTS`, it is possible to have no outputs at all for a particular
configuration.  Generate no rule in this case.

Fixes: #21989
2021-03-29 09:56:43 -04:00
Brad King
40b806ee96 Merge topic 'ninja-multi-long-custom-command'
3b864b2583 Ninja Multi-Config: Include configs in long CC scripts

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5941
2021-03-26 09:23:19 -04:00
Kyle Edwards
3b864b2583 Ninja Multi-Config: Include configs in long CC scripts
Fixes: #21973
2021-03-25 13:18:47 -04:00
Brad King
f23aa1c120 Merge topic 'ninja-utf8'
9af6e2e7b2 Ninja: Use new wincodepage tool to determine encoding

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5860
2021-03-10 11:24:39 -05:00
Kyle Edwards
9af6e2e7b2 Ninja: Use new wincodepage tool to determine encoding
Ninja 1.11 and later uses UTF-8 on Windows when possible, and
includes a tool that reports the code page in use. Use this tool
to determine what encoding to write the Ninja files in.

Fixes: #21866
2021-03-09 11:09:24 -05:00
Brad King
a133a583d4 cmLocalGenerator: Clarify GetIncludeFlags signature
Make the `config` argument non-optional so all callers must be explicit.
Convert the path style argument to an enumeration to make its role clear
at call sites.

The path style argument is implemented by `ConvertToIncludeReference`,
which was introduced with the Ninja generator by commit 5b114c9bee
(Introduce a cmLocalGenerator::ConvertToIncludeReference function,
2011-09-07, v2.8.7~187^2~4).  Its only purpose is to allow the Ninja
generator to use relative paths in `-I` flags.  Add a comment explaining
this role.
2021-02-25 13:24:45 -05:00
Kyle Edwards
3a95503512 Ninja: Use CMP0116 status recorded at time of custom command's creation 2021-02-23 09:14:31 -05:00
Ben Boeckel
ca505718f4 clang-tidy: fix readability-redundant-string-init warnings 2021-01-27 08:45:45 -05:00
Kyle Edwards
98805a11ce Ninja Multi-Config: Run POST_BUILD when BYPRODUCTS don't overlap
Fixes: #21252
2021-01-07 11:26:17 -05:00
Shannon Booth
d43f4692e0 Ninja: Omit custom commands with an empty COMMAND
Fixes: #21063
2020-12-23 09:59:03 -05:00
Kyle Edwards
dcf9f4d2f7 Ninja Multi-Config: Add support for cross-config custom commands
Co-Author: Brad King <brad.king@kitware.com>
2020-12-15 07:01:21 -05:00
Brad King
7b64b0cd5a cmLocalGenerator: Refactor custom command generator construction
Add support for constructing and using multiple generators for one
custom command.  cmGeneratorTarget contains a code path that needs this
behavior when used with Ninja but not other generators, so use virtual
dispatch through cmLocalGenerator.
2020-12-15 07:00:52 -05:00
Brad King
84fecbf214 cmLocalNinjaGenerator: Remove leftover local debugging comment 2020-10-27 14:58:15 -04:00
Kyle Edwards
146e1e6ba1 Ninja: Transform DEPFILEs with policy CMP0116
Fixes: #21267
2020-10-13 10:19:46 -04:00
Vitaly Stakhovsky
1380b43764 Refactor: Use cmToCStr() 2020-09-03 11:36:54 -04:00
Vitaly Stakhovsky
11425041f0 cmMakefile::GetDefinition: return cmProp 2020-09-02 07:27:32 -04:00
Ben McMorran
37a279f8d1 Ninja: Write msvc_deps_prefix as UTF-8 when console codepage is UTF-8 2020-08-06 23:36:03 -07:00