Skip to content

Commit

Permalink
Static bundles for the IAR toolchain[DRAFT] (#177)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
reimerix and sokhealy committed Aug 8, 2024
1 parent 5b65c03 commit fa93409
Showing 1 changed file with 47 additions and 19 deletions.
66 changes: 47 additions & 19 deletions ArchiveUtility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 " \$<TARGET_FILE:${bundle_library}>")
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}
Expand Down

0 comments on commit fa93409

Please sign in to comment.