Skip to content

Commit 23ccf11

Browse files
committed
update cmake
1 parent 1687382 commit 23ccf11

File tree

5 files changed

+101
-111
lines changed

5 files changed

+101
-111
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,13 @@ jobs:
120120
# Build ARM with CMake
121121
# ---------------------------------------
122122
arm-cmake:
123-
if: false
124123
runs-on: ubuntu-latest
125124
strategy:
126125
fail-fast: false
127126
matrix:
128127
board:
129128
# Alphabetical order by family
130-
- 'metro_m7_1011'
129+
#- 'metro_m7_1011'
131130
# - 'stm32f303disco' # overflows flash
132131
- 'stm32f411ve_discovery'
133132

ports/family_support.cmake

Lines changed: 97 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
1-
include_guard()
1+
include_guard(GLOBAL)
22

33
include(CMakePrintHelpers)
44
find_package(Python COMPONENTS Interpreter)
55
find_package(Git REQUIRED)
66

77
# TOP is path to root directory
88
set(TOP ${CMAKE_CURRENT_LIST_DIR}/..)
9-
#get_filename_component(TOP "${TOP}" REALPATH)
9+
get_filename_component(TOP ${TOP} ABSOLUTE)
10+
11+
set(UF2CONV_PY ${TOP}/lib/uf2/utils/uf2conv.py)
12+
13+
#-------------------------------------------------------------
14+
# Toolchain
15+
# Can be changed via -DTOOLCHAIN=gcc|iar or -DCMAKE_C_COMPILER=
16+
#-------------------------------------------------------------
17+
# Detect toolchain based on CMAKE_C_COMPILER
18+
if (DEFINED CMAKE_C_COMPILER)
19+
string(FIND ${CMAKE_C_COMPILER} "iccarm" IS_IAR)
20+
string(FIND ${CMAKE_C_COMPILER} "clang" IS_CLANG)
21+
string(FIND ${CMAKE_C_COMPILER} "gcc" IS_GCC)
22+
23+
if (NOT IS_IAR EQUAL -1)
24+
set(TOOLCHAIN iar)
25+
elseif (NOT IS_CLANG EQUAL -1)
26+
set(TOOLCHAIN clang)
27+
elseif (NOT IS_GCC EQUAL -1)
28+
set(TOOLCHAIN gcc)
29+
endif ()
30+
endif ()
1031

11-
# Default to gcc
1232
if (NOT DEFINED TOOLCHAIN)
1333
set(TOOLCHAIN gcc)
1434
endif ()
1535

36+
#-------------------------------------------------------------
37+
# FAMILY and BOARD
38+
#-------------------------------------------------------------
1639
if (NOT BOARD)
1740
message(FATAL_ERROR "BOARD not specified")
1841
endif ()
@@ -33,8 +56,6 @@ if (NOT DEFINED FAMILY)
3356
list(GET BOARD_PATH 0 FAMILY)
3457
endif ()
3558

36-
set(UF2CONV_PY ${TOP}/lib/uf2/utils/uf2conv.py)
37-
3859
# enable LTO if supported
3960
include(CheckIPOSupported)
4061
check_ipo_supported(RESULT IPO_SUPPORTED)
@@ -50,29 +71,34 @@ function(family_add_bin_hex TARGET)
5071
# placeholder, will be override by family specific
5172
endfunction()
5273

53-
function(family_add_default_example_warnings TARGET)
54-
# target_compile_options(${TARGET} PUBLIC
55-
# -Wall
56-
# -Wextra
57-
# -Werror
58-
# -Wfatal-errors
59-
# -Wdouble-promotion
60-
# -Wfloat-equal
61-
# -Wshadow
62-
# -Wwrite-strings
63-
# -Wsign-compare
64-
# -Wmissing-format-attribute
65-
# -Wunreachable-code
66-
# -Wcast-align
67-
# -Wcast-qual
68-
# -Wnull-dereference
69-
# -Wuninitialized
70-
# -Wunused
71-
# -Wredundant-decls
72-
# #-Wstrict-prototypes
73-
# #-Werror-implicit-function-declaration
74-
# #-Wundef
75-
# )
74+
function(family_add_default_warnings TARGET)
75+
target_compile_options(${TARGET} PUBLIC
76+
-Wall
77+
-Wextra
78+
#-Werror
79+
-Wfatal-errors
80+
-Wdouble-promotion
81+
-Wstrict-prototypes
82+
-Wstrict-overflow
83+
-Werror-implicit-function-declaration
84+
-Wfloat-equal
85+
-Wundef
86+
-Wshadow
87+
-Wwrite-strings
88+
-Wsign-compare
89+
-Wmissing-format-attribute
90+
-Wunreachable-code
91+
-Wcast-align
92+
-Wcast-function-type
93+
-Wcast-qual
94+
-Wnull-dereference
95+
-Wuninitialized
96+
-Wunused
97+
-Wunused-function
98+
-Wreturn-type
99+
-Wredundant-decls
100+
-Wmissing-prototypes
101+
)
76102

77103
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
78104
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
@@ -98,19 +124,18 @@ endfunction()
98124

99125

100126
function(family_configure_common TARGET)
101-
# run size after build
102-
add_custom_command(TARGET ${TARGET} POST_BUILD
103-
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET}>
104-
)
105-
106-
# add hex, bin and uf2 targets
107-
family_add_bin_hex(${TARGET})
108-
109-
# Add warnings flags
127+
# Add BOARD_${BOARD} define
128+
string(TOUPPER ${BOARD} BOARD_UPPER)
129+
string(REPLACE "-" "_" BOARD_UPPER ${BOARD_UPPER})
130+
target_compile_definitions(${TARGET} PUBLIC
131+
BOARD_${BOARD_UPPER}
132+
)
110133

111-
# Generate map file
112-
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
113-
#family_add_linkermap(${TARGET})
134+
# compile define from command line
135+
if(DEFINED CFLAGS_CLI)
136+
separate_arguments(CFLAGS_CLI)
137+
target_compile_options(${TARGET} PUBLIC ${CFLAGS_CLI})
138+
endif()
114139

115140
# executable target linked with board target
116141
family_add_board_target(board_${BOARD})
@@ -127,88 +152,60 @@ function(family_configure_common TARGET)
127152

128153
# Add segger rtt to example
129154
if(LOGGER STREQUAL "RTT" OR LOGGER STREQUAL "rtt")
130-
if (NOT TARGET segger_rtt)
131-
add_library(segger_rtt STATIC ${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c)
132-
target_include_directories(segger_rtt PUBLIC ${TOP}/lib/SEGGER_RTT/RTT)
133-
endif()
134-
target_link_libraries(${TARGET} PUBLIC segger_rtt)
155+
target_sources(${TARGET} PUBLIC ${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c)
156+
target_include_directories(${TARGET} PUBLIC ${TOP}/lib/SEGGER_RTT/RTT)
157+
# target_compile_definitions(${TARGET} PUBLIC SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL)
135158
endif ()
136159
endif ()
160+
161+
family_add_default_warnings(${TARGET})
162+
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
163+
164+
# run size after build
165+
add_custom_command(TARGET ${TARGET} POST_BUILD
166+
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET}>
167+
)
168+
169+
# add hex, bin and uf2 targets
170+
family_add_bin_hex(${TARGET})
171+
137172
endfunction()
138173

139174

140175
# Add tinyusb to example
141-
function(family_add_tinyusb TARGET OPT_MCU RTOS)
142-
# tinyusb target is built for each example since it depends on example's tusb_config.h
143-
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
144-
add_library(${TARGET}-tinyusb_config INTERFACE)
145-
146-
# path to tusb_config.h
147-
target_include_directories(${TARGET}-tinyusb_config INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
148-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_MCU=${OPT_MCU})
176+
function(family_add_tinyusb TARGET OPT_MCU)
177+
# tinyusb's CMakeList.txt
178+
add_subdirectory(${TOP}/lib/tinyusb/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
149179

180+
# Add TinyUSB sources, include and common define
181+
tinyusb_target_add(${TARGET})
182+
target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_MCU=${OPT_MCU})
150183
if (DEFINED LOG)
151-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_DEBUG=${LOG})
152-
if (LOG STREQUAL "4")
153-
# no inline for debug level 4
154-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE TU_ATTR_ALWAYS_INLINE=)
184+
target_compile_definitions(${TARGET} PUBLIC CFG_TUSB_DEBUG=${LOG})
185+
if (LOG STREQUAL "4") # no inline for debug level 4
186+
target_compile_definitions(${TARGET} PUBLIC TU_ATTR_ALWAYS_INLINE=)
155187
endif ()
156188
endif()
189+
endfunction()
157190

158-
if (RTOS STREQUAL "freertos")
159-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_OS=OPT_OS_FREERTOS)
160-
endif ()
161-
162-
# tinyusb's CMakeList.txt
163-
add_subdirectory(${TOP}/lib/tinyusb/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
191+
function(family_configure_tinyuf2 TARGET OPT_MCU)
192+
family_configure_common(${TARGET})
164193

165-
if (RTOS STREQUAL "freertos")
166-
target_link_libraries(${TARGET}-tinyusb PUBLIC freertos_kernel)
167-
endif ()
194+
include(${TOP}/src/tinyuf2.cmake)
195+
add_tinyuf2(${TARGET})
168196

169-
# tinyusb depends on board target for low level mcu header and function
170-
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
171-
target_link_libraries(${TARGET} PUBLIC ${TARGET}-tinyusb)
172-
endfunction()
197+
family_add_tinyusb(${TARGET} ${OPT_MCU})
173198

174-
function(family_add_uf2version TARGET DEPS_REPO)
199+
# Add uf2 version
175200
execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION)
176201
string(STRIP ${GIT_VERSION} GIT_VERSION)
177-
# string(REPLACE ${TOP}/ "" DEPS_REPO "${DEPS_REPO}")
178-
# foreach (DEP ${DEPS_REPO})
179-
# execute_process(COMMAND ${GIT_EXECUTABLE} -C ${TOP} submodule status ${DEP}
180-
# OUTPUT_VARIABLE DEP_VERSION
181-
# )
182-
# string(STRIP ${DEP_VERSION} DEP_VERSION)
183-
# string(FIND "${DEP_VERSION}" " " SPACE_POS)
184-
# string(SUBSTRING "${DEP_VERSION}" ${SPACE_POS} -1 DEP_VERSION)
185-
# string(STRIP ${DEP_VERSION} DEP_VERSION)
186-
#
187-
# set(GIT_SUBMODULE_VERSIONS "${GIT_SUBMODULE_VERSIONS} ${DEP_VERSION}")
188-
# endforeach ()
189-
#
190-
# string(STRIP ${GIT_SUBMODULE_VERSIONS} GIT_SUBMODULE_VERSIONS)
191-
# string(REPLACE lib/ "" GIT_SUBMODULE_VERSIONS ${GIT_SUBMODULE_VERSIONS})
192-
193202
cmake_print_variables(GIT_VERSION)
194-
cmake_print_variables(GIT_SUBMODULE_VERSIONS)
195-
196203
target_compile_definitions(${TARGET} PUBLIC
197204
UF2_VERSION_BASE="${GIT_VERSION}"
198-
UF2_VERSION="${GIT_VERSION} - ${GIT_SUBMODULE_VERSIONS}"
205+
UF2_VERSION="${GIT_VERSION}"
199206
)
200207
endfunction()
201208

202-
function(family_configure_tinyuf2 TARGET OPT_MCU)
203-
family_configure_common(${TARGET})
204-
205-
include(${TOP}/src/tinyuf2.cmake)
206-
add_tinyuf2(${TARGET})
207-
208-
family_add_uf2version(${TARGET} "${FAMILY_SUBMODULE_DEPS}")
209-
family_add_tinyusb(${TARGET} ${OPT_MCU} none)
210-
endfunction()
211-
212209

213210
# Add bin/hex output
214211
function(family_add_bin_hex TARGET)
@@ -239,12 +236,6 @@ function(family_add_uf2 TARGET FAMILY_ID)
239236
VERBATIM)
240237
endfunction()
241238

242-
function(family_add_linkermap TARGET)
243-
add_custom_command(TARGET ${TARGET} POST_BUILD
244-
COMMAND linkermap -v $<TARGET_FILE:${TARGET}>.map
245-
VERBATIM)
246-
endfunction()
247-
248239
#----------------------------------
249240
# Flashing target
250241
#----------------------------------

ports/mimxrt10xx/apps/esp32programmer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ target_include_directories(esp32programmer PUBLIC
2121
)
2222

2323
configure_app(esp32programmer)
24-
family_add_tinyusb(esp32programmer OPT_MCU_MIMXRT1XXX none)
24+
family_add_tinyusb(esp32programmer OPT_MCU_MIMXRT1XXX)

ports/mimxrt10xx/apps/factory_test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ target_include_directories(factory_test PUBLIC
2222
)
2323

2424
configure_app(factory_test)
25-
family_add_tinyusb(factory_test OPT_MCU_MIMXRT1XXX none)
25+
family_add_tinyusb(factory_test OPT_MCU_MIMXRT1XXX)

ports/mimxrt10xx/apps/factory_test_metro_sd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ include(middleware-sdmmc/CMakeLists.txt)
2828
add_sdmmc(factory_test_metro_sd)
2929

3030
configure_app(factory_test_metro_sd)
31-
family_add_tinyusb(factory_test_metro_sd OPT_MCU_MIMXRT1XXX none)
31+
family_add_tinyusb(factory_test_metro_sd OPT_MCU_MIMXRT1XXX)
3232

3333
#------------------------------------
3434
#

0 commit comments

Comments
 (0)