[cmake-developers] Setting include directories via target_link_libraries() ?

Alexander Neundorf neundorf at kde.org
Thu Dec 6 14:30:29 EST 2012


Hi,

I haven't followed the long thread between Brad and Stephen about importing 
and exporting targets closely...

So, if I understand correctly, in the future the following cmake code

find_package(Foo)

add_executable(hello main.cpp)

target_link_libraries(hello ${Foo_LIBRARIES})


may also set include directories ?

If so, I don't like this at all.
It changes the meaning of an existing command.

I would much prefer if instead there was a new command, e.g. 

target_use_targets(hello Foo::FooLibrary)

which would be obviously different from target_link_libraries(), and it would 
also only accept other targets as arguments, not library paths.

If target_link_libraries() is overloaded to do more than its name says (i.e. 
not only linking, but also set include dirs and definitions), IMO this will 
make for hard-to-understand/debug cmake files.
In the example above there is no visible hint that what 
target_link_libraries() actually does. (There is also no hint whether the 
find_package() expects a module or a Config file)


I'd much prefer the following:

find_package(Foo NO_MODULE)

add_executable(hello main.cpp)

target_use_targets(hello Foo::FooLibrary)


Alex



More information about the cmake-developers mailing list