From fa9340974f98fb9375d77be73f0cd1fd438af1ea Mon Sep 17 00:00:00 2001 From: Christian Reimer Date: Thu, 8 Aug 2024 22:58:09 +0200 Subject: [PATCH] Static bundles for the IAR toolchain[DRAFT] (#177) We made a release to Asensing but the IAR library was not bundled properly and static linking was not done. The plan is to use `add_static_library_bundle` but, the archive code is not compatible with IAR. A flag was added that is only set during IAR compilation and installs. Currently, we are using CMAKE but plan to move to Bazel after this patch release --------- Co-authored-by: sokhealy --- ArchiveUtility.cmake | 66 +++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/ArchiveUtility.cmake b/ArchiveUtility.cmake index 1533764..a530a60 100644 --- a/ArchiveUtility.cmake +++ b/ArchiveUtility.cmake @@ -127,25 +127,53 @@ function (add_static_library_bundle target) string (APPEND mri_script "fi\n\n") endforeach() string (APPEND mri_script "echo save\n") - string (APPEND mri_script "echo end") - - set (mri_script_file ${mri_script_dir}/script.mri.sh) - - file (GENERATE - OUTPUT ${mri_script_file} - CONTENT "${mri_script}" - CONDITION 1 - ) - - add_custom_command ( - OUTPUT ${output_directory}/${output_library} - COMMAND bash ${mri_script_file} | ${CMAKE_AR} -M - COMMAND_EXPAND_LISTS - WORKING_DIRECTORY - ${output_directory} - DEPENDS - ${bundle_libraries} - ) + string (APPEND mri_script "echo end\n") + + if (ARCHIVE_IAR) + set (iar_script) + string (APPEND iar_script "--create") + foreach (bundle_library IN LISTS bundle_libraries) + string (APPEND iar_script " \$") + endforeach() + string (APPEND iar_script " -o ${output_directory}/${output_library}\n") + + set (iar_script_file ${mri_script_dir}/script.iar.sh) + set (iar_cp_file ${mri_script_dir}/script.iar_cp.sh) + + file (GENERATE + OUTPUT ${iar_script_file} + CONTENT "${iar_script}" + CONDITION 1 + ) + + add_custom_command ( + OUTPUT ${output_directory}/${output_library} + COMMAND ${CMAKE_AR} -f ${iar_script_file} + COMMAND_EXPAND_LISTS + WORKING_DIRECTORY + ${output_directory} + DEPENDS + ${bundle_libraries} + ) + else () + set (mri_script_file ${mri_script_dir}/script.mri.sh) + + file (GENERATE + OUTPUT ${mri_script_file} + CONTENT "${mri_script}" + CONDITION 1 + ) + + add_custom_command ( + OUTPUT ${output_directory}/${output_library} + COMMAND bash ${mri_script_file} | ${CMAKE_AR} -M + COMMAND_EXPAND_LISTS + WORKING_DIRECTORY + ${output_directory} + DEPENDS + ${bundle_libraries} + ) + endif() add_custom_target (${target} ALL DEPENDS ${output_directory}/${output_library}