From ffefd959b3d72860f713f9cf199f2640e7f7679f Mon Sep 17 00:00:00 2001 From: Kai Berszin Date: Tue, 9 Dec 2025 14:33:37 +0100 Subject: [PATCH] sw: Allow cluster level overwrites of CMake definitions Less hardcoding of Spatz configurations but instead put the burden on higher-level settings. --- sw/snRuntime/CMakeLists.txt | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/sw/snRuntime/CMakeLists.txt b/sw/snRuntime/CMakeLists.txt index 15d4e420..c817925f 100644 --- a/sw/snRuntime/CMakeLists.txt +++ b/sw/snRuntime/CMakeLists.txt @@ -30,8 +30,25 @@ if(SPATZ_CLUSTER_CFG MATCHES "^(spatz_cluster\.(default|mempool|smallvrf|32b|dou elseif("${SPATZ_CLUSTER_CFG}" MATCHES "^spatz_cluster.carfield\\.(l2|dram)\\.hjson$") set(_plat_folder "cheshire") else() - message(FATAL_ERROR - "Unknown configuration SPATZ_CLUSTER_CFG: ${SPATZ_CLUSTER_CFG} for platform assignment") + if(NOT DEFINED SPATZ_CLUSTER_PLATFORM) + message(WARNING + "Unknown configuration SPATZ_CLUSTER_CFG: ${SPATZ_CLUSTER_CFG} for platform assignment") + else() + message(STATUS + "Overwriting platform with SPATZ_CLUSTER_PLATFORM: ${SPATZ_CLUSTER_PLATFORM}") + set(_plat_folder "${SPATZ_CLUSTER_PLATFORM}") + endif() +endif() + +# 3. Check for platform folder assignment and throw a FATAL_ERROR if missing +if(NOT _plat_folder) + # Check if a platform was set (either by the match above or externally) + # If no platform was set AND the platform folder is missing, throw FATAL_ERROR + message(FATAL_ERROR + "Could not determine platform folder. " + "Configuration 'SPATZ_CLUSTER_CFG' was unmatched AND " + "required variable 'SPATZ_CLUSTER_PLATFORM' is not set.") + endif() set(PLATFORM_SOURCE_FOLDER "src/platforms/${_plat_folder}" CACHE STRING "Path to the platform-specific sources") @@ -60,6 +77,16 @@ string(TOUPPER "${_key}" _key) set(_orig_var "MEM_${_key}_ORIGIN") set(_size_var "MEM_${_key}_SIZE") +if(NOT DEFINED ${_orig_var} AND DEFINED SPATZ_CLUSTER_MEMORY_ORIGIN) + message(STATUS "Overriding memory origin with SPATZ_CLUSTER_MEMORY_ORIGIN: ${SPATZ_CLUSTER_MEMORY_ORIGIN}") + set(_orig_var "SPATZ_CLUSTER_MEMORY_ORIGIN") +endif() + +if(NOT DEFINED ${_size_var} AND DEFINED SPATZ_CLUSTER_MEMORY_SIZE) + message(STATUS "Overriding memory size with SPATZ_CLUSTER_MEMORY_SIZE: ${SPATZ_CLUSTER_MEMORY_SIZE}") + set(_size_var "SPATZ_CLUSTER_MEMORY_SIZE") +endif() + if(DEFINED ${_orig_var} AND DEFINED ${_size_var}) # perform the lookup set(MEM_DRAM_ORIGIN "${${_orig_var}}" CACHE STRING "Base address of external memory")