[CMake] link_libraries vs target_link_libraries

Fernando Cacciola fernando.cacciola at gmail.com
Mon Nov 10 09:01:13 EST 2008


Hi people,

The CGAL library (www.cgal.org) uses cmake as build system. Thus, our 
users do:

find_package(CGAL REQUIRED)
include( ${CGAL_USE_FILE} )
...


UseCGAL.cmake, as all such files, call include_directories, 
add_definitions and overrides (under certain circumstances) the 
compiler/linker flags that were used to build the CGAL library.

These are all settings that affect any target added after the inclusion 
of UseCGAL.cmake.

However, following the recommended practice (according to the 
documentation of the deprecated link_libraries command), UseCGAL DOES 
NOT call link_libraries. Instead, it realies on the user calling 
target_link_libraries himself.

Well, I'm questioning this recommended practice because it's half baked: 
It makes sense to allow users to control which targets are linked 
against CGAL, but NOT if OTOH they cannot control which targets are 
given the CGAL include directories, definitions and flags.

That is, IMO, target_link_libraries makes little sense in the absence of 
target_include_directories, target_add_definitions and target_*_FLAGS.

What it's so special about linking that only that command can be made 
target specific???

Or am I missing something?

TIA

Fernando Cacciola






More information about the CMake mailing list