Ninja: Transform DEPFILEs with policy CMP0116

Fixes: #21267
This commit is contained in:
Kyle Edwards
2020-10-02 17:35:40 -04:00
parent 596439b1bb
commit 146e1e6ba1
23 changed files with 234 additions and 3 deletions
+5
View File
@@ -239,6 +239,11 @@ The options are:
command itself.
Using ``DEPFILE`` with other generators than Ninja is an error.
If the ``DEPFILE`` argument is relative, it should be relative to
:variable:`CMAKE_CURRENT_BINARY_DIR`, and any relative paths inside the
``DEPFILE`` should also be relative to :variable:`CMAKE_CURRENT_BINARY_DIR`
(see policy :policy:`CMP0116`.)
Build Events
^^^^^^^^^^^^
+1
View File
@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.20
.. toctree::
:maxdepth: 1
CMP0116: Ninja generators transform DEPFILEs from add_custom_command(). </policy/CMP0116>
CMP0115: Source file extensions must be explicit. </policy/CMP0115>
Policies Introduced by CMake 3.19
+38
View File
@@ -0,0 +1,38 @@
CMP0116
-------
.. versionadded:: 3.20
Ninja generators transform ``DEPFILE`` s from :command:`add_custom_command`.
In CMake 3.19 and below, files given to the ``DEPFILE`` argument of
:command:`add_custom_command` were passed directly to Ninja's ``depfile``
variable without any path resolution. This meant that if
:command:`add_custom_command` was called from a subdirectory (created by
:command:`add_subdirectory`), the ``DEPFILE`` argument would have to be either
an absolute path or a path relative to :variable:`CMAKE_BINARY_DIR`, rather
than :variable:`CMAKE_CURRENT_BINARY_DIR`. In addition, no transformation was
done on the file listed in ``DEPFILE``, which meant that the paths within the
``DEPFILE`` had the same restrictions.
Starting with CMake 3.20, the ``DEPFILE`` argument is relative to
:variable:`CMAKE_CURRENT_BINARY_DIR` (unless it is absolute), and the paths in
the ``DEPFILE`` are also relative to :variable:`CMAKE_CURRENT_BINARY_DIR`.
CMake automatically transforms the paths in the ``DEPFILE`` (unless they are
absolute) after the custom command is run. The file listed in ``DEPFILE`` is
not modified in any way. Instead, CMake writes the transformation to its own
internal file, and passes this internal file to Ninja's ``depfile`` variable.
This transformation happens regardless of whether or not ``DEPFILE`` is
relative, and regardless of whether or not :command:`add_custom_command` is
called from a subdirectory.
The ``OLD`` behavior for this policy is to pass the ``DEPFILE`` to Ninja
unaltered. The ``NEW`` behavior for this policy is to transform the ``DEPFILE``
after running the custom command.
This policy was introduced in CMake version 3.20. Unlike most policies,
CMake version |release| does *not* warn by default when this policy is not set
(unless ``DEPFILE`` is used in a subdirectory) and simply uses ``OLD``
behavior. See documentation of the
:variable:`CMAKE_POLICY_WARNING_CMP0116 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
variable to control the warning.
@@ -0,0 +1,5 @@
ninja-depfile-transformation
----------------------------
* Ninja generators now transform ``DEPFILE`` s from
:command:`add_custom_command`. See policy :policy:`CMP0116` for details.
@@ -27,6 +27,8 @@ warn by default:
policy :policy:`CMP0102`.
* ``CMAKE_POLICY_WARNING_CMP0112`` controls the warning for
policy :policy:`CMP0112`.
* ``CMAKE_POLICY_WARNING_CMP0116`` controls the warning for
policy :policy:`CMP0116`.
This variable should not be set by a project in CMake code. Project
developers running CMake may set this variable in their cache to