Using target_include_directories()

Stephen Kelly steveire at gmail.com
Mon Mar 25 20:51:02 UTC 2013


Alexander Neundorf wrote:
>> >> > Also, does this apply to the BUILD and INSTALL interface
>> >> 
>> >> Yes, it applies to both, because it is not wrapped in either
>> >> specifier. I can't think of any reason it would be appropriate for KDE
>> >> to have something like that wrapped in BUILD_INTERFACE or
>> >> INSTALL_INTERFACE.
>> > 
>> > I'm not sure I understand how you mean that.
>> > Do you mean in general or specifically why the kdeui include dir should
>> > be restricted to one of the two ?
>> 
>> I mean in general.
>> 
>> If target foo headers need target bar headers, then the bar include paths
>> are needed whether foo is used in-build or from an installed location.
> 
> Something which is in PUBLIC applies to
> * building itself
> * being used in-project
> * being used as imported target
> 
> The difference between the first two is not that big, putting an include
> dir into PUBLIC BUILD_INTERFACE doesn't add dependencies for the project
> compared to putting it into PRIVATE, so being sloppy there won't break
> much typically. 

*shrug*

I don't see much benefit in being sloppy.

> But my question was actually the following: does the INSTALL interface of
> kdeui end up in the INSTALL interface of kwidgets, and the BUILD interface
> of kdeui goes into the BUILD interface of kwidgets ?

Not really. I think your question conveys a misunderstanding.

The interface include directories of kdeui are not copied into kwidgets.

It's more like a pointer, in c++ terms. If 'kdeui' is in the same 
buildsystem as 'kwidgets', then the BUILD interface is read and added to the 
compile line of kwidgets. If 'kdeui' is an IMPORTED target, then the 
INTERFACE_INCLUDE_DIRECTORIES doesn't have a BUILD/INSTALL distinction. The 
INTERFACE_INCLUDE_DIRECTORIES of IMPORTED targets don't contain 
BUILD_INTERFACE or INSTALL_INTERFACE. One or the other gets stripped out at 
export-time.

Pretend for a moment that there is no circular dependency and it is as 
simple as this:

 add_library(kdeui ...)

 set(kdeui_INCLUDES 
   ${CMAKE_CURRENT_SOURCE_DIR}/widgets
   ${CMAKE_CURRENT_SOURCE_DIR}/actions
 )

 target_include_directories(kdeui PUBLIC 
   $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include> 
   $<BUILD_INTERFACE:${kdeui_INCLUDES}>
 )

 install(FILES 
   ${CMAKE_CURRENT_SOURCE_DIR}/widgets/somewidget.h
   ${CMAKE_CURRENT_SOURCE_DIR}/actions/someaction.h
   DESTINATION include
 )

 add_library(kwidgets ...)
 target_include_directories(kwidgets PUBLIC
   $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include> 
   $<TARGET_PROPERTY:kdeui,INTERFACE_INCLUDE_DIRECTORIES>
 )

 add_library(specialwidgets ...)
 target_include_directories(specialwidgets PUBLIC
   $<TARGET_PROPERTY:kwidgets,INTERFACE_INCLUDE_DIRECTORIES>
 )

When kwidgets is built, it will use 

 -I${CMAKE_CURRENT_SOURCE_DIR}/widgets -I${CMAKE_CURRENT_SOURCE_DIR}/actions

specialwidgets will use those too.

When kwidgets and kdeui are install(EXPORT)'ed, the IMPORTED targets will 
contain only:

 INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_PREFIX}/include"

So:

 find_package(KWidgets)
 add_library(someexternal ...)
 target_include_directories(someexternal KF5::kwidgets)

So, someexternal will use

 -Ithe_install_prefix_of_kdeui/include

Hopefully that answers your question. You seem to have started with some 
misunderstanding somewhere.

Thanks,

Steve.




More information about the Kde-buildsystem mailing list