# PhoneRail 宿主机构建 —— 不依赖 ESP-IDF,用来跑单元测试(CTest)。 # # bash host/test.sh 配置 + 编译 + ctest # # 与 IDF 目标共享的源码只有 ../main 里的与硬件无关部分。 # 新增一个既要上板又要被测的 .c,必须同时加进: # ../main/CMakeLists.txt 的 SRCS 和 下面的 PHONERAIL_CORE_SRCS cmake_minimum_required(VERSION 3.16) project(phonerail_host C) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) add_compile_options(-Wall -Wextra -Werror) set(FW_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) # ---- 被测代码 ------------------------------------------------------------- set(PHONERAIL_CORE_SRCS ${FW_ROOT}/main/version.c ) add_library(phonerail_core STATIC ${PHONERAIL_CORE_SRCS}) target_include_directories(phonerail_core PUBLIC ${FW_ROOT}/main) # ---- 测试框架 Unity(从 ESP-IDF v5.4 原样复制到 third_party/,与上板测试同一套) add_library(unity STATIC ${FW_ROOT}/third_party/unity/unity.c) target_include_directories(unity PUBLIC ${FW_ROOT}/third_party/unity) target_compile_definitions(unity PUBLIC UNITY_OUTPUT_COLOR) # 第三方源码不吃本工程的 -Werror target_compile_options(unity PRIVATE -w) # ---- 测试用例:test/test_*.c 一个文件一个可执行 + 一条 ctest --------------- enable_testing() file(GLOB PHONERAIL_TESTS ${FW_ROOT}/test/test_*.c) foreach(test_src ${PHONERAIL_TESTS}) get_filename_component(test_name ${test_src} NAME_WE) add_executable(${test_name} ${test_src}) target_link_libraries(${test_name} PRIVATE phonerail_core unity) add_test(NAME ${test_name} COMMAND ${test_name}) endforeach()