Frameworks/Epics/kdelibs cleanups/link private details

< Frameworks‎ | Epics‎ | kdelibs cleanups
Revision as of 15:54, 8 June 2012 by Randomguy3 (Talk | contribs) (Make page easier to read)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Find out what should be part of the link interface and what should not be.

If a framework uses a library, but does not contain any of its symbols in its API, then it can be linked to privately.

See how this works in kcoreaddons (edited):

  LINK_PRIVATE pthread

pthread is linked to privately because none of the pthread symbols are in the kcoreaddons API. That means that if an application links to kcoreaddons they don't automatically have to link to pthread too.

Conversely, lots of the QtCore API is in the kcoreaddons API (returning QString, inheriting QObject etc), so downstreams using kcoreaddons also have to link to QtCore too.

CMake makes things easier for downstreams if we list our public and private link libraries separately, so we should do that.

The way to figure it out is this:

git grep "QT_.*_LIBRAR"

this gives you the target_link_libraries lines in frameworks.

For example in solid:

stephen@hal:~/dev/src/kf5/tier1/solid{frameworks}$ git grep "QT_.*_LIBRAR"
solid/CMakeLists.txt:target_link_libraries(solid ${QT_QTCORE_LIBRARY} 
${solid_OPTIONAL_LIBS} )
solid/CMakeLists.txt:target_link_libraries(solid LINK_INTERFACE_LIBRARIES 
solid/CMakeLists.txt:target_link_libraries(solid_static ${QT_QTCORE_LIBRARY} 
tests/CMakeLists.txt:target_link_libraries(fakehardwaretest solid_static 
tests/CMakeLists.txt:target_link_libraries(halbasictest solid_static 
tests/CMakeLists.txt:target_link_libraries(solidhwtest ${QT_QTCORE_LIBRARY} 
tests/CMakeLists.txt:target_link_libraries(solidmttest ${QT_QTCORE_LIBRARY} 

There are results there for the QtXml and the QtDBus libraries for example. We can use grep to see if either is in the public API of solid:

stephen@hal:~/dev/src/kf5/tier1/solid{frameworks}$ git grep Xml
solid/backends/fakehw/fakemanager.cpp:#include <QtXml/QDomDocument>
solid/backends/fakehw/fakemanager.cpp:#include <QtXml/QDomElement>
solid/backends/fakehw/fakemanager.cpp:#include <QtXml/QDomNode>
solid/backends/fakehw/fakemanager.cpp:    QString machineXmlFile = xmlFile;
solid/backends/fakehw/fakemanager.cpp:    d->xmlFile = machineXmlFile;
solid/managerbase.cpp:    QString 
solid/managerbase.cpp:    if (!solidFakeXml.isEmpty()) {
solid/managerbase.cpp:        m_backends << new 
Solid::Backends::Fake::FakeManager(0, solidFakeXml);
stephen@hal:~/dev/src/kf5/tier1/solid{frameworks}$ git grep Dom
solid/backends/fakehw/fakemanager.cpp:#include <QtXml/QDomDocument>
solid/backends/fakehw/fakemanager.cpp:#include <QtXml/QDomElement>
solid/backends/fakehw/fakemanager.cpp:#include <QtXml/QDomNode>
solid/backends/fakehw/fakemanager.cpp:    QDomDocument fakeDocument;
solid/backends/fakehw/fakemanager.cpp:        qWarning() << Q_FUNC_INFO << 
"Error while creating the QDomDocument." << endl;
solid/backends/fakehw/fakemanager.cpp:    QDomElement mainElement = 
solid/backends/fakehw/fakemanager.cpp:    QDomNode node = 
solid/backends/fakehw/fakemanager.cpp:        QDomElement tempElement = 
*FakeManager::parseDeviceElement(const QDomElement &deviceElement)
solid/backends/fakehw/fakemanager.cpp:    QDomNode propertyNode = 
solid/backends/fakehw/fakemanager.cpp:        QDomElement propertyElement = 
solid/backends/fakehw/fakemanager.h:class QDomElement;
solid/backends/fakehw/fakemanager.h:    FakeDevice *parseDeviceElement(const 
QDomElement &element);

QtXml is only an implementation detail of solid, so we can link to it privately. Repeat for all link dependencies. If you can say for certain that one or some arguments to link_interface_libraries should be public, then go ahead and change them to use the LINK_PUBLIC and LINK_PRIVATE keywords.

If in doubt, put what you are not certain about after LINK_PRIVATE.

This page was last modified on 8 June 2012, at 15:54. Content is available under Creative Commons License SA 4.0 unless otherwise noted.