[cmake-developers] Setting includes, defines and other usage requirements with one command

Alexander Neundorf neundorf at kde.org
Sun Jan 27 06:14:06 EST 2013


On Thursday 24 January 2013, Stephen Kelly wrote:
> Hi there,
> 
> I've pushed the tll-includes-defines topic to my clone again, rebased to
> master.
> 
> It allows the removal a lot of redundant use of target_include_directories
> and target_compile_definitions. I think the real value of the whole feature
> will only come when all usage requirements can be set by connecting targets
> together one time with one command, be that with tll() or with
> target_use_interfaces().
> 
> One reason I think tll() should be used for that is that it has the
> implication that can be documented and easily understood - namely that
> cmake requirements usage is based on linking targets together.

Yes, but that's changing of the meaning of tll(), which exists for a long 
time.

> Linking correctly requires having compiled correctly, and compiling
> correctly depends on having used the correct include directories and
> compile definitions as specified by upstream, as well as a few other
> things such as use of -fPIC. Currently in cmake master, the -fPIC compile
> flag may be added depending on what targets are used in tll() calls, but
> the compile definitions and the include directories are not. As linking
> correctly depends on compiling correctly as specified by upstream, it
> seems natural to ensure that compiling correctly is possible as a result
> of
> target_link_libraries calls.
> 
> As far as I understand, the only objection is to the idea that
> target_link_libraries would be doing something other than linking, and it
> might not be obvious. It is currently used for -fPIC, so I'm not so sure.
> 
> Also, the objection is not that people would have to learn or discover, in
> documentation or otherwise, that target_link_libraries could have an effect
> other than linking. The objection instead is that, even long term and for
> experienced people, reading a line of code that contains a
> target_link_libraries call alone would not inform them of whether it is
> 'only' linking or whether it has other affects. This also seems funny to
> me. Given a line containing target_use_interfaces(foo PRIVATE bar), it is
> impossible to know from reading alone whether foo INCLUDE_DIRECTORIES,
> COMPILE_DEFINITIONS, LINK_LIBRARIES, or all three, are affected by the
> line. 

A new command (or macro) could warn if a target is used which doesn't have all 
three properties set (or maybe only for imported targets).

Does

function(target_use_stuff _target )
  target_compile_definitions(${_target} ${ARGN})
  target_include_directories(${_target} ${ARGN})
  target_link_libraries(${_target} ${ARGN})
endfunction()

actually differ from what you want to do for tll() ?

Alex



More information about the cmake-developers mailing list