[CMake] $<> expressions in include_directories command

Brad King brad.king at kitware.com
Mon Jul 25 11:22:40 EDT 2011


On 07/13/2011 12:10 PM, Alexander Neundorf wrote:
> When I talked last time with Brad such a feature was still on his TODO, and is 
> there since at least 2007 already, but still more or less at the bottom of the 
> list.

It's more of a "wish I had time to do this" ;)

> add_library(foo ${fooSrcs})
> set_target_properties(foo PROPERTIES INCLUDE_DIRS ${...whereever})
> 
> This should then also work when exporting/importing targets and with different 
> configurations.

Yes.  This is effectively a "usage requirements" feature.

> You are right that target_link_libraries() could take care of the rest (Brad 
> suggested this too), but I wouldn't like that, since it would be a change in 
> behaviour and very unobvious.

It's not a change in behavior because currently no projects set any such
properties on their targets since CMake doesn't define any.  Perhaps it
is not obvious because we're trying to give target_link_libraries a
meaning beyond just linking.  However, it is already a nice place that
lists the dependencies of a target so it is tempting to use it.

> If a user who doesn't know the "new" behaviour of target_link_libraries() 
> would see the new code, he would have no chance to find out where the include 
> dirs are coming from:
> 
>    add_executable(hello ${srcs})
>    target_link_libraries(hello ${FOO_LIBRARIES})
> 
> Actually this would even be a somewhat source incompatible change, since it 
> would mean that the same cmake code would suddenly create a different set of 
> include dirs.

It is not incompatible because the change is only after updating to a newer
version of FOO which sets the usage requirement properties.  The newer
FOO would have to require a sufficiently new version of CMake to support
the feature.  No old build would be affected.

>    target_use_libraries(hello USE_INCLUDE_DIRS ${FOO_LIBRARIES})
> or 
>    target_use_bundle(hello USE_INCLUDE_DIRS ${FOO_LIBRARIES})

I'm not opposed to introducing a new command for this.  However, I think
USE_INCLUDE_DIRS is too verbose.  The command is stating that it wants to
do everything needed to use FOO.  Instead we should bring in everything
by default but allow a NO_INCLUDE_DIRS option to drop certain requirements
in obscure cases.

-Brad


More information about the CMake mailing list