Skip to content

Commit

Permalink
Respect OUTPUT_NAME when linking targets that have it defined
Browse files Browse the repository at this point in the history
This causes the OUTPUT_NAME target_property to be used when passing the
-l flag to corrosion_link_libraries. However, if any users have
corrosion_link_libraries(MyRustExe LibA) in their CMakeLists before the
target LibA is defined, it will now error out because the target is not
defined yet.
  • Loading branch information
ADKaster authored and jschwe committed May 23, 2022
1 parent abe7f4f commit e80ba34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 2 additions & 3 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,9 @@ function(corrosion_link_libraries target_name)
PROPERTY CARGO_DEPS_LINKER_LANGUAGES
$<TARGET_PROPERTY:${library},LINKER_LANGUAGE>
)
corrosion_add_target_rustflags(${target_name} "-L$<TARGET_LINKER_FILE_DIR:${library}>")

# TODO: The output name of the library can be overridden - find a way to support that.
corrosion_add_target_rustflags(${target_name} "-l${library}")
corrosion_add_target_rustflags(${target_name} "-L$<TARGET_LINKER_FILE_DIR:${library}>")
corrosion_add_target_rustflags(${target_name} "-l$<TARGET_LINKER_FILE_BASE_NAME:${library}>")
endforeach()
endfunction(corrosion_link_libraries)

Expand Down
4 changes: 3 additions & 1 deletion test/cpp2rust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml)
corrosion_link_libraries(rust-exe cpp-lib cpp-lib2 cpp-lib3)

add_library(cpp-lib lib.cpp)
target_compile_features(cpp-lib PRIVATE cxx_std_14)
Expand All @@ -15,6 +14,7 @@ set_target_properties(
cpp-lib2
PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME cpp-lib-renamed
)

add_library(cpp-lib3 "path with space/lib3.cpp" )
Expand All @@ -24,3 +24,5 @@ set_target_properties(
PROPERTIES
POSITION_INDEPENDENT_CODE ON
)

corrosion_link_libraries(rust-exe cpp-lib cpp-lib2 cpp-lib3)

0 comments on commit e80ba34

Please sign in to comment.