cmake 2.6.2 now required - changes in handling shared libs

Alexander Neundorf neundorf at kde.org
Tue Nov 11 01:00:50 CET 2008


Hi,

as of now cmake 2.6.2 is required to build KDE4 trunk.

This brings some bugfixes, some nice features and one relatively big change, 
which concerns shared library handling.

Warning: if you get linker errors or errors related to different build 
types/configurations (i.e. debug vs. release etc.) please let me know .


Now straight on to the big change(TM).

Short version:
In kdelibs, when creating a shared lib, now also add the arguments
"EXPORT kdelibsLibraryTargets" to the install(TARGETS ...) command, like this:

install(TARGETS threadweaver EXPORT kdelibsLibraryTargets
                             ${INSTALL_TARGETS_DEFAULT_ARGS})

And to define a minimal link interface, do this:

target_link_libraries(threadweaver
                              LINK_INTERFACE_LIBRARIES ${QT_QTCORE_LIBRARY} )


Now the long version (you should read it):

The correct way to create and install a shared library is now:

kde4_add_library(kfoo SHARED ${kfooSources} ) 
target_link_libraries(kfoo kdecore ${QT_QTCORE_LIBRARY} ${ZLIB_LIBRARY})

# No changes so far, but the next line is new.
# It specifies to which libraries other targets will be linked which 
# link to libkfoo. By default these are all libraries kfoo links against,
# which can lead to some unnecessary dependencies, slower startup, etc.
# So we now specifiy which "link interface" the library kfoo has, ZLIB
# is used only internally, so users of kfoo don't have to link against it:

target_link_libraries(kfoo LINK_INTERFACE_LIBRARIES 
                           kdecore ${QT_QTCORE_LIBRARY})

# Next change: shared libraries are now exported as targets, i.e. for every
# library target a snippet of cmake code is created which can be included by 
# other cmake-using projects, and there this code will create "imported"
# library targets. E.g. here we have the target kfoo, which can be referenced
# within this project simply by its name "kfoo". With the exported (and then
# imported) targets this is now also possible in external projects. 
# In order to have a target "exported", it must be installed and be marked as 
# belonging to an "export set", which can be assigned arbitrary names, here I
# decided to name it "MyKFooExports":

install(TARGETS kfoo EXPORT MyKFooExports ${INSTALL_TARGETS_DEFAULT_ARGS})

# The command above basically tells cmake to create the mentioned script
# snippets. Now these must actually be installed themselves, so the following
# command does that for all targets which have been marked as belonging to 
# "MyKFooExports":
install(EXPORT MyKFooExports DESTINATION ${DATA_INSTALL_DIR}/cmake/modules
                             FILE MyKFooExportedLibraryTargets.cmake )


Alex


More information about the Kde-buildsystem mailing list