Skip to content

Commit

Permalink
Improvements to corrosion_link_libraries()
Browse files Browse the repository at this point in the history
- Allow linking by full path and non-target library name

Co-authored-by: Jonathan Schwender <schwenderjonathan@gmail.com>
  • Loading branch information
Felix-El and jschwe committed Sep 5, 2024
1 parent 3d7c4b2 commit f3d0095
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,6 @@ function(corrosion_link_libraries target_name)
return()
endif()
endif()
add_dependencies(_cargo-build_${target_name} ${ARGN})
foreach(library ${ARGN})
set_property(
TARGET _cargo-build_${target_name}
Expand All @@ -1150,8 +1149,19 @@ function(corrosion_link_libraries target_name)
$<TARGET_PROPERTY:${library},LINKER_LANGUAGE>
)

corrosion_add_target_local_rustflags(${target_name} "-L$<TARGET_LINKER_FILE_DIR:${library}>")
corrosion_add_target_local_rustflags(${target_name} "-l$<TARGET_LINKER_FILE_BASE_NAME:${library}>")
if (TARGET "${library}")
corrosion_add_target_local_rustflags(${target_name}
"-L$<TARGET_LINKER_FILE_DIR:${library}>"
"-l$<TARGET_LINKER_FILE_BASE_NAME:${library}>"
)
add_dependencies(_cargo-build_${target_name} ${library})
elseif(IS_ABSOLUTE "${library}")
# Linking via full path (See https://doc.rust-lang.org/rustc/command-line-arguments.html#linking-modifiers-verbatim)
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()
endforeach()
endfunction()

Expand Down

0 comments on commit f3d0095

Please sign in to comment.