To answer your question:
# Assume libtool_file is set somewhere to your .la file.
file(READ "${libtool_file}" contents)
if (contents MATCHES "dependency_libs *= *'([^']*)'")
string(STRIP "${CMAKE_MATCH_1}" deps)
string(REGEX REPLACE " +" ";" deps "${deps}")
target_link_libraries(my_target PRIVATE ${deps})
else ()
message(WARNING "${libtool_file} does not declare dependencies")
endif ()
But I would really, REALLY encourage you to use something more standard like PkgConfig, for which CMake has native support. Or better yet, the library's own find_package
-compatible config package and its imported targets if they are available.
For what it's worth, I could only find one, single .la
file on my system that included a dependency. That file was /usr/lib/x86_64-linux-gnu/libltdl.la
and it contained a single dependency on -ldl
(which can be better accessed through ${CMAKE_DL_LIBS}
, anyway).