@@ -3,3 +3,63 @@ if (NOT TARGET pico_platform_sections)
33
44 target_include_directories (pico_platform_sections_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR} /include )
55endif ()
6+
7+ # pico_sections_time_critical(TARGET [SOURCES])
8+ # \brief\ Prefix target's object file sections with ".time_critical"
9+ #
10+ # This function will apply "objcopy --prefix-alloc-sections .time_critical" to all the object files of
11+ # TARGET that match either an optionally specified list of source files or all the target's "SOURCES" found
12+ # within in the target's "SOURCE_DIR".
13+ #
14+ # Examples:
15+ # pico_sections_time_critical(MyTarget)
16+ #
17+ # pico_sections_time_critical(MyTarget
18+ # some_time_critical_code.c
19+ # other_time_critical_code.c
20+ # )
21+ #
22+ # \param\ TARGET The build target
23+ # \param\ SOURCES Optional, source files of the object files to be modified. If not specified, uses the build
24+ # target's "SOURCES" list.
25+ function (pico_sections_time_critical TARGET )
26+ add_custom_command (
27+ TARGET ${TARGET}
28+ PRE_LINK
29+ COMMAND ${CMAKE_COMMAND} -E echo "execute_process($<LIST:TRANSFORM,$<LIST:FILTER,$<LIST:TRANSFORM,$<TARGET_OBJECTS:${TARGET} >,REPLACE,/\. /,/>,INCLUDE,$<LIST:JOIN,$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:FILTER,$<LIST:TRANSFORM,$<IF:$<STREQUAL:${ARGN} ,>,$<TARGET_PROPERTY:${TARGET} ,SOURCES>,${ARGN} >,REPLACE,^$<TARGET_PROPERTY:${TARGET} ,SOURCE_DIR>/,>,EXCLUDE,^/|\. h$>,PREPEND,/$<TARGET_NAME:${TARGET} >.dir/>,APPEND,.o$>,REPLACE,\\\. ,\\\\ .>,|>>,PREPEND,COMMAND ${CMAKE_OBJCOPY} --prefix-alloc-sections .time_critical >)" > ${TARGET} _sections_time_critical.cmake
30+ COMMAND ${CMAKE_COMMAND} -P ${TARGET} _sections_time_critical.cmake
31+ COMMAND ${CMAKE_COMMAND} -E echo "$<IF:$<STREQUAL:${ARGN} ,>,All,Selected> \" $<TARGET_NAME:${TARGET} >\" object file alloc-section names have been updated for \" time_critical\" linker placement"
32+ VERBATIM
33+ COMMAND_EXPAND_LISTS
34+ )
35+ endfunction ()
36+
37+ # pico_sections_not_in_flash(TARGET [SOURCES])
38+ # \brief\ Prefix target's object file sections with ".time_critical_ram"
39+ #
40+ # This function will apply "objcopy --prefix-alloc-sections .time_critical_ram" to all the object files of
41+ # TARGET that match either an optionally specified list of source files or all the target's "SOURCES" found
42+ # within in the target's "SOURCE_DIR".
43+ #
44+ # Examples:
45+ # pico_sections_not_in_flash(MyTarget)
46+ #
47+ # pico_sections_not_in_flash(MyTarget
48+ # some_code.c
49+ # other_code.c
50+ # )
51+ #
52+ # \param\ TARGET The build target
53+ # \param\ SOURCES Optional, source files of the object files to be modified. If not specified, uses the build
54+ # target's "SOURCES" list.
55+ function (pico_sections_not_in_flash TARGET )
56+ add_custom_command (
57+ TARGET ${TARGET}
58+ PRE_LINK
59+ COMMAND ${CMAKE_COMMAND} -E echo "execute_process($<LIST:TRANSFORM,$<LIST:FILTER,$<LIST:TRANSFORM,$<TARGET_OBJECTS:${TARGET} >,REPLACE,/\. /,/>,INCLUDE,$<LIST:JOIN,$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:FILTER,$<LIST:TRANSFORM,$<IF:$<STREQUAL:${ARGN} ,>,$<TARGET_PROPERTY:${TARGET} ,SOURCES>,${ARGN} >,REPLACE,^$<TARGET_PROPERTY:${TARGET} ,SOURCE_DIR>/,>,EXCLUDE,^/|\. h$>,PREPEND,/$<TARGET_NAME:${TARGET} >.dir/>,APPEND,.o$>,REPLACE,\\\. ,\\\\ .>,|>>,PREPEND,COMMAND ${CMAKE_OBJCOPY} --prefix-alloc-sections .time_critical_ram >)" > ${TARGET} _sections_not_in_flash.cmake
60+ COMMAND ${CMAKE_COMMAND} -P ${TARGET} _sections_not_in_flash.cmake
61+ COMMAND ${CMAKE_COMMAND} -E echo "$<IF:$<STREQUAL:${ARGN} ,>,All,Selected> \" $<TARGET_NAME:${TARGET} >\" object file section names have been updated for \" not_in_flash\" linker placement"
62+ VERBATIM
63+ COMMAND_EXPAND_LISTS
64+ )
65+ endfunction ()
0 commit comments