Skip to content

Commit

Permalink
Merge pull request #366 from adafruit/fix-cmake-build
Browse files Browse the repository at this point in the history
Fix cmake build
  • Loading branch information
hathach authored Dec 15, 2023
2 parents ddd10ca + 12f1651 commit db3ffa2
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 106 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build_arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ on:
types:
- created

jobs:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# ---------------------------------------
# Build ARM family
# ---------------------------------------
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/build_cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build CMake

on:
pull_request:
push:
repository_dispatch:
release:
types:
- created

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# ---------------------------------------
# Build ARM family
# ---------------------------------------
ARM:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
board:
# Alphabetical order by family
- 'metro_m7_1011'
- 'stm32f303disco'

steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install Ninja
run: sudo apt install -y ninja-build

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout common submodules in lib
run: git submodule update --init lib/tinyusb lib/uf2

- name: Install ARM GCC
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '11.2-2022.02'

- name: Build
run: |
cmake . -B _build -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DBOARD=${{ matrix.board }}
cmake --build _build
# - uses: actions/upload-artifact@v3
# with:
# name: ${{ matrix.board }}
# path: |
# _build/ports/*/tinyusb.bin
# _build/ports/*/tinyusb.hex
# _build/ports/*/apps/*/*.uf2
20 changes: 10 additions & 10 deletions ports/CMakeLists.txt → CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.17)

include(${CMAKE_CURRENT_LIST_DIR}/family_support.cmake)

# Espressif has its own build system
if(NOT FAMILY STREQUAL espressif)
project(tinyuf2_all C ASM)
endif ()

add_subdirectory(${FAMILY})
cmake_minimum_required(VERSION 3.17)

include(ports/family_support.cmake)

# Espressif has its own build system
if(NOT FAMILY STREQUAL espressif)
project(tinyuf2_all C ASM)
endif ()

add_subdirectory(ports/${FAMILY})
29 changes: 29 additions & 0 deletions ports/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,32 @@ project(tinyuf2)
add_custom_command(TARGET app POST_BUILD
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o ${CMAKE_CURRENT_LIST_DIR}/apps/self_update/main/bootloader_bin.c ${CMAKE_BINARY_DIR}/tinyuf2.bin
)

# Post build: update arduino-esp32 bootloader for debug purpose
if (0)

#set(ARDUINO_VARIANT_DIR /home/hathach/code/arduino-esp32/variants/${BOARD})
set(ARDUINO_VARIANT_DIR /home/hathach/code/arduino-esp32/variants/adafruit_feather_esp32s3)

add_custom_command(TARGET bootloader POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bootloader/bootloader.bin ${ARDUINO_VARIANT_DIR}/bootloader-tinyuf2.bin
)

add_custom_command(TARGET app POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/tinyuf2.bin ${ARDUINO_VARIANT_DIR}/tinyuf2.bin
)

file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/sdkconfig SDKCONFIG_CONTENTS)
foreach (line ${SDKCONFIG_CONTENTS})
if (line MATCHES "CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"(.*).csv\"")
set(PARTITION_TABLE_CSV ${CMAKE_MATCH_1})
cmake_print_variables(PARTITION_TABLE_CSV)
break()
endif ()
endforeach ()

add_custom_command(TARGET app POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/${PARTITION_TABLE_CSV}.csv ${ARDUINO_VARIANT_DIR}/${PARTITION_TABLE_CSV}-tinyuf2.csv
)

endif ()
63 changes: 52 additions & 11 deletions ports/family_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_guard()

include(CMakePrintHelpers)
find_package(Python COMPONENTS Interpreter)
find_package(Git REQUIRED)

# TOP is path to root directory
set(TOP ${CMAKE_CURRENT_LIST_DIR}/..)
Expand Down Expand Up @@ -44,6 +45,11 @@ endif ()
#------------------------------------
# Functions
#------------------------------------

function(family_add_bin_hex TARGET)
# placeholder, will be override by family specific
endfunction()

function(family_add_default_example_warnings TARGET)
# target_compile_options(${TARGET} PUBLIC
# -Wall
Expand Down Expand Up @@ -105,6 +111,10 @@ function(family_configure_common TARGET)
# Generate map file
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")

# All executable target linked with board target
family_add_board_target(board_${BOARD})
target_link_libraries(${TARGET} PUBLIC board_${BOARD})

# ETM Trace option
if (TRACE_ETM STREQUAL "1")
target_compile_definitions(${TARGET} PUBLIC TRACE_ETM)
Expand Down Expand Up @@ -161,26 +171,47 @@ function(family_add_tinyusb TARGET OPT_MCU RTOS)
target_link_libraries(${TARGET} PUBLIC ${TARGET}-tinyusb)
endfunction()


function(family_add_uf2version TARGET DEPS_REPO)
execute_process(COMMAND git describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION)
string(STRIP ${GIT_VERSION} GIT_VERSION)
string(REPLACE ${TOP}/ "" DEPS_REPO "${DEPS_REPO}")
foreach (DEP ${DEPS_REPO})
execute_process(COMMAND ${GIT_EXECUTABLE} -C ${TOP} submodule status ${DEP}
OUTPUT_VARIABLE DEP_VERSION
)
string(STRIP ${DEP_VERSION} DEP_VERSION)
string(FIND "${DEP_VERSION}" " " SPACE_POS)
string(SUBSTRING "${DEP_VERSION}" ${SPACE_POS} -1 DEP_VERSION)
string(STRIP ${DEP_VERSION} DEP_VERSION)

set(GIT_SUBMODULE_VERSIONS "${GIT_SUBMODULE_VERSIONS} ${DEP_VERSION}")
endforeach ()

execute_process(COMMAND bash "-c" "git -C ${TOP}/lib submodule status ${DEPS_REPO} | cut -d\" \" -f3,4 | paste -s -d\" \" -"
OUTPUT_VARIABLE GIT_SUBMODULE_VERSIONS
)
string(REPLACE ../ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})
string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})
string(STRIP ${GIT_SUBMODULE_VERSIONS} GIT_SUBMODULE_VERSIONS)
string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})

cmake_print_variables(GIT_VERSION GIT_SUBMODULE_VERSIONS)
cmake_print_variables(GIT_VERSION)
cmake_print_variables(GIT_SUBMODULE_VERSIONS)

target_compile_definitions(${TARGET} PUBLIC
UF2_VERSION_BASE="${GIT_VERSION}"
UF2_VERSION="${GIT_VERSION} - ${GIT_SUBMODULE_VERSIONS}"
)
endfunction()

function(family_configure_tinyuf2 TARGET OPT_MCU)
family_configure_common(${TARGET})

#target_include_directories(${TARGET} PUBLIC)
#target_compile_definitions(${TARGET} PUBLIC)
include(${TOP}/src/tinyuf2.cmake)
add_tinyuf2(${TARGET})

family_add_uf2version(${TARGET} "${FAMILY_SUBMODULE_DEPS}")

family_add_tinyusb(tinyuf2 ${OPT_MCU} none)
endfunction()

#----------------------------------
# Output
#----------------------------------
Expand Down Expand Up @@ -308,8 +339,18 @@ function(family_flash_uf2 TARGET FAMILY_ID)
)
endfunction()

#----------------------------------
# Family specific
#----------------------------------

include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)

# Family submodules dependencies
if (DEFINED FAMILY_SUBMODULE_DEPS)
foreach(DEP ${FAMILY_SUBMODULE_DEPS})
# Check if the submodule is present. If not, fetch it
if(NOT EXISTS ${DEP}/.git)
string(REPLACE ${TOP}/ "" DEP_REL ${DEP})
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${TOP} submodule update --init ${DEP_REL}
)
endif()
endforeach()
endif ()
18 changes: 2 additions & 16 deletions ports/mimxrt10xx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ project(tinyuf2 C ASM)
#------------------------------------
# TinyUF2
#------------------------------------

set(CMAKE_EXECUTABLE_SUFFIX .elf)

add_executable(tinyuf2
board_flash.c
boards.c
Expand All @@ -22,28 +20,16 @@ target_link_options(tinyuf2 PUBLIC
"LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/linker/common.ld"
)

family_configure_common(tinyuf2)

# add board target
add_board_target(board_${BOARD})
target_link_libraries(tinyuf2 PUBLIC board_${BOARD})

# Add tinyusb target
family_add_tinyusb(tinyuf2 OPT_MCU_MIMXRT1XXX none)

# Add tinyuf2
include(${TOP}/src/tinyuf2.cmake)
add_tinyuf2(tinyuf2)
family_configure_tinyuf2(tinyuf2 OPT_MCU_MIMXRT1XXX)

family_flash_sdp(tinyuf2)
family_flash_jlink(tinyuf2 hex)
family_add_uf2(tinyuf2 ${UF2_FAMILY_ID} bin ${UF2_ADDR})
family_flash_uf2(tinyuf2 ${UF2_FAMILY_ID})

#------------------------------------
# Application (including self update)
# Application (e.g self update)
#------------------------------------

add_subdirectory(apps/erase_firmware)

if (BOARD STREQUAL metro_m7_1011)
Expand Down
6 changes: 2 additions & 4 deletions ports/mimxrt10xx/apps/app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ function(configure_app TARGET)
"LINKER:--script=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../linker/common.ld"
)

family_add_bin_hex(${TARGET})
family_add_uf2(${TARGET} ${UF2_FAMILY_ID})

family_flash_uf2(${TARGET} ${UF2_FAMILY_ID})
#family_flash_jlink(${TARGET} hex)
family_flash_pyocd(${TARGET} hex)
family_flash_jlink(${TARGET} hex)
#family_flash_pyocd(${TARGET} hex)
endfunction()
5 changes: 4 additions & 1 deletion ports/mimxrt10xx/apps/erase_firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ include(${CMAKE_CURRENT_LIST_DIR}/../app.cmake)
#------------------------------------
add_executable(erase_firmware
${TOP}/apps/erase_firmware/erase_firmware.c
${CMAKE_CURRENT_LIST_DIR}/../../boards.c
)
target_include_directories(erase_firmware PUBLIC
${TOP}/src
)
target_compile_definitions(erase_firmware PUBLIC
BUILD_NO_TINYUSB
)

configure_app(erase_firmware)
target_link_libraries(erase_firmware PUBLIC board_${BOARD})
2 changes: 0 additions & 2 deletions ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ target_include_directories(esp32programmer PUBLIC
)

configure_app(esp32programmer)

target_link_libraries(esp32programmer PUBLIC board_${BOARD})
family_add_tinyusb(esp32programmer OPT_MCU_MIMXRT1XXX none)
2 changes: 0 additions & 2 deletions ports/mimxrt10xx/apps/factory_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ target_include_directories(factory_test PUBLIC
)

configure_app(factory_test)

target_link_libraries(factory_test PUBLIC board_${BOARD})
family_add_tinyusb(factory_test OPT_MCU_MIMXRT1XXX none)
3 changes: 0 additions & 3 deletions ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ include(middleware-sdmmc/CMakeLists.txt)
add_sdmmc(factory_test_metro_sd)

configure_app(factory_test_metro_sd)

target_link_libraries(factory_test_metro_sd PUBLIC board_${BOARD})
family_add_tinyusb(factory_test_metro_sd OPT_MCU_MIMXRT1XXX none)


#------------------------------------
#
#------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions ports/mimxrt10xx/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ endif ()
set(UF2_FAMILY_ID 0x4fb2d5bd)
set(SDK_DIR ${TOP}/lib/nxp/mcux-sdk)
set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
set(FAMILY_SUBMODULE_DEPS ${SDK_DIR})

include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)

Expand Down Expand Up @@ -62,7 +63,7 @@ string(REGEX REPLACE ".*= *(0x[0-9a-fA-F]+).*" "\\1" IVT_ORIGIN ${IVT_ORIGIN})
# BOARD_TARGET
#------------------------------------
# used by all executable targets
function(add_board_target BOARD_TARGET)
function(family_add_board_target BOARD_TARGET)
if (TARGET ${BOARD_TARGET})
return()
endif ()
Expand Down Expand Up @@ -113,8 +114,7 @@ function(add_board_target BOARD_TARGET)
XIP_BOOT_HEADER_ENABLE=1
)
target_link_options(${BOARD_TARGET} PUBLIC
--specs=nosys.specs
--specs=nano.specs
--specs=nosys.specs --specs=nano.specs
)
endfunction()

Expand Down
20 changes: 10 additions & 10 deletions ports/stm32f3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ project(tinyuf2 C ASM)
#------------------------------------
# TinyUF2
#------------------------------------

set(CMAKE_EXECUTABLE_SUFFIX .elf)
add_executable(tinyuf2)

target_sources(tinyuf2 PUBLIC
add_executable(tinyuf2
board_flash.c
boards.c
boards.h
${TOP}/lib/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
)
#target_compile_options(tinyuf2 PUBLIC)
#target_link_options(tinyuf2 PUBLIC)

family_configure_tinyuf2(tinyuf2)
target_link_options(tinyuf2 PUBLIC
"LINKER:--script=${CMAKE_CURRENT_LIST_DIR}/linker/stm32f3_boot.ld"
)

family_add_bin_hex(tinyuf2)
family_configure_tinyuf2(tinyuf2 OPT_MCU_STM32F3)
family_flash_jlink(tinyuf2)

# Self Update
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/self_update)
#------------------------------------
# Application (e.g self update)
#------------------------------------
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps/self_update)
Loading

0 comments on commit db3ffa2

Please sign in to comment.