[CMake] How to specify library dir for imported interface?

Francis Giraldeau francis.giraldeau at gmail.com
Sat Jun 30 14:34:11 EDT 2018


Build fails at link time, because a static library imported using
pkg-config is not in the standard path:

[ 74%] Linking CXX executable valhalla_add_predicted_traffic
/usr/bin/c++   ... -lprime_server ...

Usually, cmake uses the absolute path to the static library, but instead,
pkg-config provides the library name and the library dir separately. Here
is the imported target:

add_library(libprime_server INTERFACE IMPORTED)
pkg_check_modules(libprime_server REQUIRED libprime_server>=0.6.3)
set_target_properties(libprime_server PROPERTIES
    INTERFACE_LINK_LIBRARIES "${libprime_server_LIBRARIES}"
    INTERFACE_INCLUDE_DIRECTORIES "${libprime_server_INCLUDE_DIRS}")

The library dir is defined in the CMakeCache.txt (both in the LDFLAGS in
LIBRARY_DIRS):

libprime_server_LDFLAGS:INTERNAL=-L/home/francis/local/lib;-lprime_server
libprime_server_LIBRARY_DIRS:INTERNAL=/home/francis/local/lib

However, it seems no property exists to actually specify the library dir of
imported target, nor the linker flags to pass when using the imported
target.

What would be the best way to specify the library dir for an imported
library?

Thanks!

Francis Giraldeau
-- 
Francis Giraldeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180630/7d569e6a/attachment.html>


More information about the CMake mailing list