forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdp.cmake
117 lines (95 loc) · 4.48 KB
/
sdp.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
# This function takes as an argument target to be built and path to .c source file(s)
# whose .s output must be verified against .s file tracked in repository. It then:
# - adds a pre-build dependency that generates .s files in build directory
# - adds a dependency on specified target to call sdp_asm_check.cmake with appropriate arguments
# - adds a custom target that calls sdp_asm_install.cmake with appropriate arguments
# - adds .s files from build directory to target sources
#
# Arguments:
# target - target to which the dependencies are to be applied
# hrt_srcs - path to the .c source file(s) to verify
function(sdp_assembly_install target hrt_srcs)
sdp_assembly_generate(${CONFIG_SOC} "${hrt_srcs}")
sdp_assembly_check(${CONFIG_SOC} "${hrt_srcs}")
sdp_assembly_prepare_install(${CONFIG_SOC} "${hrt_srcs}")
sdp_assembly_target_sources(${CONFIG_SOC} ${target} "${hrt_srcs}")
add_dependencies(${target} asm_check)
endfunction()
function(sdp_assembly_target_sources soc target hrt_srcs)
foreach(hrt_src ${hrt_srcs})
get_filename_component(hrt_dir ${hrt_src} DIRECTORY) # directory
get_filename_component(hrt_src_file ${hrt_src} NAME_WE) # filename without extension
set(hrt_s_file "${hrt_dir}/${hrt_src_file}-${soc}.s")
target_sources(${target} PRIVATE ${hrt_s_file})
endforeach()
endfunction()
function(sdp_assembly_generate soc hrt_srcs)
set(hrt_msg "Generating ASM files for Hard Real Time files.")
set(hrt_opts -g0 -fno-ident -fno-verbose-asm)
# Compiler does not know how to build for this platform so we export
# all the flags used in this zephyr build to the external build system.
zephyr_get_compile_options_for_lang(C options)
zephyr_get_compile_definitions_for_lang(C defines)
zephyr_get_include_directories_for_lang(C includes)
zephyr_get_system_include_directories_for_lang(C sys_includes)
# Replace "-I" with "-isystem" to treat all Zephyr headers as system headers
# that do not trigger -Werror.
string(REPLACE "-I" "-isystem" includes "${includes}")
set(compiler_options ${defines} ${options} ${includes} ${sys_includes})
if(TARGET asm_gen)
message(FATAL_ERROR "sdp_assembly_generate() already called, please note that
sdp_assembly_generate() must be called only once with a list of all source files."
)
endif()
# Define the asm_gen target that depends on all generated assembly files
add_custom_target(asm_gen
COMMENT ${hrt_msg}
)
foreach(hrt_src ${hrt_srcs})
if(IS_DIRECTORY ${hrt_src})
message(FATAL_ERROR "sdp_assembly_generate() was called on a directory")
endif()
get_filename_component(src_filename ${hrt_src} NAME_WE) # filename without extension
add_custom_command(TARGET asm_gen
PRE_BUILD
BYPRODUCTS ${src_filename}-${soc}-temp.s
COMMAND ${CMAKE_C_COMPILER} ${compiler_options} ${hrt_opts} -S ${hrt_src} -o ${src_filename}-${soc}-temp.s
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_NRF_MODULE_DIR}/scripts/sdp/remove_comments.py ${src_filename}-${soc}-temp.s
COMMAND_EXPAND_LISTS
COMMENT "Generating ASM file for ${hrt_src}"
)
endforeach()
add_dependencies(asm_gen syscall_list_h_target kobj_types_h_target)
endfunction()
function(sdp_assembly_check soc hrt_srcs)
set(asm_check_msg "Checking if ASM files for Hard Real Time have changed.")
if(TARGET asm_check)
message(FATAL_ERROR "sdp_assembly_check() already called, please note that
sdp_assembly_check() must be called only once with a list of all source files."
)
endif()
string(REPLACE ";" "$<SEMICOLON>" hrt_srcs_semi "${hrt_srcs}")
add_custom_target(asm_check
COMMAND ${CMAKE_COMMAND} -D hrt_srcs="${hrt_srcs_semi}" -D soc="${soc}" -P ${ZEPHYR_NRF_MODULE_DIR}/cmake/sdp_asm_check.cmake
COMMENT ${asm_check_msg}
)
add_dependencies(asm_check asm_gen)
endfunction()
function(sdp_assembly_prepare_install soc hrt_srcs)
set(asm_install_msg "Updating ASM files for Hard Real Time.")
if(TARGET asm_install)
message(FATAL_ERROR "sdp_assembly_prepare_install() already called, please note that
sdp_assembly_prepare_install() must be called only once with a list of all source files."
)
endif()
string(REPLACE ";" "$<SEMICOLON>" hrt_srcs_semi "${hrt_srcs}")
add_custom_target(asm_install
COMMAND ${CMAKE_COMMAND} -D hrt_srcs="${hrt_srcs_semi}" -D soc="${soc}" -P ${ZEPHYR_NRF_MODULE_DIR}/cmake/sdp_asm_install.cmake
COMMENT ${asm_install_msg}
)
endfunction()