Frameworks/Epics/kdelibs cleanups/link private details

From KDE Community Wiki
Revision as of 09:40, 18 February 2012 by Ervin (talk | contribs) (Created page with "<pre> 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 ca...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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):

target_link_libraries(kcoreaddons
  LINK_PUBLIC ${QT_QTCORE_LIBRARY}
  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} 
${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} 
${solid_OPTIONAL_LIBS} )
solid/CMakeLists.txt:target_link_libraries(solid LINK_INTERFACE_LIBRARIES 
${QT_CORE_LIBRARY} )
solid/CMakeLists.txt:target_link_libraries(solid_static ${QT_QTCORE_LIBRARY} 
${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} 
${solid_OPTIONAL_LIBS})
tests/CMakeLists.txt:target_link_libraries(fakehardwaretest solid_static 
${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} 
${QT_QTTEST_LIBRARY} )
tests/CMakeLists.txt:target_link_libraries(halbasictest solid_static 
${KDEWIN_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} 
${QT_QTXML_LIBRARY} ${QT_QTTEST_LIBRARY} )
tests/CMakeLists.txt:target_link_libraries(solidhwtest ${QT_QTCORE_LIBRARY} 
${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTTEST_LIBRARY} ${LIBS} 
solid_static)
tests/CMakeLists.txt:target_link_libraries(solidmttest ${QT_QTCORE_LIBRARY} 
${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTTEST_LIBRARY} ${LIBS} 
solid_static)
tests/CMakeLists.txt:#target_link_libraries(solidnettestdbusservice 
${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} 
${QT_QTTEST_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 
solidFakeXml(QString::fromLocal8Bit(qgetenv("SOLID_FAKEHW")));
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 = 
fakeDocument.documentElement();
solid/backends/fakehw/fakemanager.cpp:    QDomNode node = 
mainElement.firstChild();
solid/backends/fakehw/fakemanager.cpp:        QDomElement tempElement = 
node.toElement();
solid/backends/fakehw/fakemanager.cpp:FakeDevice 
*FakeManager::parseDeviceElement(const QDomElement &deviceElement)
solid/backends/fakehw/fakemanager.cpp:    QDomNode propertyNode = 
deviceElement.firstChild();
solid/backends/fakehw/fakemanager.cpp:        QDomElement propertyElement = 
propertyNode.toElement();
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.