Commit Graph

203 Commits

Author SHA1 Message Date
Brad King
16e24748c5 Ninja Multi-Config: Fix cross-config custom command dependency tracing
Process `CMAKE_CROSS_CONFIGS` and friends to properly configure the
generator for cross-config behavior before custom command dependency
tracing.
2021-11-04 12:23:35 -04:00
NAKAMURA Takumi
51bf4094fb Ninja: Use ccmake for edit_cache
If `ninja` is new enough to support the console pool, and `ccmake` is
available, use it for `edit_cache`.
2021-06-29 11:07:42 -04:00
NAKAMURA Takumi
23af78bb78 cmGlobalCommonGenerator: Adopt GetEditCacheTargetName
The implementation is the same for both Makefile and Ninja generators.
2021-06-29 10:39:15 -04:00
NAKAMURA Takumi
1db4d74628 cmGlobalCommonGenerator: Add SupportsDirectConsole
Default to `true` since this is used by Makefile generators.
The Ninja generator already overrides it to use a version check.
2021-06-29 10:37:16 -04: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
18408c0b88 cmGlobalNinjaGenerator: Add helper to compute absolute paths for build.ninja 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
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
d8f3e68ca9 Ninja Multi-Config: Enable relink diagnostic message
We already have a message for the "Ninja" generator, but it applies
to the "Ninja Multi-Config" generator too.
2021-02-03 11:35:31 -05:00
Ben Boeckel
b3b6ede6a1 clang-tidy: fix readability-redundant-access-specifiers warnings 2021-01-27 08:45:45 -05:00
Brad King
05f4248e3d Merge topic 'cpp-modules'
39cbbb59a5 ninja: add experimental infrastructure to generate gcc-format modmap files
791b4d26d6 ninja: add experimental infrastructure to generate modmap files with dyndep
4b23359117 ninja: Add experimental infrastructure for C++20 module dependency scanning
f814d3b3c6 cmNinjaTargetGenerator: use $OBJ_FILE for the object
b0fc2993e1 Treat the '.mpp' file extension as C++ code
988f997100 cmScanDepFormat: Fix name of our internal tool in parse errors
dacd93a2db ninja: De-duplicate version numbers required for ninja features
533386ca29 cmStandardLevelResolver: Factor out helper to capture stoi exceptions

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel <ben.boeckel@kitware.com>
Acked-by: Robert Maynard <robert.maynard@kitware.com>
Acked-by: Shannon Booth <shannon.ml.booth@gmail.com>
Merge-request: !5562
2021-01-07 08:26:28 -05:00
Ben Boeckel
791b4d26d6 ninja: add experimental infrastructure to generate modmap files with dyndep
The scan step may need to output additional information for the
compiler, not just the build tool. The modmap is assumed to be beside
the object output. Additional refactoring may open up a channel to
inform per-source paths to the dyndep rule in the future, but is not
done here.
2021-01-05 09:35:10 -05:00
Brad King
4b23359117 ninja: Add experimental infrastructure for C++20 module dependency scanning
Optionally enable this infrastructure through an undocumented
`CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP` variable.  Currently this is
experimental and intended for use by compiler writers to implement their
scanning tools.  Warn as such when the feature is activated.  Later when
compilers provide the needed scanning tools we can enable this variable
from our corresponding compiler information modules.  It is never meant
to be set by project code.

When enabled, generate a build graph similar to what we use for Fortran
module dependencies.  There are some differences needed because we can
scan dependencies without explicit preprocessing, and can directly
compile the original source afterward.

Co-Author: Ben Boeckel <ben.boeckel@kitware.com>
2021-01-05 09:34:55 -05:00
Oleksandr Koval
209daa20b2 Code style: add missed explicit 'this->'
CMake uses explicit 'this->' style. Using custom clang-tidy check we can
detect and fix places where 'this->' was missed.
2021-01-05 14:32:36 +02:00
Brad King
34469a4f71 Merge topic 'custom-command-output-genex-nmc'
1526ae3aba Tests: Add cases for Ninja Multi-Config cross-config custom commands
dcf9f4d2f7 Ninja Multi-Config: Add support for cross-config custom commands
15467f12f7 cmLocalGenerator: Adopt custom target 'force' output name generation
7b64b0cd5a cmLocalGenerator: Refactor custom command generator construction
d29da8ed3e cmMakefile: Simplify custom target 'force' output name generation
2b1cc175ee Help: Clarify version adding add_custom_{command,target} OUTPUT genex support

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5612
2020-12-16 06:20:39 -05:00
Brad King
b485e86363 Merge topic 'ninja-no-cleandead'
1144d25094 Merge branch 'backport-ninja-no-cleandead' into ninja-no-cleandead
73a961eaba Ninja: Remove cleandead on regeneration

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5614
2020-12-15 07:36:07 -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
1144d25094 Merge branch 'backport-ninja-no-cleandead' into ninja-no-cleandead 2020-12-14 10:14:19 -05:00
Brad King
73a961eaba Ninja: Remove cleandead on regeneration
Remove the `cleandead` tool invocation added by commit fb18215904
(Ninja: clean ninja metadata once generated, 2019-05-13,
v3.17.0-rc1~207^2).  The tool deletes files that were not previously
deleted by regenerating the build system.  Also, there are use cases
where no-longer-generated files should not be removed, such as Qt's TS
files.

Fixes: #21549
2020-12-14 10:08:14 -05:00
Brad King
5d49943504 Merge topic 'ninja-regen-metadata'
73d1c78bf4 ci: update to use ninja 1.10.2
11f4259362 Ninja: Clean metadata after regen during build on Windows with 1.10.2+

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5555
2020-12-01 09:29:12 -05:00
Brad King
11f4259362 Ninja: Clean metadata after regen during build on Windows with 1.10.2+
Ninja 1.10.2 fixes support for `generator = 1` rules that run metadata
update commands during regeneration while a build is running.  Update
the condition added by commit ccaa0bccc4 (Ninja: Do not clean metadata
when re-generating inside a running build, 2020-01-27,
v3.17.0-rc1~73^2) to remove our workaround when Ninja is new enough.

Fixes: #20274
2020-11-30 14:57:48 -05:00
Brad King
5e3b0aa9b2 Merge topic 'ninja-cleandead-no-dyndep'
c5011399c5 Ninja: Avoid cleandead with dyndep bindings for Fortran module dependencies

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5490
2020-11-11 09:34:17 -05:00
Brad King
c5011399c5 Ninja: Avoid cleandead with dyndep bindings for Fortran module dependencies
The Ninja `cleandead` tool does not account for implicit outputs
discovered by `dyndep` bindings and can remove Fortran `.mod` files that
are still needed.  Disable the `cleandead` step when using `dyndep`
bindings.

Fixes: #21406
2020-11-10 15:16:28 -05:00
Cengizhan Pasaoglu
bd705788f6 Constify some code as suggested by clang-tidy 2020-10-20 00:04:04 +03:00
Brad King
c555959717 Merge topic 'ninja-depfile-transformation'
146e1e6ba1 Ninja: Transform DEPFILEs with policy CMP0116
596439b1bb cmCustomCommandGenerator: Add option to transform depfile
b2c14bc774 cmake -E: Add cmake_transform_depfile internal command
946adadd40 cmGccDepfileReader: Rework helper code

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5325
2020-10-14 11:49:51 -04:00
Kyle Edwards
297ab15bf6 Ninja Multi-Config: Read configuration variables as normal variables
Early versions of the Ninja Multi-Config generator required
CMAKE_CONFIGURATION_TYPES and friends to be cache variables in order
to support selecting the default config in cmake(1) --build. The
behavior of cmake(1) --build has since been updated to no longer
require this, and requiring these variables to be cache variables is
inconsistent with the other generators.

Read the variables as normal CMake variables like the other generators.
This does not require a policy, since the only scenario where this would
cause a breakage is one where the cache variable and the CMake variable
are explicitly set to different values, which doesn't make sense to do
anyway.
2020-10-13 10:52:02 -04:00
Kyle Edwards
146e1e6ba1 Ninja: Transform DEPFILEs with policy CMP0116
Fixes: #21267
2020-10-13 10:19:46 -04:00
Kitware Robot
bdca8b01d2 Modernize: Use #pragma once in all header files
#pragma once is a widely supported compiler pragma, even though it is
not part of the C++ standard. Many of the issues keeping #pragma once
from being standardized (distributed filesystems, build farms, hard
links, etc.) do not apply to CMake - it is easy to build CMake on a
single machine. CMake also does not install any header files which can
be consumed by other projects (though cmCPluginAPI.h has been
deliberately omitted from this conversion in case anyone is still using
it.) Finally, #pragma once has been required to build CMake since at
least August 2017 (7f29bbe6 enabled server mode unconditionally, which
had been using #pragma once since September 2016 (b13d3e0d)). The fact
that we now require C++11 filters out old compilers, and it is unlikely
that there is a compiler which supports C++11 but does not support
#pragma once.
2020-09-03 09:30:21 -04:00
Robert Maynard
e783bf8aa6 ISPC: Support ISPC header generation byproducts and parallel builds 2020-08-28 11:21:31 -04:00
Kyle Edwards
cfe2dc4721 Ninja: Remove parameter default for cmNinjaTargetDepends 2020-07-24 11:49:59 -04:00
Kyle Edwards
dddb4f02f7 Ninja Multi-Config: Make "install" targets depend on default configs
And add an "install:all" target.

Fixes: #20713
2020-05-22 13:15:50 -04:00
Kyle Edwards
b45976fe10 Ninja: Remove config suffix from order-only target
Fixes: #20621
2020-04-23 12:46:58 -04:00
Kyle Edwards
9590c3a400 Generator: Don't allow Ninja Multi-Config variables on other generators
We may want to enable these variables later on with specific
semantics. To avoid breaking backwards compatibility, make it an
error to use them for now.
2020-02-27 09:23:08 -05:00
Kyle Edwards
46c836644d Ninja Multi-Config: Fix issue with "all" in CMAKE_NMC_DEFAULT_CONFIGS
Prior to this fix, CMAKE_NMC_DEFAULT_CONFIGS would inherit "all" from
the union of CMAKE_NMC_DEFAULT_BUILD_FILE_CONFIG and
CMAKE_NMC_CROSS_CONFIGS. This is inconsistent with the behavior of the
"all" target signifying CMAKE_NMC_CROSS_CONFIGS. Update "all" in
CMAKE_NMC_DEFAULT_CONFIGS to inherit only from CMAKE_NMC_CROSS_CONFIGS.
2020-02-11 10:49:54 -05:00
Kyle Edwards
67102d3252 Ninja Multi-Config: Add support for DEPFILE option in add_custom_command()
And give other generators a path forward to add support in the future.
2020-02-07 14:18:54 -05:00
Kyle Edwards
16a4ba5b31 Ninja Multi-Config: Use build.ninja if cmake --build has no --config
If cmake --build is called with no --config argument, and a
build.ninja file is available, use that instead of defaulting to the
Debug config.
2020-02-04 14:13:07 -05:00
Kyle Edwards
b966f86d86 Ninja Multi-Config: Shuffle variables around
Remove redundant variable CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE.
Rename other variables. Document and improve handling of error
conditions.
2020-02-03 13:27:51 -05:00
Brad King
b12b013028 Ninja: Factor metadata cleanup into dedicated method 2020-01-27 15:39:04 -05:00
Kyle Edwards
b7a2baf38c Ninja Multi-Config: Add variable to control configs used in cross-config build 2020-01-23 15:47:12 -05:00
Kyle Edwards
8337ed0d73 Ninja Multi-Config: Add variable to control aliases in build.ninja 2020-01-22 10:26:21 -05:00
Kyle Edwards
110037369d Refactor: Split Ninja files into impl-<Config>.ninja and build-<Config>.ninja 2020-01-22 10:26:21 -05:00
Kyle Edwards
e8032e202e Ninja Multi-Config: Make cross-config building opt-in
Many users will want to use the Ninja Multi-Config generator like a
traditional Visual Studio-style multi-config generator, which doesn't
mix configurations - custom commands are built using target executables
of the same configuration the command is for. We do not want to force
these people to generate an N*N build matrix when they only need N*1,
especially if they have lots of targets. Add a new variable,
CMAKE_NINJA_CROSS_CONFIG_ENABLE, to opt-in to the cross-config build
matrix.
2020-01-10 16:31:29 -05:00
Brad King
2ee6baef4f Merge topic 'ninja-postgen-commands'
fb18215904 Ninja: clean ninja metadata once generated

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Jan Niklas Hasse <jhasse@bixense.com>
Merge-request: !3316
2020-01-10 13:30:35 -05:00
Marc Chevrier
a00960288b GlobalGenerator family: modernize memory management 2020-01-07 11:03:11 +01:00
Ben Boeckel
fb18215904 Ninja: clean ninja metadata once generated
Fixes: #15830
2020-01-06 11:57:08 -05:00
Marc Chevrier
5444a8095d cmGlobalGenerator: modernize memrory managemenbt 2019-12-30 16:55:39 +01:00
Kyle Edwards
5a8a9f7229 Ninja: Add multi-config variant
Co-Authored-by: vector-of-bool <vectorofbool@gmail.com>
2019-12-13 10:51:46 -05:00
Kyle Edwards
3bc63e99e4 Refactor: Prepare Ninja generator for multi-config 2019-12-13 10:51:46 -05:00