diff --git a/README.md b/README.md index eb0c5d2f..20cd08f7 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,8 @@ corrosion_import_crate(MANIFEST_PATH [NO_LINKER_OVERRIDE] # Specify cargo build profile (e.g. release or a custom profile) [PROFILE ] + # Retrieve the list of imported crates in the current scope + [IMPORTED_CRATES ] # Build only the specified crate types (Ignored with CMake < 3.19) [CRATE_TYPES ... ] # Only import the specified crates from a workspace diff --git a/cmake/Corrosion.cmake b/cmake/Corrosion.cmake index ae547d13..fe4e926c 100644 --- a/cmake/Corrosion.cmake +++ b/cmake/Corrosion.cmake @@ -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}) @@ -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) diff --git a/cmake/CorrosionGenerator.cmake b/cmake/CorrosionGenerator.cmake index 013949dd..4f2df9f0 100644 --- a/cmake/CorrosionGenerator.cmake +++ b/cmake/CorrosionGenerator.cmake @@ -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}")