add_dependencies.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. add_dependencies
  2. ----------------
  3. Add a dependency between top-level targets.
  4. .. code-block:: cmake
  5. add_dependencies(<target> <target-dependency>...)
  6. Makes a top-level ``<target>`` depend on other top-level targets to
  7. ensure that they build before ``<target>`` does. A top-level target
  8. is one created by one of the :command:`add_executable`,
  9. :command:`add_library`, or :command:`add_custom_target` commands
  10. (but not targets generated by CMake like ``install``).
  11. Dependencies added to an :ref:`imported target <Imported Targets>`
  12. or an :ref:`interface library <Interface Libraries>` are followed
  13. transitively in its place since the target itself does not build.
  14. .. versionadded:: 3.3
  15. Allow adding dependencies to interface libraries.
  16. .. versionadded:: 3.8
  17. Dependencies will populate the :prop_tgt:`MANUALLY_ADDED_DEPENDENCIES`
  18. property of ``<target>``.
  19. .. versionchanged:: 3.9
  20. The :ref:`Ninja Generators` use weaker ordering than
  21. other generators in order to improve available concurrency.
  22. They only guarantee that the dependencies' custom commands are
  23. finished before sources in ``<target>`` start compiling; this
  24. ensures generated sources are available.
  25. .. versionchanged:: 4.1
  26. The command may be called with no dependencies.
  27. Previously, at least one dependency was required.
  28. See Also
  29. ^^^^^^^^
  30. * The ``DEPENDS`` option of :command:`add_custom_target` and
  31. :command:`add_custom_command` commands for adding file-level
  32. dependencies in custom rules.
  33. * The :prop_sf:`OBJECT_DEPENDS` source file property to add
  34. file-level dependencies to object files.