From 12166142fdbfa88035edb253c3d61746af908935 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 14 Mar 2025 12:33:06 +0200 Subject: [PATCH 1/4] cmake/zephyr: decentralize src/debug/tester/ Adding all source files in a single, giant zephyr/CMakeLists.txt is inconvenient and does not scale. Link: https://github.com/thesofproject/sof/issues/8260 Signed-off-by: Kai Vehmanen --- src/debug/tester/CMakeLists.txt | 30 +++++++++++++++++++++++++++--- zephyr/CMakeLists.txt | 14 +------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/debug/tester/CMakeLists.txt b/src/debug/tester/CMakeLists.txt index 5b33427b3219..aa146c24d597 100644 --- a/src/debug/tester/CMakeLists.txt +++ b/src/debug/tester/CMakeLists.txt @@ -1,3 +1,27 @@ -add_local_sources(tester.c) -add_local_sources(tester_dummy_test.c) -add_local_sources(tester_simple_dram_test.c) +# SPDX-License-Identifier: BSD-3-Clause + +set(base_files + tester.c + tester_dummy_test.c + tester_simple_dram_test.c +) + +is_zephyr(it_is) +if(it_is) ### Zephyr ### + + if(CONFIG_COMP_TESTER STREQUAL "m") + + add_subdirectory(llext ${PROJECT_BINARY_DIR}/tester_llext) + add_dependencies(app tester) + + elseif(CONFIG_COMP_TESTER) + + zephyr_library_sources(${base_files}) + + endif() + +else() ### XTOS ### + + add_local_sources(sof ${base_files}) + +endif() diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 37c9f8f80b8d..88d2b34c8511 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -203,20 +203,8 @@ add_subdirectory(../src/init/ init_unused_install/) add_subdirectory(../src/ipc/ ipc_unused_install/) add_subdirectory(../src/debug/telemetry/ telemetry_unused_install/) add_subdirectory(../src/debug/debug_stream/ debug_stream_unused_install/) +add_subdirectory(../src/debug/tester/ debug_tester_unused_install/) add_subdirectory(../src/schedule/ schedule_unused_install/) - -if(CONFIG_COMP_TESTER STREQUAL "m") - add_subdirectory(${SOF_DEBUG_PATH}/tester/llext - ${PROJECT_BINARY_DIR}/tester_llext) - add_dependencies(app tester) -elseif(CONFIG_COMP_TESTER) - zephyr_library_sources_ifdef(CONFIG_COMP_TESTER - ${SOF_DEBUG_PATH}/tester/tester.c - ${SOF_DEBUG_PATH}/tester/tester_dummy_test.c - ${SOF_DEBUG_PATH}/tester/tester_simple_dram_test.c - ) -endif() - add_subdirectory(test/) From 5a2a069e82a493409aeeb61cf15bf66795836b57 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 17 Mar 2025 14:27:49 +0200 Subject: [PATCH 2/4] cmake/zephyr: decentralize src/math/ Adding all source files in a single, giant zephyr/CMakeLists.txt is inconvenient and does not scale. Align new cmake files with: https://docs.zephyrproject.org/latest/contribute/style/cmake.html Link: https://github.com/thesofproject/sof/issues/8260 Signed-off-by: Kai Vehmanen --- src/math/CMakeLists.txt | 78 ++++++++++++++++++-------- src/math/auditory/CMakeLists.txt | 23 +++++++- src/math/fft/CMakeLists.txt | 23 +++++++- zephyr/CMakeLists.txt | 96 +------------------------------- 4 files changed, 97 insertions(+), 123 deletions(-) diff --git a/src/math/CMakeLists.txt b/src/math/CMakeLists.txt index ef0c409b69a6..a4381630a061 100644 --- a/src/math/CMakeLists.txt +++ b/src/math/CMakeLists.txt @@ -1,58 +1,92 @@ # SPDX-License-Identifier: BSD-3-Clause if(BUILD_LIBRARY) - add_local_sources(sof numbers.c) - return() + add_local_sources(sof numbers.c) + return() endif() -add_local_sources(sof numbers.c) +set(base_files numbers.c) if(CONFIG_CORDIC_FIXED) - add_local_sources(sof trig.c) + list(APPEND base_files trig.c) endif() -add_local_sources_ifdef(CONFIG_MATH_LUT_SINE_FIXED sof lut_trig.c) +if(CONFIG_MATH_LUT_SINE_FIXED) + list(APPEND base_files lut_trig.c) +endif() -add_local_sources_ifdef(CONFIG_SQRT_FIXED sof sqrt_int16.c) +if(CONFIG_SQRT_FIXED) + list(APPEND base_files sqrt_int16.c) +endif() -add_local_sources_ifdef(CONFIG_MATH_EXP sof exp_fcn.c exp_fcn_hifi.c) +if(CONFIG_MATH_EXP) + list(APPEND base_files exp_fcn.c exp_fcn_hifi.c) +endif() if(CONFIG_MATH_DECIBELS) - add_local_sources(sof decibels.c) + list(APPEND base_files decibels.c) endif() -add_local_sources_ifdef(CONFIG_NATURAL_LOGARITHM_FIXED sof log_e.c) +if(CONFIG_NATURAL_LOGARITHM_FIXED) + list(APPEND base_files log_e.c) +endif() -add_local_sources_ifdef(CONFIG_COMMON_LOGARITHM_FIXED sof log_10.c) +if(CONFIG_COMMON_LOGARITHM_FIXED) + list(APPEND base_files log_10.c) +endif() -add_local_sources_ifdef(CONFIG_POWER_FIXED sof power.c) +if(CONFIG_POWER_FIXED) + list(APPEND base_files power.c) +endif() -add_local_sources_ifdef(CONFIG_BINARY_LOGARITHM_FIXED sof base2log.c) +if(CONFIG_BINARY_LOGARITHM_FIXED) + list(APPEND base_files base2log.c) +endif() -add_local_sources_ifdef(CONFIG_MATH_FIR sof fir_generic.c fir_hifi2ep.c fir_hifi3.c fir_hifi5.c) +if(CONFIG_MATH_FIR STREQUAL "m") + add_subdirectory(fir_llext ${PROJECT_BINARY_DIR}/fir_llext) + add_dependencies(app fir) +elseif(CONFIG_MATH_FIR) + list(APPEND base_files fir_generic.c fir_hifi2ep.c fir_hifi3.c fir_hifi5.c) +endif() if(CONFIG_MATH_FFT) - add_subdirectory(fft) + add_subdirectory(fft) endif() -add_local_sources_ifdef(CONFIG_MATH_IIR_DF2T sof - iir_df2t_generic.c iir_df2t_hifi3.c iir_df2t.c) +if(CONFIG_MATH_IIR_DF2T) + list(APPEND base_files iir_df2t_generic.c iir_df2t_hifi3.c iir_df2t.c) +endif() -add_local_sources_ifdef(CONFIG_MATH_IIR_DF1 sof - iir_df1_generic.c iir_df1_hifi3.c iir_df1_hifi4.c iir_df1_hifi5.c iir_df1.c) +if(CONFIG_MATH_IIR_DF1) + list(APPEND base_files iir_df1_generic.c iir_df1_hifi3.c iir_df1_hifi4.c iir_df1_hifi5.c iir_df1.c) +endif() if(CONFIG_MATH_WINDOW) - add_local_sources(sof window.c) + list(APPEND base_files window.c) endif() if(CONFIG_MATH_MATRIX) - add_local_sources(sof matrix.c) + list(APPEND base_files matrix.c) endif() if(CONFIG_MATH_AUDITORY) - add_subdirectory(auditory) + add_subdirectory(auditory) endif() if(CONFIG_MATH_DCT) - add_local_sources(sof dct.c) + list(APPEND base_files dct.c) +endif() + +is_zephyr(it_is) +if(it_is) ### Zephyr ### + + zephyr_library_sources( + ${base_files} + ) + +else() ### XTOS ### + + add_local_sources(sof ${base_files}) + endif() diff --git a/src/math/auditory/CMakeLists.txt b/src/math/auditory/CMakeLists.txt index 2983e1eb4483..ac89bc544f48 100644 --- a/src/math/auditory/CMakeLists.txt +++ b/src/math/auditory/CMakeLists.txt @@ -1,7 +1,24 @@ # SPDX-License-Identifier: BSD-3-Clause -add_local_sources(sof auditory.c) +set(base_files auditory.c) -add_local_sources_ifdef(CONFIG_MATH_16BIT_MEL_FILTERBANK sof mel_filterbank_16.c) +if(CONFIG_MATH_16BIT_MEL_FILTERBANK) + list(APPEND base_files mel_filterbank_16.c) +endif() -add_local_sources_ifdef(CONFIG_MATH_32BIT_MEL_FILTERBANK sof mel_filterbank_32.c) +if(CONFIG_MATH_32BIT_MEL_FILTERBANK) + list(APPEND base_files mel_filterbank_32.c) +endif() + +is_zephyr(it_is) +if(it_is) ### Zephyr ### + + zephyr_library_sources( + ${base_files} + ) + +else() ### XTOS ### + + add_local_sources(sof ${base_files}) + +endif() diff --git a/src/math/fft/CMakeLists.txt b/src/math/fft/CMakeLists.txt index 8d422b93c5b1..cfdf61b2bd8a 100644 --- a/src/math/fft/CMakeLists.txt +++ b/src/math/fft/CMakeLists.txt @@ -1,7 +1,24 @@ # SPDX-License-Identifier: BSD-3-Clause -add_local_sources(sof fft_common.c) +set(base_files fft_common.c) -add_local_sources_ifdef(CONFIG_MATH_16BIT_FFT sof fft_16.c fft_16_hifi3.c) +if(CONFIG_MATH_16BIT_FFT) + list(APPEND base_files fft_16.c fft_16_hifi3.c) +endif() -add_local_sources_ifdef(CONFIG_MATH_32BIT_FFT sof fft_32.c fft_32_hifi3.c) +if(CONFIG_MATH_32BIT_FFT) + list(APPEND base_files fft_32.c fft_32_hifi3.c) +endif() + +is_zephyr(it_is) +if(it_is) ### Zephyr ### + + zephyr_library_sources( + ${base_files} + ) + +else() ### XTOS ### + + add_local_sources(sof ${base_files}) + +endif() diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 88d2b34c8511..5ba4d1aca5f4 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -140,7 +140,6 @@ set(SOF_SAMPLES_PATH "${SOF_SRC_PATH}/samples") set(SOF_LIB_PATH "${SOF_SRC_PATH}/lib") set(SOF_DRIVERS_PATH "${SOF_SRC_PATH}/drivers") set(SOF_DEBUG_PATH "${SOF_SRC_PATH}/debug") -set(SOF_MATH_PATH "${SOF_SRC_PATH}/math") set(SOF_TRACE_PATH "${SOF_SRC_PATH}/trace") set(RIMAGE_TOP ${sof_top_dir}/tools/rimage) @@ -204,6 +203,7 @@ add_subdirectory(../src/ipc/ ipc_unused_install/) add_subdirectory(../src/debug/telemetry/ telemetry_unused_install/) add_subdirectory(../src/debug/debug_stream/ debug_stream_unused_install/) add_subdirectory(../src/debug/tester/ debug_tester_unused_install/) +add_subdirectory(../src/math/ math_unused_install/) add_subdirectory(../src/schedule/ schedule_unused_install/) add_subdirectory(test/) @@ -450,13 +450,6 @@ zephyr_include_directories(${SOF_PLATFORM_PATH}/${PLATFORM}/include) # Commented files will be added/removed as integration dictates. zephyr_library_sources( - # SOF math utilities - ${SOF_MATH_PATH}/decibels.c - ${SOF_MATH_PATH}/numbers.c - ${SOF_MATH_PATH}/trig.c - ${SOF_MATH_PATH}/exp_fcn.c - ${SOF_MATH_PATH}/exp_fcn_hifi.c - # SOF library - parts to transition to Zephyr over time ${SOF_LIB_PATH}/notifier.c ${SOF_LIB_PATH}/dma.c @@ -502,57 +495,6 @@ zephyr_library_sources_ifdef(CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL ${SOF_LIB_PATH}/cpu-clk-manager.c ) -# Optional math utility -zephyr_library_sources_ifdef(CONFIG_MATH_LUT_SINE_FIXED - ${SOF_MATH_PATH}/lut_trig.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_FFT - ${SOF_MATH_PATH}/fft/fft_common.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_16BIT_FFT - ${SOF_MATH_PATH}/fft/fft_16.c - ${SOF_MATH_PATH}/fft/fft_16_hifi3.c -) - -zephyr_library_sources_ifdef(ONFIG_MATH_32BIT_FFT - ${SOF_MATH_PATH}/fft/fft_32.c - ${SOF_MATH_PATH}/fft/fft_32_hifi3.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_DCT - ${SOF_MATH_PATH}/dct.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_WINDOW - ${SOF_MATH_PATH}/window.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_MATRIX - ${SOF_MATH_PATH}/matrix.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_AUDITORY - ${SOF_MATH_PATH}/auditory/auditory.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_16BIT_MEL_FILTERBANK - ${SOF_MATH_PATH}/auditory/mel_filterbank_16.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_32BIT_MEL_FILTERBANK - ${SOF_MATH_PATH}/auditory/mel_filterbank_32.c -) - -zephyr_library_sources_ifdef(CONFIG_NATURAL_LOGARITHM_FIXED - ${SOF_MATH_PATH}/log_e.c -) - -zephyr_library_sources_ifdef(CONFIG_BINARY_LOGARITHM_FIXED - ${SOF_MATH_PATH}/base2log.c -) - # SOF module interface functions add_subdirectory(../src/module module_unused_install/) @@ -620,33 +562,6 @@ elseif(CONFIG_COMP_IIR) ) endif() -if(CONFIG_MATH_FIR STREQUAL "m") - add_subdirectory(${SOF_MATH_PATH}/fir_llext - ${PROJECT_BINARY_DIR}/fir_llext) - add_dependencies(app fir) -elseif(CONFIG_MATH_FIR) - zephyr_library_sources( - ${SOF_MATH_PATH}/fir_generic.c - ${SOF_MATH_PATH}/fir_hifi2ep.c - ${SOF_MATH_PATH}/fir_hifi3.c - ${SOF_MATH_PATH}/fir_hifi5.c - ) -endif() - -zephyr_library_sources_ifdef(CONFIG_MATH_IIR_DF1 - ${SOF_MATH_PATH}/iir_df1_generic.c - ${SOF_MATH_PATH}/iir_df1_hifi3.c - ${SOF_MATH_PATH}/iir_df1_hifi4.c - ${SOF_MATH_PATH}/iir_df1_hifi5.c - ${SOF_MATH_PATH}/iir_df1.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_IIR_DF2T - ${SOF_MATH_PATH}/iir_df2t_generic.c - ${SOF_MATH_PATH}/iir_df2t_hifi3.c - ${SOF_MATH_PATH}/iir_df2t.c -) - if(CONFIG_COMP_ASRC STREQUAL "m") add_subdirectory(${SOF_AUDIO_PATH}/asrc/llext ${PROJECT_BINARY_DIR}/asrc_llext) @@ -1034,15 +949,6 @@ elseif(CONFIG_COMP_TDFB) ) endif() -zephyr_library_sources_ifdef(CONFIG_SQRT_FIXED - ${SOF_MATH_PATH}/sqrt_int16.c -) - -zephyr_library_sources_ifdef(CONFIG_MATH_EXP - ${SOF_MATH_PATH}/exp_fcn.c - ${SOF_MATH_PATH}/exp_fcn_hifi.c -) - zephyr_library_sources_ifdef(CONFIG_COMP_UP_DOWN_MIXER ${SOF_AUDIO_PATH}/up_down_mixer/up_down_mixer.c ${SOF_AUDIO_PATH}/up_down_mixer/up_down_mixer_hifi3.c From 09566cde512906cd72569e0f28e0d358b6803f45 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 14 Mar 2025 18:38:08 +0200 Subject: [PATCH 3/4] schedule: trim unnecessary paths from source files Now that cmake rules are moved to same directory as source files, no need to specify the full path for source files. Signed-off-by: Kai Vehmanen --- src/schedule/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/schedule/CMakeLists.txt b/src/schedule/CMakeLists.txt index 35cbfec4f8e5..7646a55191ba 100644 --- a/src/schedule/CMakeLists.txt +++ b/src/schedule/CMakeLists.txt @@ -39,11 +39,11 @@ else() endif() zephyr_library_sources_ifdef(CONFIG_ZEPHYR_DP_SCHEDULER - ${SOF_SRC_PATH}/schedule/zephyr_dp_schedule.c + zephyr_dp_schedule.c ) zephyr_library_sources_ifdef(CONFIG_ZEPHYR_TWB_SCHEDULER - ${SOF_SRC_PATH}/schedule/zephyr_twb_schedule.c + zephyr_twb_schedule.c ) else() ### Not Zephyr ### From 29f495e7d4fe332fd68fd5fbff613d7387e99d87 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 14 Mar 2025 18:40:37 +0200 Subject: [PATCH 4/4] cmake/zephyr: sort the add_subdirectory() statement list Reorder the add_subdirectory() statements to alphabetical order. There will be more entries here, so better to organize this list now. Signed-off-by: Kai Vehmanen --- zephyr/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 5ba4d1aca5f4..aa6a67e754a1 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -198,11 +198,11 @@ macro(add_local_sources_ifdef condition target) zephyr_library_sources_ifdef(${condition} ${ARGN}) endmacro() -add_subdirectory(../src/init/ init_unused_install/) -add_subdirectory(../src/ipc/ ipc_unused_install/) -add_subdirectory(../src/debug/telemetry/ telemetry_unused_install/) add_subdirectory(../src/debug/debug_stream/ debug_stream_unused_install/) +add_subdirectory(../src/debug/telemetry/ telemetry_unused_install/) add_subdirectory(../src/debug/tester/ debug_tester_unused_install/) +add_subdirectory(../src/init/ init_unused_install/) +add_subdirectory(../src/ipc/ ipc_unused_install/) add_subdirectory(../src/math/ math_unused_install/) add_subdirectory(../src/schedule/ schedule_unused_install/) add_subdirectory(test/)