[CMake] does CMake have "usage targets" like Premake?

Alexander Neundorf a.neundorf-work at gmx.net
Tue Jan 17 12:32:15 EST 2012


On Tuesday 17 January 2012, Lance Luvaul wrote:
> I think cmake's find_package is only a first order approximation to
> premake's usages.  What usage library targets have that find_package
> doesn't is the ability to cleanly inject dependency info (like include
> dirs or link libraries) into any target that claims to be dependent on
> the library.  This is achieved simply by having the target call "uses
> <library>"... there is no need for the target to explicitly add anything
> to target_link_libraries() or include_directories().

For the linking part this works with cmake.
That's what you have to do with cmake:

find_package(Foo REQUIRED)

include_directories(${FOO_INCLUDES})
add_executable(HelloWorld ${srcs})
target_link_libraries(HelloWorld ${FOO_LIBRARIES} )

Dependencies are handled properly by the target_link_libraries() call, i.e. 
transitive libraries are added.

If FindFoo.cmake or FooConfig.cmake create imported targets for the libraries 
in question, these imported targets have properties.
Currently these properties contain the actual location of the library on disk, 
also for different configurations, so on Windows you'll get the debug library 
in a debug build, and the release library in a release build.

It is planned to add support for having the include directories also as such a 
target propery, so that you could save the include_directories() call in the 
example above.

Alex


More information about the CMake mailing list