Skip to content

Commit e7090c7

Browse files
committed
cmake refactor
1 parent ba3d71b commit e7090c7

File tree

12 files changed

+112
-197
lines changed

12 files changed

+112
-197
lines changed

.github/workflows/build_arm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- 'stm32f0 stm32f1 stm32f2 stm32f3'
4747
- 'stm32f4'
4848
- 'stm32f7'
49-
- 'stm32g4 stm32h7'
49+
- 'stm32h7'
5050
- 'stm32l0 stm32l4 stm32u5 stm32wb'
5151
- 'tm4c123 xmc4000'
5252
steps:

.github/workflows/cmake_arm.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
- 'imxrt'
3939
- 'rp2040'
4040
- 'stm32g0'
41+
- 'stm32g4'
4142
steps:
4243
- name: Setup Python
4344
uses: actions/setup-python@v4
@@ -75,11 +76,11 @@ jobs:
7576
# Upload binaries for hardware test with self-hosted
7677
- name: Prepare rp2040 Artifacts
7778
if: contains(matrix.family, 'rp2040') && github.repository_owner == 'hathach'
78-
working-directory: ${{github.workspace}}/cmake-build-ci-raspberry_pi_pico
79+
working-directory: ${{github.workspace}}/cmake-build/cmake-build-raspberry_pi_pico
7980
run: |
80-
find device/ -name "*.elf" -exec mv {} ../ \;
81-
# find host/ -name "*.elf" -exec mv {} ../ \;
82-
# find dual/ -name "*.elf" -exec mv {} ../ \;
81+
find device/ -name "*.elf" -exec mv {} ../../ \;
82+
# find host/ -name "*.elf" -exec mv {} ../../ \;
83+
# find dual/ -name "*.elf" -exec mv {} ../../ \;
8384
8485
- name: Upload Artifacts for rp2040
8586
if: contains(matrix.family,'rp2040') && github.repository_owner == 'hathach'

hw/bsp/family_support.cmake

Lines changed: 72 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ endfunction()
8484

8585

8686
function(family_initialize_project PROJECT DIR)
87-
# set output suffix to .elf (skip espressif)
88-
if(NOT FAMILY STREQUAL "espressif")
87+
# set output suffix to .elf (skip espressif and rp2040)
88+
if(NOT FAMILY STREQUAL "espressif" AND NOT FAMILY STREQUAL "rp2040")
8989
set(CMAKE_EXECUTABLE_SUFFIX .elf PARENT_SCOPE)
9090
endif()
9191

@@ -144,6 +144,11 @@ function(family_add_default_example_warnings TARGET)
144144
endfunction()
145145

146146

147+
#------------------------------------
148+
# Main target configure
149+
#------------------------------------
150+
151+
# Add common configuration to example
147152
function(family_configure_common TARGET)
148153
# run size after build
149154
add_custom_command(TARGET ${TARGET} POST_BUILD
@@ -158,6 +163,66 @@ function(family_configure_common TARGET)
158163
endfunction()
159164

160165

166+
# configure an executable target to link to tinyusb in device mode, and add the board implementation
167+
function(family_configure_device_example TARGET)
168+
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
169+
endfunction()
170+
171+
172+
# configure an executable target to link to tinyusb in host mode, and add the board implementation
173+
function(family_configure_host_example TARGET)
174+
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
175+
endfunction()
176+
177+
178+
# Add tinyusb to example
179+
function(family_add_tinyusb TARGET OPT_MCU)
180+
# tinyusb target is built for each example since it depends on example's tusb_config.h
181+
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
182+
add_library(${TARGET}-tinyusb_config INTERFACE)
183+
184+
target_include_directories(${TARGET}-tinyusb_config INTERFACE
185+
${CMAKE_CURRENT_SOURCE_DIR}/src
186+
)
187+
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
188+
CFG_TUSB_MCU=${OPT_MCU}
189+
)
190+
191+
# tinyusb's CMakeList.txt
192+
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
193+
endfunction()
194+
195+
196+
# Add freeRTOS support to example
197+
function(family_add_freertos TARGET)
198+
# freeros config
199+
if (NOT TARGET freertos_config)
200+
add_library(freertos_config INTERFACE)
201+
target_include_directories(freertos_config SYSTEM INTERFACE
202+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig
203+
)
204+
endif()
205+
206+
# freertos kernel should be generic as freertos_config however, CMAKE complains with missing variable
207+
# such as CMAKE_C_COMPILE_OBJECT
208+
if (NOT TARGET freertos_kernel)
209+
add_subdirectory(${TOP}/lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR}/lib/freertos_kernel)
210+
endif ()
211+
212+
# Add FreeRTOS option to tinyusb_config
213+
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
214+
CFG_TUSB_OS=OPT_OS_FREERTOS
215+
)
216+
# link tinyusb with freeRTOS kernel
217+
target_link_libraries(${TARGET}-tinyusb PUBLIC
218+
freertos_kernel
219+
)
220+
target_link_libraries(${TARGET} PUBLIC
221+
freertos_kernel
222+
)
223+
endfunction()
224+
225+
161226
# Add bin/hex output
162227
function(family_add_bin_hex TARGET)
163228
add_custom_command(TARGET ${TARGET} POST_BUILD
@@ -167,6 +232,10 @@ function(family_add_bin_hex TARGET)
167232
endfunction()
168233

169234

235+
#----------------------------------
236+
# Flashing target
237+
#----------------------------------
238+
170239
# Add flash jlink target
171240
function(family_flash_jlink TARGET)
172241
if (NOT DEFINED JLINKEXE)
@@ -233,48 +302,7 @@ function(family_flash_nxplink TARGET)
233302
endfunction()
234303

235304

236-
# configure an executable target to link to tinyusb in device mode, and add the board implementation
237-
function(family_configure_device_example TARGET)
238-
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
239-
endfunction()
240-
241-
242-
# configure an executable target to link to tinyusb in host mode, and add the board implementation
243-
function(family_configure_host_example TARGET)
244-
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
245-
endfunction()
246-
247-
248-
# Add freeRTOS support to example, can be overridden by FAMILY/family.cmake
249-
function(family_add_freertos TARGET)
250-
# freeros config
251-
if (NOT TARGET freertos_config)
252-
add_library(freertos_config INTERFACE)
253-
target_include_directories(freertos_config SYSTEM INTERFACE
254-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig
255-
)
256-
endif()
257-
258-
# freertos kernel should be generic as freertos_config however, CMAKE complains with missing variable
259-
# such as CMAKE_C_COMPILE_OBJECT
260-
if (NOT TARGET freertos_kernel)
261-
add_subdirectory(${TOP}/lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR}/lib/freertos_kernel)
262-
endif ()
263-
264-
# Add FreeRTOS option to tinyusb_config
265-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
266-
CFG_TUSB_OS=OPT_OS_FREERTOS
267-
)
268-
# link tinyusb with freeRTOS kernel
269-
target_link_libraries(${TARGET}-tinyusb PUBLIC
270-
freertos_kernel
271-
)
272-
target_link_libraries(${TARGET} PUBLIC
273-
freertos_kernel
274-
)
275-
endfunction()
276-
277-
305+
# family specific: can override above functions
278306
include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)
279307

280308
if (NOT FAMILY_MCUS)

hw/bsp/imxrt/family.cmake

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ if (NOT TARGET ${BOARD_TARGET})
3636
${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_clock.c
3737
)
3838
target_compile_definitions(${BOARD_TARGET} PUBLIC
39-
CFG_TUSB_MCU=OPT_MCU_MIMXRT
4039
__ARMVFP__=0
4140
__ARMFPV5__=0
4241
XIP_EXTERNAL_FLASH=1
@@ -100,33 +99,16 @@ function(family_configure_example TARGET)
10099
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
101100
)
102101

103-
#---------- TinyUSB ----------
104-
# tinyusb target is built for each example since it depends on example's tusb_config.h
105-
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
106-
add_library(${TARGET}-tinyusb_config INTERFACE)
107-
108-
target_include_directories(${TARGET}-tinyusb_config INTERFACE
109-
${CMAKE_CURRENT_SOURCE_DIR}/src
110-
)
111-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
112-
CFG_TUSB_MCU=OPT_MCU_MIMXRT
113-
)
114-
115-
# tinyusb's CMakeList.txt
116-
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
102+
# Add TinyUSB
103+
family_add_tinyusb(${TARGET} OPT_MCU_MIMXRT)
117104

118105
# Link dependencies
119106
target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
120107

121-
# group target (not yet supported by clion)
122-
set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
123-
PROPERTIES FOLDER ${TARGET}_sub
124-
)
125-
126-
#---------- Flash ----------
108+
# Flashing
127109
family_flash_jlink(${TARGET})
128110
family_flash_nxplink(${TARGET})
129-
family_flash_pyocd(${TARGET})
111+
#family_flash_pyocd(${TARGET})
130112
endfunction()
131113

132114

hw/bsp/lpc18/family.cmake

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,13 @@ function(family_configure_example TARGET)
8383
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
8484
)
8585

86-
#---------- TinyUSB ----------
87-
# tinyusb target is built for each example since it depends on example's tusb_config.h
88-
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
89-
add_library(${TARGET}-tinyusb_config INTERFACE)
90-
91-
target_include_directories(${TARGET}-tinyusb_config INTERFACE
92-
${CMAKE_CURRENT_SOURCE_DIR}/src
93-
)
94-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
95-
CFG_TUSB_MCU=OPT_MCU_LPC18XX
96-
)
97-
98-
# tinyusb's CMakeList.txt
99-
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
86+
# Add TinyUSB
87+
family_add_tinyusb(${TARGET} OPT_MCU_LPC18XX)
10088

10189
# Link dependencies
10290
target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
10391

104-
# group target (not yet supported by clion)
105-
set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
106-
PROPERTIES FOLDER ${TARGET}_sub
107-
)
108-
109-
#---------- Flash ----------
92+
# Flashing
11093
family_flash_jlink(${TARGET})
11194
endfunction()
11295

hw/bsp/lpc55/family.cmake

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,16 @@ function(family_configure_example TARGET)
109109
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
110110
)
111111

112-
#---------- TinyUSB ----------
113-
# tinyusb target is built for each example since it depends on example's tusb_config.h
114-
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
115-
add_library(${TARGET}-tinyusb_config INTERFACE)
116-
117-
target_include_directories(${TARGET}-tinyusb_config INTERFACE
118-
${CMAKE_CURRENT_SOURCE_DIR}/src
119-
)
120-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
121-
CFG_TUSB_MCU=OPT_MCU_LPC55XX
122-
)
123-
124-
# tinyusb's CMakeList.txt
125-
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
112+
# Add TinyUSB
113+
family_add_tinyusb(${TARGET} OPT_MCU_LPC55XX)
126114

127115
# Link dependencies
128116
target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
129117

130-
# group target (not yet supported by clion)
131-
set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
132-
PROPERTIES FOLDER ${TARGET}_sub
133-
)
134-
135-
#---------- Flash ----------
118+
# Flashing
136119
family_flash_jlink(${TARGET})
137120
family_flash_nxplink(${TARGET})
138-
family_flash_pyocd(${TARGET})
121+
#family_flash_pyocd(${TARGET})
139122
endfunction()
140123

141124

hw/bsp/mcx/family.cmake

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,13 @@ function(family_configure_example TARGET)
9191
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
9292
)
9393

94-
#---------- TinyUSB ----------
95-
# tinyusb target is built for each example since it depends on example's tusb_config.h
96-
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
97-
add_library(${TARGET}-tinyusb_config INTERFACE)
98-
99-
target_include_directories(${TARGET}-tinyusb_config INTERFACE
100-
${CMAKE_CURRENT_SOURCE_DIR}/src
101-
)
102-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
103-
CFG_TUSB_MCU=OPT_MCU_MCXN9
104-
)
105-
106-
# tinyusb's CMakeList.txt
107-
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
94+
# Add TinyUSB
95+
family_add_tinyusb(${TARGET} OPT_MCU_MCXN9)
10896

10997
# Link dependencies
11098
target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
11199

112-
# group target (not yet supported by clion)
113-
set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
114-
PROPERTIES FOLDER ${TARGET}_sub
115-
)
116-
117-
#---------- Flash ----------
100+
# Flashing
118101
family_flash_jlink(${TARGET})
119102
#family_flash_nxplink(${TARGET})
120103
#family_flash_pyocd(${TARGET})

hw/bsp/nrf/family.cmake

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,13 @@ function(family_configure_example TARGET)
9898
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
9999
)
100100

101-
#---------- TinyUSB ----------
102-
# tinyusb target is built for each example since it depends on example's tusb_config.h
103-
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
104-
add_library(${TARGET}-tinyusb_config INTERFACE)
105-
106-
target_include_directories(${TARGET}-tinyusb_config INTERFACE
107-
${CMAKE_CURRENT_SOURCE_DIR}/src
108-
)
109-
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
110-
CFG_TUSB_MCU=OPT_MCU_NRF5X
111-
)
112-
113-
# tinyusb's CMakeList.txt
114-
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
101+
# Add TinyUSB
102+
family_add_tinyusb(${TARGET} OPT_MCU_NRF5X)
115103

116104
# Link dependencies
117105
target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
118106

119-
# group target (not yet supported by clion)
120-
set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
121-
PROPERTIES FOLDER ${TARGET}_sub
122-
)
123-
124-
#---------- Flash ----------
107+
# Flashing
125108
family_flash_jlink(${TARGET})
126109
endfunction()
127110

0 commit comments

Comments
 (0)