summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt84
1 files changed, 71 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 100214c..9fa048f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,12 @@
# CMakeLists.txt - Main per-platform build script for sbc-harness project
#
-# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
cmake_minimum_required(VERSION 3.30)
if (NOT PICO_PLATFORM)
- message(FATAL_ERROR "PICO_PLATFORM must be specified; use the GNUmakefile to set this")
+ 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")
@@ -14,21 +14,45 @@ include("${PICO_SDK_PATH}/external/pico_sdk_import.cmake")
project(sbc_harness)
+add_subdirectory(3rd-party/pico-fmt/pico_fmt)
+add_subdirectory(3rd-party/pico-fmt/pico_printf)
pico_sdk_init()
-add_compile_options(-Wall -Wextra -Werror)
+if ((PICO_PLATFORM STREQUAL "host") AND (NOT PICO_NO_GC_SECTIONS))
+ # On non-host builds, this is done by `pico_standard_link`.
+ add_compile_options(-ffunction-sections -fdata-sections)
+ add_link_options("LINKER:--gc-sections")
+endif()
+
+add_compile_options(-Wall -Wextra -Wswitch-enum -Werror)
+
+string(TOUPPER "${CMAKE_BUILD_TYPE}" _upper_cmake_build_type)
+string(REPLACE " " ";" _build_type_flags "${CMAKE_C_FLAGS_${_upper_cmake_build_type}}")
+if ("-DNDEBUG" IN_LIST _build_type_flags)
+ add_compile_options(-Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable)
+ target_compile_definitions(pico_printf INTERFACE PICO_PRINTF_ALWAYS_INCLUDED=1)
+endif()
-function(target_embed_sources arg_target arg_hdrname)
+function(_suppress_tinyusb_warnings)
+ __suppress_tinyusb_warnings()
+ set_source_files_properties(
+ ${PICO_TINYUSB_PATH}/src/device/usbd.c
+ PROPERTIES
+ COMPILE_OPTIONS "-Wno-switch-enum")
+endfunction()
+
+function(target_embed_sources arg_compile_target arg_link_target arg_hdrname)
set(embed_objs)
foreach(embed_src IN LISTS ARGN)
add_custom_command(
- OUTPUT "${embed_src}.obj"
+ OUTPUT "${embed_src}.o"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND mkdir -p -- "$<PATH:GET_PARENT_PATH,${CMAKE_CURRENT_BINARY_DIR}/${embed_src}>" &&
- ${CMAKE_LINKER} -r -b binary -o "${CMAKE_CURRENT_BINARY_DIR}/${embed_src}.obj" "${embed_src}"
+ ${CMAKE_LINKER} -r -b binary -o "${CMAKE_CURRENT_BINARY_DIR}/${embed_src}.o" "${embed_src}" &&
+ ${CMAKE_OBJCOPY} --rename-section .data=.rodata,alloc,load,readonly,data,contents "${CMAKE_CURRENT_BINARY_DIR}/${embed_src}.o" "${CMAKE_CURRENT_BINARY_DIR}/${embed_src}.o"
DEPENDS "${embed_src}"
)
- list(APPEND embed_objs "${embed_src}.obj")
+ list(APPEND embed_objs "${embed_src}.o")
endforeach()
set_source_files_properties("${embed_objs}" PROPERTIES
EXTERNAL_OBJECT true
@@ -45,7 +69,8 @@ function(target_embed_sources arg_target arg_hdrname)
DEPENDS "${embed_objs}" "${CMAKE_SOURCE_DIR}/build-aux/embed-sources.h.gen"
)
- target_sources("${arg_target}" PRIVATE "${embed_objs}" "${arg_hdrname}")
+ target_sources("${arg_compile_target}" PRIVATE "${arg_hdrname}")
+ target_sources("${arg_link_target}" PRIVATE "${embed_objs}")
endfunction()
function(add_stack_analysis arg_outfile arg_objlib_target)
@@ -55,20 +80,53 @@ function(add_stack_analysis arg_outfile arg_objlib_target)
)
add_custom_command(
OUTPUT "${arg_outfile}"
- COMMAND "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen" "$<TARGET_OBJECTS:${arg_objlib_target}>" >"${arg_outfile}"
+ COMMAND "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen" "${PICO_PLATFORM}" "${CMAKE_SOURCE_DIR}" "$<TARGET_OBJECTS:${arg_objlib_target}>" >"${arg_outfile}"
COMMAND_EXPAND_LISTS
- DEPENDS "$<TARGET_OBJECTS:${arg_objlib_target}>" "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen"
+ DEPENDS "$<TARGET_OBJECTS:${arg_objlib_target}>"
+ "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/__init__.py"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/analyze.py"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/app_main.py"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/app_output.py"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/app_plugins.py"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/test_analyze.py"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/util.py"
+ "${CMAKE_SOURCE_DIR}/build-aux/measurestack/vcg.py"
COMMENT "Calculating ${arg_objlib_target} required stack sizes"
)
endfunction()
+include(CTest)
+if (NOT DEFINED ENABLE_TESTS)
+ if (PICO_PLATFORM STREQUAL "host")
+ set(ENABLE_TESTS 1)
+ else()
+ set(ENABLE_TESTS 0)
+ endif()
+endif()
+
+function(add_lib_test arg_libname arg_testname)
+ if (ENABLE_TESTS)
+ add_executable("${arg_testname}" "tests/${arg_testname}.c")
+ target_link_libraries("${arg_testname}" "${arg_libname}")
+ target_include_directories("${arg_testname}" PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
+ add_test(
+ NAME "${arg_libname}/${arg_testname}"
+ COMMAND "${CMAKE_SOURCE_DIR}/build-aux/valgrind" "./${arg_testname}"
+ )
+ endif()
+endfunction()
+
+add_subdirectory(libmisc)
+add_subdirectory(libobj)
+add_subdirectory(libfmt)
add_subdirectory(libcr)
add_subdirectory(libcr_ipc)
-add_subdirectory(libmisc)
-add_subdirectory(libhw)
+add_subdirectory(libhw_generic)
+add_subdirectory(libhw_cr)
add_subdirectory(libdhcp)
add_subdirectory(libusb)
add_subdirectory(lib9p)
+add_subdirectory(lib9p_util)
add_subdirectory(cmd/sbc_harness)
-add_subdirectory(cmd/srv9p)