Files
pixiv_downloader/cmake/GetLinkLibraries.cmake
2022-03-19 17:14:53 +08:00

37 lines
1.5 KiB
CMake

function(get_link_libraries OUTPUT_LIST TARGET)
get_target_property(IMPORTED ${TARGET} IMPORTED)
list(APPEND VISITED_TARGETS ${TARGET})
if (IMPORTED)
get_target_property(LIBS ${TARGET} INTERFACE_LINK_LIBRARIES)
else()
get_target_property(LIBS ${TARGET} LINK_LIBRARIES)
endif()
set(LIB_FILES "")
foreach(LIB ${LIBS})
if (TARGET ${LIB})
get_target_property(LIB_IMPORTED ${LIB} IMPORTED)
list(FIND VISITED_TARGETS ${LIB} VISITED)
if (${VISITED} EQUAL -1)
if (LIB_IMPORTED)
get_target_property(LIB_FILE ${LIB} LOCATION)
if (NOT LIB_FILE)
get_target_property(LIB_FILE ${LIB} IMPORTED_LOCATION)
endif()
if (NOT LIB_FILE)
get_target_property(LIB_FILE ${LIB} IMPORTED_IMPLIB)
endif()
if (NOT LIB_FILE)
get_target_property(LIB_FILE ${LIB} INTERFACE_LINK_LIBRARIES)
endif()
get_link_libraries(LINK_LIB_FILES ${LIB})
list(APPEND LIB_FILES ${LIB_FILE} ${LINK_LIB_FILES})
else()
list(APPEND LIB_FILES ${LIB})
endif()
endif()
endif()
endforeach()
set(VISITED_TARGETS ${VISITED_TARGETS} PARENT_SCOPE)
set(${OUTPUT_LIST} ${LIB_FILES} PARENT_SCOPE)
endfunction()