xxxx_LIBRARY_DIRS not used

Alexander Neundorf neundorf at
Mon Dec 29 10:52:12 CET 2008

On Friday 26 December 2008, Thiago Macieira wrote:
> Hi all
> It seems we have a problem with the xxxx_LIBRARY_DIRS variables not being
> used, even though they are set properly by PKG_CHECK_MODULE. That causes
> linking errors.
> Let me give you a concrete example: Google Gadgets library (ggadget) in
> kdebase/workspace/plasma/scriptengines/google_gadgets. The CMakeLists.txt
> file has:
> target_link_libraries(plasma_package_ggl
>   plasma ${KDE4_KDECORE_LIBS} )
> And the variable GOOGLEGADGETS_LIBRARIES contains a simple list of
> libraries to be linked to:
> qt-1.0;ggadget-1.0;QtGui;png;SM;ICE;QtCore;z;gthread-2.0;rt;glib-2.0;pthrea
> As you can see, there is no directory information there. This comes from
> FindPkgConfig.cmake's call:
>  _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}"
> LIBRARIES           "(^| )-l" --libs-only-l )
> Note the --libs-only-l line. The rest of the information is in the
> variable we're missing:
> _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}"
> LIBRARY_DIRS        "(^| )-L" --libs-only-L )
> So, the question is: how do we use this other variable? I see two options:
> 1) add the missing link_directories(${GOOGLEGADGETS_LIBRARY_DIRS}) to the
> CMakeLists.txt
> What is the recommended way?

I recommend to use find_library() and both FOO_LIBDIR and 
FOO_LIBRARY_DIRS as HINTS directories.

Also I suggest to use a "PC_" prefix for the variables set by 
FindPkgConfig.cmake, so they don't get mixed up with other variables.
You can have a look at kdelibs/cmake/modules/FindLibXml2.cmake for what I 
currently suggest how to use pkgconfig.

My other suggestion would be to iterate over all libs from FOO_LIBRARIES and 
do find_library() for each of them, probably checking only the directories 
from _LIBDIR and LIBRARY_DIRS. Then additionally there must be code to take 
care what happens if something is not found/not found there or if pkgconfig 
is not there at all/doesn't find the package.


More information about the Kde-buildsystem mailing list