From ef563ebfe3d5725e197d7de7f46b7e7a7672cf78 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Tue, 31 Oct 2023 06:36:58 +0000 Subject: [PATCH] cmake/zephyr: decentralize src/init/ Adding all source files in a single, giant zephyr/CMakeLists.txt is inconvenient and does not scale. Signed-off-by: Marc Herbert --- scripts/cmake/misc.cmake | 9 +++++++++ src/init/CMakeLists.txt | 16 ++++++++++++++++ zephyr/CMakeLists.txt | 26 +++++++++++++++++++++----- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/scripts/cmake/misc.cmake b/scripts/cmake/misc.cmake index ac68b7627..ee794780c 100644 --- a/scripts/cmake/misc.cmake +++ b/scripts/cmake/misc.cmake @@ -40,6 +40,15 @@ function(get_optimization_flag OUT_VAR) endif() endfunction() +# Zephyr duplicate in sof/zephyr/CMakeLists.txt; keep in sync +macro(is_zephyr ret) + if(CONFIG_ZEPHYR_SOF_MODULE) + set(${ret} TRUE) + else() + set(${ret} FALSE) + endif() +endmacro() + # Adds sources to target like target_sources, but assumes that # paths are relative to subdirectory. # Works like: diff --git a/src/init/CMakeLists.txt b/src/init/CMakeLists.txt index 91c8bb5d9..efa155793 100644 --- a/src/init/CMakeLists.txt +++ b/src/init/CMakeLists.txt @@ -1,5 +1,18 @@ # SPDX-License-Identifier: BSD-3-Clause +is_zephyr(it_is) +if(it_is) ### Zephyr ### + + +zephyr_library_sources( + init.c + ext_manifest.c +) + + +else() ### Not Zephyr ### + + add_local_sources(sof init.c) add_library(ext_manifest STATIC "") @@ -21,3 +34,6 @@ sof_append_relative_path_definitions(ext_manifest) target_link_libraries(ext_manifest sof_options) target_link_libraries(sof_static_libraries INTERFACE ext_manifest) + + +endif() # Zephyr diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 2c7e78222..2e7a26a1b 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -1,7 +1,7 @@ -# This is still WIP - Not fully validated on any platform. - # When west is installed, Zephyr's CMake invokes west to list and try to -# compile every Zephyr module that can be found. +# compile every Zephyr module that can be found. See +# sof/zephyr/module.yml and +# https://docs.zephyrproject.org/latest/develop/modules.html if(CONFIG_SOF) if(CONFIG_LIBRARY) @@ -114,6 +114,24 @@ zephyr_include_directories( # SOC level sources # Files that are commented may not be needed. + +# New, "de-centralized Zephyr" way. Requires "is_zephyr()" conditionals in +# the decentralized CMakeLists.txt files shared with XTOS. + +# XTOS duplicate in sof/scripts/misc.cmake; keep in sync +macro(is_zephyr ret) + if(CONFIG_ZEPHYR_SOF_MODULE) + set(${ret} TRUE) + else() + set(${ret} FALSE) + endif() +endmacro() + +add_subdirectory(../src/init/ init_unused_install/) + + +# Old way below: all .c files added by this giant CMake file. + # Intel TGL and CAVS 2.5 platforms if (CONFIG_SOC_SERIES_INTEL_CAVS_V25) @@ -372,8 +390,6 @@ zephyr_library_sources( ${SOF_AUDIO_PATH}/pipeline/pipeline-xrun.c # SOF core infrastructure - runs on top of Zephyr - ${SOF_SRC_PATH}/init/init.c - ${SOF_SRC_PATH}/init/ext_manifest.c ${SOF_SRC_PATH}/arch/xtensa/drivers/cache_attr.c ${SOF_SRC_PATH}/schedule/zephyr_domain.c ${SOF_SRC_PATH}/schedule/schedule.c