Files
libsession-util/cmake/AddStaticBundleLib.cmake
Jason Rhinelander cbc37c8fc5 Fix link dependency recursion for interface libraries
LINK_LIBRARIES apparently isn't set for pure interface libraries, so we
weren't picking up some needed libraries found via interface targets
when building a bundled static lib; this fixes it by following
INTERFACE_LINK_LIBRARIES when we recurse into an interface library.
2024-04-05 12:49:07 -03:00

37 lines
1.3 KiB
CMake

set(LIBSESSION_STATIC_BUNDLE_LIBS "" CACHE INTERNAL "list of libs to go into the static bundle lib")
function(_libsession_static_bundle_append tgt)
list(APPEND LIBSESSION_STATIC_BUNDLE_LIBS "${tgt}")
set(LIBSESSION_STATIC_BUNDLE_LIBS "${LIBSESSION_STATIC_BUNDLE_LIBS}" CACHE INTERNAL "")
endfunction()
# Call as:
#
# libsession_static_bundle(target [target2 ...])
#
# to append the given target(s) to the list of libraries that will be combined to make the static
# bundled libsession-util.a.
function(libsession_static_bundle)
foreach(tgt IN LISTS ARGN)
if(TARGET "${tgt}" AND NOT "${tgt}" IN_LIST LIBSESSION_STATIC_BUNDLE_LIBS)
get_target_property(tgt_type ${tgt} TYPE)
if(tgt_type STREQUAL STATIC_LIBRARY)
message(STATUS "Adding ${tgt} to libsession-util bundled library list")
_libsession_static_bundle_append("${tgt}")
endif()
if(tgt_type STREQUAL INTERFACE_LIBRARY)
get_target_property(tgt_link_deps ${tgt} INTERFACE_LINK_LIBRARIES)
else()
get_target_property(tgt_link_deps ${tgt} LINK_LIBRARIES)
endif()
if(tgt_link_deps)
libsession_static_bundle(${tgt_link_deps})
endif()
endif()
endforeach()
endfunction()