cmake 2.6.2 now required - changes in handling shared libs

Ben Boeckel mathstuf at gmail.com
Fri Nov 28 07:16:40 CET 2008


On Thursday 27 November 2008 15:02:54 Alexander Neundorf wrote:
> On Tuesday 25 November 2008, Ben Boeckel wrote:
> > On Monday 10 November 2008 19:00:50 Alexander Neundorf wrote:
> > > 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
> > >
> > > >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> > > >> unsubscribe <<
> >
> > Hi,
> >
> > I am developing a project that uses KDE4 and I am trying to get the
> > CMakeLists.txt to conform to the changes made upstream. I made the change
> > to one of my libraries, but when I try to do it on another library which
> > requires it, it errors with:
> >
> > CMake Error: INSTALL(EXPORT "sigmod_EXPORTS" ...) includes target
> > "sigmod" which requires target "sigcore" that is not in the export set.
>
> This means you expüort the target "sigmod" which links to "sigcore",
> but "sigcore" is not exported.
> Is sigcore a shared library ?
> Then you should export it too.
>
> Exporting targets is only useful if you install shared libs which should be
> used by other projects. Is that the case for you ?
>
> Alex

Sigcore is a shared library that is also in my project. It's a game engine, so 
it may or may not me used by other projects, but if it is, these libraries 
handle the loading and saving of the game data. The sigcore and sigmod 
directories are siblings, so I'm not sure how to export the sigcore target 
without installing sigcore (or hacking around to find where the temporary cmake 
file ends up). Unless there is other CMake magic I've missed in my reading.

--Ben


More information about the Kde-buildsystem mailing list