diff --git a/cmake/Corrosion.cmake b/cmake/Corrosion.cmake index 14b7bd2d..41c2b1b3 100644 --- a/cmake/Corrosion.cmake +++ b/cmake/Corrosion.cmake @@ -1077,7 +1077,6 @@ function(corrosion_link_libraries target_name) " aside from establishing a build dependency." ) endif() - add_dependencies(_cargo-build_${target_name} ${ARGN}) foreach(library ${ARGN}) set_property( TARGET _cargo-build_${target_name} @@ -1086,8 +1085,29 @@ function(corrosion_link_libraries target_name) $ ) - corrosion_add_target_local_rustflags(${target_name} "-L$") - corrosion_add_target_local_rustflags(${target_name} "-l$") + if (TARGET ${library}) + corrosion_add_target_local_rustflags(${target_name} + "-L$" + "-l$" + ) + add_dependencies(_cargo-build_${target_name} ${library}) + get_property(libs TARGET ${library} PROPERTY INTERFACE_LINK_LIBRARIES) + corrosion_link_libraries(${target_name} ${libs}) + elseif(IS_ABSOLUTE ${library}) + # Linking via full path + corrosion_add_target_local_rustflags(${target_name} "-Clink-arg=${library}") + else() + # We have to assume ${library} is a non-CMake library name + corrosion_add_target_local_rustflags(${target_name} "-l${library}") + endif() + + # Propagate dependency on ${library} + set_property( + TARGET _cargo-build_${target_name} + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES + ${library} + ) endforeach() endfunction(corrosion_link_libraries)