From 3c81186daf97cf7011fd2806dfd0bc3b875e92f3 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 31 Oct 2024 15:39:37 -0600 Subject: Clean up the build system --- CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6655b0a..100214c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,11 +6,11 @@ cmake_minimum_required(VERSION 3.30) if (NOT PICO_PLATFORM) - message(FATAL_ERROR "PICO_PLATFORM must be specified") + message(FATAL_ERROR "PICO_PLATFORM must be specified; use the GNUmakefile to set this") endif() set(PICO_SDK_PATH "${CMAKE_SOURCE_DIR}/3rd-party/pico-sdk") -include(pico_sdk_import.cmake) +include("${PICO_SDK_PATH}/external/pico_sdk_import.cmake") project(sbc_harness) @@ -18,6 +18,50 @@ pico_sdk_init() add_compile_options(-Wall -Wextra -Werror) +function(target_embed_sources arg_target arg_hdrname) + set(embed_objs) + foreach(embed_src IN LISTS ARGN) + add_custom_command( + OUTPUT "${embed_src}.obj" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND mkdir -p -- "$" && + ${CMAKE_LINKER} -r -b binary -o "${CMAKE_CURRENT_BINARY_DIR}/${embed_src}.obj" "${embed_src}" + DEPENDS "${embed_src}" + ) + list(APPEND embed_objs "${embed_src}.obj") + endforeach() + set_source_files_properties("${embed_objs}" PROPERTIES + EXTERNAL_OBJECT true + GENERATED true + ) + + set_source_files_properties("${arg_hdrname}" PROPERTIES + GENERATED true + ) + add_custom_command( + OUTPUT "${arg_hdrname}" + COMMAND "${CMAKE_SOURCE_DIR}/build-aux/embed-sources.h.gen" "${embed_objs}" >"${arg_hdrname}" + COMMAND_EXPAND_LISTS + DEPENDS "${embed_objs}" "${CMAKE_SOURCE_DIR}/build-aux/embed-sources.h.gen" + ) + + target_sources("${arg_target}" PRIVATE "${embed_objs}" "${arg_hdrname}") +endfunction() + +function(add_stack_analysis arg_outfile arg_objlib_target) + target_compile_options("${arg_objlib_target}" PUBLIC "-fcallgraph-info=su,da") + set_source_files_properties("${arg_outfile}" PROPERTIES + GENERATED true + ) + add_custom_command( + OUTPUT "${arg_outfile}" + COMMAND "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen" "$" >"${arg_outfile}" + COMMAND_EXPAND_LISTS + DEPENDS "$" "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen" + COMMENT "Calculating ${arg_objlib_target} required stack sizes" + ) +endfunction() + add_subdirectory(libcr) add_subdirectory(libcr_ipc) add_subdirectory(libmisc) -- cgit v1.2.3-2-g168b