Am 2018-05-24 18:48, schrieb Francesco Abbate:
Hi all,

I stumbled in a problem with CMake. Everything is working fine except
that, for two libraries that I locate with pkg-config, cmake does not
include during linking the library's path (-L<path>) which is given by
pkg-config.


Here an extract of the CMakeLists.txt:


[...]

include(FindPkgConfig)
pkg_search_module(AGG REQUIRED libagg)

[...]

target_link_libraries(libcanvas ${AGG_LIBRARIES})
target_include_directories(libcanvas PUBLIC
${PROJECT_SOURCE_DIR}/include ${AGG_INCLUDE_DIRS})
[...]

Yes, this is a known shortcoming. But there is already help available!

For CMake >= 3.7 you can ask FindPkgConfig to create an imported target for you, which will then include not only the library paths, but also the include directories, so you do not need to explicitely call target_include_directories() anymore:

pkg_search_module(AGG REQUIRED IMPORTED_TARGET libagg)

target_link_libraries(libcanvas PkgConfig::AGG)

I strongly encourage you to go this way as it also drags in needed defines and the like.

If you can't go that route for whatever reason you need to do

link_directories(${AGG_LIBRARY_DIRS})

Side note: this is the only place I can still accept the usage of that command.

And since it's crappy that you have the full library path in the target, but not in a variable, there will be <PREFIX>_LINK_LIBARIES from CMake 3.12 on, which would be the thing you pass to target_link_libraries() instead and which has the exact same information the imported target already has.

Greetings,

Eike
--

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:
https://cmake.org/mailman/listinfo/cmake

Reply via email to