add_dependencies

Add a dependency between top-level targets.

add_dependencies(<target> <target-dependency>...)

Makes a top-level <target> depend on other top-level targets to ensure that they build before <target> does. A top-level target is one created by one of the add_executable(), add_library(), or add_custom_target() commands (but not targets generated by CMake like install).

Dependencies added to an imported target or an interface library are followed transitively in its place since the target itself does not build.

在 3.3 版被加入: Allow adding dependencies to interface libraries.

在 3.8 版被加入: Dependencies will populate the MANUALLY_ADDED_DEPENDENCIES property of <target>.

在 3.9 版的變更: The Ninja 生成器 use weaker ordering than other generators in order to improve available concurrency. They only guarantee that the dependencies' custom commands are finished before sources in <target> start compiling; this ensures generated sources are available.

在 4.1 版的變更: The command may be called with no dependencies. Previously, at least one dependency was required.

另請參見