CMP0116.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. CMP0116
  2. -------
  3. .. versionadded:: 3.20
  4. Ninja generators transform ``DEPFILE`` s from :command:`add_custom_command`.
  5. In CMake 3.19 and below, files given to the ``DEPFILE`` argument of
  6. :command:`add_custom_command` were passed directly to Ninja's ``depfile``
  7. variable without any path resolution. This meant that if
  8. :command:`add_custom_command` was called from a subdirectory (created by
  9. :command:`add_subdirectory`), the ``DEPFILE`` argument would have to be either
  10. an absolute path or a path relative to :variable:`CMAKE_BINARY_DIR`, rather
  11. than :variable:`CMAKE_CURRENT_BINARY_DIR`. In addition, no transformation was
  12. done on the file listed in ``DEPFILE``, which meant that the paths within the
  13. ``DEPFILE`` had the same restrictions.
  14. Starting with CMake 3.20, the ``DEPFILE`` argument is relative to
  15. :variable:`CMAKE_CURRENT_BINARY_DIR` (unless it is absolute), and the paths in
  16. the ``DEPFILE`` are also relative to :variable:`CMAKE_CURRENT_BINARY_DIR`.
  17. CMake automatically transforms the paths in the ``DEPFILE`` (unless they are
  18. absolute) after the custom command is run. The file listed in ``DEPFILE`` is
  19. not modified in any way. Instead, CMake writes the transformation to its own
  20. internal file, and passes this internal file to Ninja's ``depfile`` variable.
  21. This transformation happens regardless of whether or not ``DEPFILE`` is
  22. relative, and regardless of whether or not :command:`add_custom_command` is
  23. called from a subdirectory.
  24. The ``OLD`` behavior for this policy is to pass the ``DEPFILE`` to Ninja
  25. unaltered. The ``NEW`` behavior for this policy is to transform the ``DEPFILE``
  26. after running the custom command. The status of ``CMP0116`` is recorded at the
  27. time of the custom command's creation, and you can have custom commands in the
  28. same directory with different values for ``CMP0116`` by setting the policy
  29. before each custom command.
  30. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.20
  31. .. |WARNS_OR_DOES_NOT_WARN| replace::
  32. does *not* warn by default (unless ``DEPFILE`` is used in a subdirectory)
  33. .. include:: include/STANDARD_ADVICE.rst
  34. See documentation of the
  35. :variable:`CMAKE_POLICY_WARNING_CMP0116 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
  36. variable to control the warning.
  37. .. include:: include/DEPRECATED.rst