[cmake-developers] Optional dependencies in target INTERFACE

Stephen Kelly steveire at gmail.com
Mon Jun 30 04:18:52 EDT 2014


Hello,

QtSQL provides abstracted access to database data. It does not depend on 
QtGui or QtWidgets.

It also provides the header-only qsqlrelationaldelegate.h. The contents of 
that header depend on QtWidgets, and are wrapped in an ifdef QT_WIDGETS_LIB. 
That means that the QSqlRelationalDelegate class is only available if that 
macro is defined, which is an effect of linking to Qt5Widgets anyway. This 
seems to be a good and well-working way to have an optional INTERFACE 
dependency.

Unfortunately most projects do not have something similar to QT_WIDGETS_LIB 
macros.

If a target is only a dependency if the depender uses a particular header, 
then should that target appear in the INTERFACE_LINK_LIBRARIES? If using 
QtGui but not using #include <qopengl> you do not depend on the GL 
libraries. If you add that include, you do depend on the GL libraries. Do 
the GL libraries belong in the INTERFACE_LINK_LIBRARIES of QtGui? That is 
the subject of 

 https://bugreports.qt-project.org/browse/QTBUG-39859

In the case of modularized-Boost header-only libraries with INTERFACE 
targets, what criteria should be used to determine whether to put a 
dependency in the INTERFACE_LINK_LIBRARIES and make component packages? The 
actual dependencies required are determined by what the user #includes, not 
by what headers are #included by 'my' headers.

Thanks,

Steve.




More information about the cmake-developers mailing list