Explicitly link against public/interface dependencies?

Hi, I want to ask if I should explicitly call the find_package() and target_link_libraries() if they are provided by a library through INTERFACE_LINK_LIBRARIES.

A short explanation of what I mean :thinking:, I have a shared library TinyOrm::TinyOrm that has a public or interface dependencies for eg. Qt::Core, Qt::Sql, and range-v3::range-v3 and now I have a project hello::hello that links against this TinyOrm library.

Should I link against it like this:

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core Sql)
tiny_find_package(Qt${QT_VERSION_MAJOR} ${minQtVersion} CONFIG
    REQUIRED COMPONENTS Core Sql
)
tiny_find_package(range-v3 ${minRangeV3Version} CONFIG REQUIRED)
find_package(TinyOrm 0.1.0 CONFIG REQUIRED)

target_link_libraries(hello
    PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Sql
        range-v3::range-v3
        TinyOrm::TinyOrm
)

Or like this :sunglasses::

find_package(TinyOrm 0.1.0 CONFIG REQUIRED)

target_link_libraries(hello PRIVATE TinyOrm::TinyOrm)

Thank you for advice and suggestion. :pray:

The second one. However, TinyOrm will need to use find_package (probably via find_dependency from include(FindDependencyMacro)) to make its dependency targets available.

1 Like

Ok :ok_hand:, I’ve been confused about this since I started using CMake.

But it is logical, why would I duplicate that when it is already defined in the INTERFACE_LINK_LIBRARIES.