target_link_libraries and add_dependencies

前端 未结 2 1259
不思量自难忘°
不思量自难忘° 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:24

    I don't know what you're particularly interested in...

    From a conceptual point of view -- I think you're right. It is a waste of bytes.

    From a CMake documentation point of view -- You should prefer make so to guarantee the correct build order.

    According to the documentation target_link_libraries, add_dependencies concepts was ideologically split. Such an idea of split dependencies, and linker options is also persisted in the Makefile format in the GNU make tool.

    target_link_libraries

    ..Specify libraries or flags to use when linking a given target..

    add_dependencies

    ...Make a top-level depend on other top-level targets to ensure that they build before does...

    In modern CMake from 3.* you can omit add_dependencies if you will perform linking with an aliased target:

    add_library(fooLib 1.cpp 2.cpp)
    add_library(my::fooLib ALIAS fooLib)
    ...
    target_link_libraries(fooBin my::fooLib)
    

提交回复
热议问题