Is there any use case in which
target_link_libraries(my-lib x y z)
add_dependencies(my-lib x) # this is not just a waste of bytes?
If so, can someone explain what it would be?
Is there any use case in which
target_link_libraries(my-lib x y z)
add_dependencies(my-lib x) # this is not just a waste of bytes?
If so, can someone explain what it would be?
I don't know in what particularly you're interesting...
From conceptual point of view -- I think you're right it is a waste of bytes
From cmake documentation point of view -- You should prefer make so to guarantee correct build order
According to the documentation target_link_libraries, add_dependencies concepts was ideologically splitted. Such idea of split depencies, and linker options is also persist in Makefile format in GNU make tool
target_link_libraries
add_dependencies
In modern cmake from 3.* you can omit add_dependencies if you will perform linking with aliased target
In current CMake releases:
After some error checking
add_dependencies
results in a call toTarget->AddUtility()
.x
is added to the list of utilities formy-lib
.target_link_libraries
does not result in a call toAddUtility
, but it does add the arguments to theLINK_LIBRARIES
target property.Later, both the content of the
LINK_LIBRARIES
target property and the list of utilities are used to compute the dependencies of the target incmComputeTargetDepends
.The list of utilities in a target can not be queried at configure time, and is only used at generate time, so the use of
add_dependencies
with arguments which are libraries already added withtarget_link_libraries
is redundant.It's used in cases where top-level targets depend on each other. That is, if x is a something that you add to your project (at top-level) with
you shall tell CMake about it. And you do that with add_dependencies.