Skip to content

Commit 8ede566

Browse files
authored
Merge pull request hathach#2039 from hathach/add-cmake-build
Add cmake build
2 parents 0871238 + a4d5d51 commit 8ede566

File tree

36 files changed

+613
-105
lines changed

36 files changed

+613
-105
lines changed

.idea/cmake.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/cdc_msc.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.idea/runConfigurations/hid_composite.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.idea/runConfigurations/msc_dual_lun.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

cmake/cpu/cortex-m7.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set(TOOLCHAIN_COMMON_FLAGS
2+
-mthumb
3+
-mcpu=cortex-m7
4+
-mfloat-abi=hard
5+
-mfpu=fpv5-d16
6+
)

cmake/toolchain/arm_gcc.cmake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
set(CMAKE_SYSTEM_NAME Generic)
2+
3+
set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc")
4+
set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
5+
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
6+
set(GCC_ELF2BIN "arm-none-eabi-objcopy")
7+
set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
8+
9+
# Look for includes and libraries only in the target system prefix.
10+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
11+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
12+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
13+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
14+
15+
# pass TOOLCHAIN_CPU to
16+
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_SYSTEM_PROCESSOR)
17+
18+
include(${CMAKE_CURRENT_LIST_DIR}/../cpu/${CMAKE_SYSTEM_PROCESSOR}.cmake)
19+
20+
# enable all possible warnings for building examples
21+
list(APPEND TOOLCHAIN_COMMON_FLAGS
22+
-fdata-sections
23+
-ffunction-sections
24+
-fsingle-precision-constant
25+
-fno-strict-aliasing
26+
)
27+
28+
set(TOOLCHAIN_WARNING_FLAGS
29+
-Wall
30+
-Wextra
31+
-Werror
32+
-Wfatal-errors
33+
-Wdouble-promotion
34+
-Wstrict-prototypes
35+
-Wstrict-overflow
36+
-Werror-implicit-function-declaration
37+
-Wfloat-equal
38+
-Wundef
39+
-Wshadow
40+
-Wwrite-strings
41+
-Wsign-compare
42+
-Wmissing-format-attribute
43+
-Wunreachable-code
44+
-Wcast-align
45+
-Wcast-function-type
46+
-Wcast-qual
47+
-Wnull-dereference
48+
-Wuninitialized
49+
-Wunused
50+
-Wreturn-type
51+
-Wredundant-decls
52+
)
53+
54+
include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)

cmake/toolchain/set_flags.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include(CMakePrintHelpers)
2+
foreach(LANG IN ITEMS C CXX ASM)
3+
# join the toolchain flags into a single string
4+
list(APPEND TOOLCHAIN_${LANG}_FLAGS ${TOOLCHAIN_COMMON_FLAGS})
5+
list(JOIN TOOLCHAIN_${LANG}_FLAGS " " TOOLCHAIN_${LANG}_FLAGS)
6+
set(CMAKE_${LANG}_FLAGS_INIT "${TOOLCHAIN_${LANG}_FLAGS}")
7+
8+
#cmake_print_variables(CMAKE_${LANG}_FLAGS_INIT)
9+
10+
# optimization flags
11+
set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-Og")
12+
endforeach()
13+
14+
# try_compile is cmake test compiling its own example,
15+
# pass -nostdlib to skip stdlib linking
16+
get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
17+
if(IS_IN_TRY_COMPILE)
18+
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -nostdlib")
19+
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib")
20+
endif()

examples/device/audio_4_channel_mic/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.17)
22

33
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
44

55
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
66
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
77

8-
project(${PROJECT})
8+
project(${PROJECT} C CXX ASM)
99

1010
# Checks this example is valid for the family and initializes the project
1111
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
1212

13+
# Espressif has its own cmake build system
14+
if(FAMILY STREQUAL "espressif")
15+
return()
16+
endif()
17+
1318
add_executable(${PROJECT})
1419

1520
# Example source
1621
target_sources(${PROJECT} PUBLIC
1722
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
1823
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
19-
)
24+
)
2025

2126
# Example include
2227
target_include_directories(${PROJECT} PUBLIC
2328
${CMAKE_CURRENT_SOURCE_DIR}/src
24-
)
29+
)
2530

2631
# Configure compilation flags and libraries for the example... see the corresponding function
2732
# in hw/bsp/FAMILY/family.cmake for details.

examples/device/audio_test/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.17)
22

33
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
44

55
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
66
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
77

8-
project(${PROJECT})
8+
project(${PROJECT} C CXX ASM)
99

1010
# Checks this example is valid for the family and initializes the project
1111
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
1212

13+
# Espressif has its own cmake build system
14+
if(FAMILY STREQUAL "espressif")
15+
return()
16+
endif()
17+
1318
add_executable(${PROJECT})
1419

1520
# Example source

examples/device/audio_test_multi_rate/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.17)
22

33
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
44

55
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
66
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
77

8-
project(${PROJECT})
8+
project(${PROJECT} C CXX ASM)
99

1010
# Checks this example is valid for the family and initializes the project
1111
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
1212

13+
# Espressif has its own cmake build system
14+
if(FAMILY STREQUAL "espressif")
15+
return()
16+
endif()
17+
1318
add_executable(${PROJECT})
1419

1520
# Example source

0 commit comments

Comments
 (0)