Skip to content

Commit 58ed105

Browse files
committed
cmake: add two new targets for SDP
Add two new targets regarding ASM code for SDP: asm_check that checks if ASM file has changed, and asm_update that updates ASM files in source directory with the new generated. Signed-off-by: Magdalena Pastula <[email protected]>
1 parent 1164518 commit 58ed105

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

cmake/sdp.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,41 @@ function(sdp_assembly_generate hrt_srcs)
4949
add_dependencies(asm_gen syscall_list_h_target)
5050

5151
endfunction()
52+
53+
function(sdp_assembly_check hrt_srcs)
54+
set(asm_check_msg "Checking if ASM files for Hard Real Time have changed.")
55+
56+
if(TARGET asm_check)
57+
message(FATAL_ERROR "sdp_assembly_check() already called, please note that
58+
sdp_assembly_check() must be called only once with a list of all source files."
59+
)
60+
endif()
61+
62+
string(REPLACE ";" "$<SEMICOLON>" hrt_srcs_semi "${hrt_srcs}")
63+
64+
add_custom_target(asm_check
65+
COMMAND ${CMAKE_COMMAND} -D hrt_srcs="${hrt_srcs_semi}" -P ${ZEPHYR_NRF_MODULE_DIR}/cmake/sdp_asm_check.cmake
66+
COMMENT ${asm_check_msg}
67+
)
68+
69+
add_dependencies(asm_check asm_gen)
70+
71+
endfunction()
72+
73+
function(sdp_assembly_prepare_install hrt_srcs)
74+
set(asm_install_msg "Updating ASM files for Hard Real Time.")
75+
76+
if(TARGET asm_install)
77+
message(FATAL_ERROR "sdp_assembly_prepare_install() already called, please note that
78+
sdp_assembly_prepare_install() must be called only once with a list of all source files."
79+
)
80+
endif()
81+
82+
string(REPLACE ";" "$<SEMICOLON>" hrt_srcs_semi "${hrt_srcs}")
83+
84+
add_custom_target(asm_install
85+
COMMAND ${CMAKE_COMMAND} -D hrt_srcs="${hrt_srcs_semi}" -P ${ZEPHYR_NRF_MODULE_DIR}/cmake/sdp_asm_install.cmake
86+
COMMENT ${asm_install_msg}
87+
)
88+
89+
endfunction()

cmake/sdp_asm_check.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
function(asm_check)
8+
9+
foreach(hrt_src ${hrt_srcs})
10+
get_filename_component(asm_filename ${hrt_src} NAME_WE) # filename without extension
11+
get_filename_component(src_dir ${hrt_src} DIRECTORY)
12+
13+
execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files --ignore-eol
14+
${src_dir}/${asm_filename}.s ${asm_filename}-temp.s
15+
RESULT_VARIABLE compare_result)
16+
17+
if( compare_result EQUAL 0)
18+
message("File ${asm_filename}.s has not changed.")
19+
elseif( compare_result EQUAL 1)
20+
message(WARNING "${asm_filename}.s ASM file content has changed.\
21+
If you want to include the new ASM in build, \
22+
please run `ninja asm_install` in FLPR build directory and build again")
23+
else()
24+
message("Something went wrong when comparing ${asm_filename}.s and ${asm_filename}-temp.s")
25+
endif()
26+
endforeach()
27+
28+
endfunction(asm_check)
29+
30+
asm_check()

cmake/sdp_asm_install.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
function(asm_install)
8+
9+
foreach(hrt_src ${hrt_srcs})
10+
get_filename_component(asm_filename ${hrt_src} NAME_WE) # filename without extension
11+
get_filename_component(src_dir ${hrt_src} DIRECTORY)
12+
13+
file(RENAME ${asm_filename}-temp.s ${src_dir}/${asm_filename}.s RESULT rename_result)
14+
15+
if (rename_result EQUAL 0)
16+
message("Updated ${asm_filename}.s ASM file.")
17+
else()
18+
message(WARNING "${asm_filename}.s cannot be updated, new ASM does not exist. Please run ninja asm_gen to create one.")
19+
endif()
20+
21+
endforeach()
22+
23+
endfunction(asm_install)
24+
25+
asm_install()

0 commit comments

Comments
 (0)