CMP0116.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.
  27. This policy was introduced in CMake version 3.20. Unlike most policies,
  28. CMake version |release| does *not* warn by default when this policy is not set
  29. (unless ``DEPFILE`` is used in a subdirectory) and simply uses ``OLD``
  30. behavior. See documentation of the
  31. :variable:`CMAKE_POLICY_WARNING_CMP0116 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
  32. variable to control the warning.