Hello Eike, On 22/12/14 16:39, Rolf Eike Beer wrote: > What I would like to get is the following: when a list of libraries and > directories is returned by PkgConfig then for every of these libraries the > absolute path to the library is determined using find_library() using the > given > directories as hints. > [...] > Since this would introduce new behavior people would need to adapt > their CMakeLists.txt to this new feature. Therefore I think it would be a > good > idea to expose this new information not by new variables, but using targets.
We have a macro to do exactly this and a few other things (actually 2 macros, that diverged slightly I will make them one again as soon I as I have some time), you can find them here: https://github.com/robotology/yarp/blob/master/conf/MacroStandardFindModule.cmake https://github.com/robotology/ycm/blob/master/modules/StandardFindModule.cmake The macro tries first to find a CMake config file (some recent version of some package installs cmake config files, but we still need to support older versions, so that's the reason for this check). If the config files were not found, it uses pkg-config to detect the package, and find the libraries as you want to do, but instead of creating targets it sets some variables (see the documentation in the files). It's probably not perfect, but with this, creating a "FindXXX.cmake" for a software using pkg-config becomes trivial, for example: https://github.com/robotology/yarp/blob/master/conf/FindGtkDataboxMM.cmake and then you just use find_package() to locate your package and to get the variables. I agree that using targets would be a great thing, but at the time I didn't find a way generic enough to do all of this in the macro, since it's not always easy to understand which one is the "main" library "add_library(UNKNOWN IMPORTED)" and which ones should be in the "INTERFACE_LINK_LIBRARIES" property. Moreover we depend on CMake 2.8.9 that does not support all the features that we would need for targets. Perhaps using a recent CMake version you can use "add_library(INTERFACE IMPORTED)" and put all of them in the INTERFACE_LINK_LIBRARIES? > So if I search for OpenSSL using PkgConfig I would get a target > PkgConfig::OpenSSL that I can link to, and that has the libraries, compile > flags, include dirs and whatnot. > > Sadly, I don't quite understand all the macros in FindPkgConfig.cmake. Can > you > either point me to the right place where I would hook up something like that > or try doing it? You can start from the macros I linked before for the pkg-config part, and then have a look at the CMake modules that create imported targets (FindQt4, FindGTK2, FindZLIB, FindGLUT, FindGLEW) for the targets part (all the variables you need should be there already). Let me know if you do it, I'd like to do it too one day... About the FindPkgConfig macros documentation, what is that is not clear? http://www.cmake.org/cmake/help/git-master/module/FindPkgConfig.html It looks well documented to me, but if there is something that is not clear we could try to improve it... I hope this helps. Let me know if I can help you more specifically with this... Cheers, Daniele -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers