Skip to content

Commit

Permalink
llext: custom target properties, add_llext_command example
Browse files Browse the repository at this point in the history
Allow external code to interact with the llext build process by publishing
custom properties on the targets created by add_llext_target(). This is
especially useful to custom commands, since they may need to retrieve
specific details about the targets on which they can operate.

Add an example usage of the new properties and add_llext_command() to
the hello_world test case.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
  • Loading branch information
pillo79 committed Mar 11, 2024
1 parent 811b075 commit 21b29c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5149,6 +5149,15 @@ endfunction()
# flags to remove and flags to append is controlled respectively by the
# LLEXT_REMOVE_FLAGS and LLEXT_APPEND_FLAGS global variables.
#
# The following custom properties of <target_name> are defined and can be
# retrieved using the get_target_property() function:
#
# - LibTarget Target name for the source compilation and/or link step.
# - LibOutput The binary file resulting from compilation and/or
# linking steps.
# - PkgInput The file to be used as input for the packaging step.
# - PkgOutput The final .llext file.
#
# Example usage:
# add_llext_target(hello_world
# OUTPUT ${PROJECT_BINARY_DIR}/hello_world.llext
Expand Down Expand Up @@ -5285,12 +5294,18 @@ function(add_llext_target target_name)
message(FATAL_ERROR "add_llext_target: unsupported architecture")
endif()

# Add user-visible target and dependency
# Add user-visible target and dependency, and fill in properties
get_filename_component(output_name ${llext_pkg_output} NAME)
add_custom_target(${target_name}
COMMENT "Generating ${output_name}"
DEPENDS ${llext_pkg_output}
)
set_target_properties(${target_name} PROPERTIES
LibTarget ${llext_lib_target}
LibOutput ${llext_lib_output}
PkgInput ${llext_pkg_input}
PkgOutput ${llext_pkg_output}
)
endfunction()

# Usage:
Expand Down
11 changes: 11 additions & 0 deletions tests/subsys/llext/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ foreach(ext_name hello_world logging)
)
generate_inc_file_for_target(app ${ext_bin} ${ext_inc})
endforeach()

# Dummy custom processing command to test add_llext_command
get_target_property(proc_in_file hello_world_ext LibOutput)
get_target_property(proc_out_file hello_world_ext PkgInput)

add_llext_command(
TARGET hello_world_ext
POST_BUILD
COMMAND echo "dummy patching ${proc_in_file} to create ${proc_out_file}"
COMMAND ${CMAKE_COMMAND} -E copy ${proc_in_file} ${proc_out_file}
)

0 comments on commit 21b29c3

Please sign in to comment.