On 21-Aug-14 00:50, Nico Schl?mer nico.schloe...@gmail.com wrote:
Hi all,
a general question:
I have a dependency chain of libraries
A - B - C - ... - Z
and all of those libraries are built with CMake, using CMake's export
functionality [1] to let the next in the chain know about its the
dependencies.
If all of the libraries are built statically and A needs some symbols
from a third-party library A1, this information needs to travel to Z.
Right now, in the export file I'm writing out the link line as
set(a_EXTRA_LIBS -lhdf5 -lhdf5_hl -ldl -lm -lz -lcurl)
You need to use find_package instead of raw `-llib` option since `-l`
will not work for windows.
In this case it will looks something like this (e.g. curl):
# CMakeLists.txt
find_package(CURL REQUIRED)
target_include_directories(your_target PUBLIC ${CURL_INCLUDE_DIRS})
target_link_libraries(your_target PUBLIC ${CURL_LIBRARIES})
See that library's paths are hard-coded in ProjectTargets*.cmake after
exporting:
set_target_properties(
your-target PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES /usr/include
)
set_target_properties(
your-target PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE
/usr/lib/x86_64-linux-gnu/libcurl.so
)
If it's not appropriate you can find it inside
ProjectConfig.cmake.in file:
@PACKAGE_INIT@
find_package(CURL REQUIRED)
include(.../ProjectTargets.cmake) # import your_target_name
target_include_directories(your_target PUBLIC ${CURL_INCLUDE_DIRS})
# New curl location
target_link_libraries(your_target PUBLIC ${CURL_LIBRARIES})
but link type need to be PRIVATE:
# CMakeLists.txt
find_package(CURL REQUIRED)
target_include_directories(your_target PRIVATE
${CURL_INCLUDE_DIRS}) # Avoid publishing hard-coded location
target_link_libraries(your_target PRIVATE ${CURL_LIBRARIES})
It's simplier when third-party package is config mode friendly:
# CMakeLists.txt
find_package(SomePack CONFIG REQUIRED)
target_link_libraries(your_target PUBLIC SomePack::some_lib)
# ProjectConfig.cmake.in
@PACKAGE_INIT@
find_package(SomePack CONFIG REQUIRED) # import SomePack::some_lib
include(.../ProjectTargets.cmake) # link to SomePack::some_lib
automatically
# `target_link_libraries` not needed, already linked
Hope this helps.
--
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