Skip to content

Commit

Permalink
Add parameter to corrosion_import_crate to return list of added targe…
Browse files Browse the repository at this point in the history
…ts (#312)

* Allow retrieving list of imported crates
* Write about retrieving imported crates list in docs

(cherry picked from commit 44749a9)
  • Loading branch information
temeddix authored and jschwe committed Feb 17, 2023
1 parent 899bb40 commit edfaf97
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -196,6 +196,8 @@ corrosion_import_crate(MANIFEST_PATH <path/to/cargo.toml>
[NO_LINKER_OVERRIDE]
# Specify cargo build profile (e.g. release or a custom profile)
[PROFILE <cargo-profile>]
# Retrieve the list of imported crates in the current scope
[IMPORTED_CRATES <variable-name>]
# Build only the specified crate types (Ignored with CMake < 3.19)
[CRATE_TYPES <crate_type1> ... <crate_typeN>]
# Only import the specified crates from a workspace
Expand Down
6 changes: 5 additions & 1 deletion cmake/Corrosion.cmake
Expand Up @@ -1070,7 +1070,7 @@ endfunction()

function(corrosion_import_crate)
set(OPTIONS ALL_FEATURES NO_DEFAULT_FEATURES NO_STD NO_LINKER_OVERRIDE)
set(ONE_VALUE_KEYWORDS MANIFEST_PATH PROFILE)
set(ONE_VALUE_KEYWORDS MANIFEST_PATH PROFILE IMPORTED_CRATES)
set(MULTI_VALUE_KEYWORDS CRATE_TYPES CRATES FEATURES FLAGS)
cmake_parse_arguments(COR "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}" ${ARGN})

Expand Down Expand Up @@ -1154,6 +1154,10 @@ function(corrosion_import_crate)
PROFILE
"${COR_PROFILE}"
)

if (DEFINED COR_IMPORTED_CRATES)
set(${COR_IMPORTED_CRATES} ${imported_crates} PARENT_SCOPE)
endif()
endif()
endfunction(corrosion_import_crate)

Expand Down
2 changes: 2 additions & 0 deletions cmake/CorrosionGenerator.cmake
Expand Up @@ -217,6 +217,8 @@ function(_generator_add_cargo_targets no_linker_override)
message(DEBUG "Corrosion created the following CMake targets: ${created_targets}")
endif()

set(imported_crates ${created_targets} PARENT_SCOPE)

foreach(target_name ${created_targets})
foreach(output_var RUNTIME_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY)
get_target_property(output_dir ${target_name} "${output_var}")
Expand Down

0 comments on commit edfaf97

Please sign in to comment.