add_dependencies: Allow calling with no dependencies

Fixes: #26713
This commit is contained in:
Martin Duffy 2025-02-20 11:04:26 -05:00
parent 8b8cf1ac8e
commit 609c949061
8 changed files with 20 additions and 2 deletions

View File

@ -12,7 +12,6 @@ ensure that they build before ``<target>`` does. A top-level target
is one created by one of the :command:`add_executable`,
:command:`add_library`, or :command:`add_custom_target` commands
(but not targets generated by CMake like ``install``).
At least one ``<target-dependency>`` must be given.
Dependencies added to an :ref:`imported target <Imported Targets>`
or an :ref:`interface library <Interface Libraries>` are followed
@ -32,6 +31,10 @@ transitively in its place since the target itself does not build.
finished before sources in ``<target>`` start compiling; this
ensures generated sources are available.
.. versionchanged:: 4.1
The command may be called with no dependencies.
Previously, at least one dependency was required.
See Also
^^^^^^^^

View File

@ -0,0 +1,4 @@
add-dependency-one-arg
----------------------
* The :command:`add_dependencies` command may be called with no dependencies.

View File

@ -12,7 +12,7 @@
bool cmAddDependenciesCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
if (args.size() < 2) {
if (args.empty()) {
status.SetError("called with incorrect number of arguments");
return false;
}

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
CMake Error at NoArgs.cmake:[0-9]+ \(add_dependencies\):
add_dependencies called with incorrect number of arguments
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)

View File

@ -0,0 +1 @@
add_dependencies()

View File

@ -0,0 +1,3 @@
enable_language(C)
add_library(a a.c)
add_dependencies(a ${noDependencies})

View File

@ -1,5 +1,7 @@
include(RunCMake)
run_cmake(NoArgs)
run_cmake(NoTarget)
run_cmake(NoDependencies)
run_cmake(ReadOnlyProperty)
run_cmake(RetrieveDependencies)