From 330d73eec17e147449b3187a19d3fc3a5bb364c4 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 17 Nov 2023 20:50:23 +0000 Subject: [PATCH] cmake: a few new add_local_sources[_ifdef]() compatibility macros For reducing CMake duplication and centralization, see #8260 Not used yet. Signed-off-by: Marc Herbert --- scripts/cmake/misc.cmake | 9 +++++++++ zephyr/CMakeLists.txt | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/scripts/cmake/misc.cmake b/scripts/cmake/misc.cmake index ee794780c..77ae05ee2 100644 --- a/scripts/cmake/misc.cmake +++ b/scripts/cmake/misc.cmake @@ -49,6 +49,15 @@ macro(is_zephyr ret) endif() endmacro() +# This macro +# - saves a LOT of repetition, and +# - mimics Zephyr, which helps with compatibility. +macro(add_local_sources_ifdef condition target) + if(${condition}) + add_local_sources(${target} ${ARGN}) + endif() +endmacro() + # Adds sources to target like target_sources, but assumes that # paths are relative to subdirectory. # Works like: diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 8ea073b87..a85928210 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -128,6 +128,22 @@ macro(is_zephyr ret) endif() endmacro() +# Wrappers for compatibility and re-use of existing, XTOS CMake files. +# Do NOT use these macros in this file or in any other Zephyr-specific +# CMake code. +macro(add_local_sources target) + if (NOT "${target}" STREQUAL "sof") + message(FATAL_ERROR "add_local_sources() target is not 'sof'") + endif() + zephyr_library_sources(${ARGN}) +endmacro() +macro(add_local_sources_ifdef condition target) + if (NOT "${target}" STREQUAL "sof") + message(FATAL_ERROR "add_local_sources_ifdef() target is not 'sof'") + endif() + zephyr_library_sources_ifdef(${condition} ${ARGN}) +endmacro() + add_subdirectory(../src/init/ init_unused_install/) add_subdirectory(../src/ipc/ ipc_unused_install/)