|
| 1 | +# |
| 2 | +# Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | +# |
| 6 | + |
| 7 | +function(sdp_assembly_generate hrt_srcs) |
| 8 | + set(hrt_msg "Generating ASM files for Hard Real Time files.") |
| 9 | + set(hrt_opts -g0 -fno-ident -fno-verbose-asm) |
| 10 | + |
| 11 | + # Compiler does not know how to build for this platform so we export |
| 12 | + # all the flags used in this zephyr build to the external build system. |
| 13 | + zephyr_get_compile_options_for_lang(C options) |
| 14 | + zephyr_get_compile_definitions_for_lang(C defines) |
| 15 | + zephyr_get_include_directories_for_lang(C includes) |
| 16 | + zephyr_get_system_include_directories_for_lang(C sys_includes) |
| 17 | + # Replace "-I" with "-isystem" to treat all Zephyr headers as system headers |
| 18 | + # that do not trigger -Werror. |
| 19 | + string(REPLACE "-I" "-isystem" includes "${includes}") |
| 20 | + |
| 21 | + set(compiler_options ${defines} ${options} ${includes} ${sys_includes}) |
| 22 | + |
| 23 | + if(TARGET asm_gen) |
| 24 | + message(FATAL_ERROR "sdp_assembly_generate() already called, please note that |
| 25 | + sdp_assembly_generate() must be called only once with a list of all source files." |
| 26 | + ) |
| 27 | + endif() |
| 28 | + |
| 29 | + # Define the asm_gen target that depends on all generated assembly files |
| 30 | + add_custom_target(asm_gen |
| 31 | + COMMENT ${hrt_msg} |
| 32 | + ) |
| 33 | + |
| 34 | + foreach(hrt_src ${hrt_srcs}) |
| 35 | + if(IS_DIRECTORY ${hrt_src}) |
| 36 | + message(FATAL_ERROR "sdp_assembly_generate() was called on a directory") |
| 37 | + endif() |
| 38 | + get_filename_component(src_filename ${hrt_src} NAME_WE) # filename without extension |
| 39 | + add_custom_command(TARGET asm_gen |
| 40 | + BYPRODUCTS ${src_filename}-temp.s |
| 41 | + COMMAND ${CMAKE_C_COMPILER} ${compiler_options} ${hrt_opts} -S ${hrt_src} -o ${src_filename}-temp.s |
| 42 | + COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_NRF_MODULE_DIR}/scripts/sdp/remove_comments.py ${src_filename}-temp.s |
| 43 | + DEPENDS ${hrt_src} |
| 44 | + COMMAND_EXPAND_LISTS |
| 45 | + COMMENT "Generating ASM file for ${hrt_src}" |
| 46 | + ) |
| 47 | + endforeach() |
| 48 | + |
| 49 | + add_dependencies(asm_gen syscall_list_h_target) |
| 50 | + |
| 51 | +endfunction() |
0 commit comments