target_link_libraries and add_dependencies

前端 未结 2 1255
不思量自难忘°
不思量自难忘° 2021-02-11 18:30

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

2条回答
  •  悲哀的现实
    2021-02-11 19:28

    In current CMake releases:

    After some error checking add_dependencies results in a call to Target->AddUtility(). x is added to the list of utilities for my-lib.

    target_link_libraries does not result in a call to AddUtility, but it does add the arguments to the LINK_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 in cmComputeTargetDepends.

    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 with target_link_libraries is redundant.

提交回复
热议问题