-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
102 lines (84 loc) · 2.26 KB
/
CMakeLists.txt
File metadata and controls
102 lines (84 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
cmake_minimum_required(VERSION 3.25)
set(C_STANDARD 99)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_EXECUTABLE_SUFFIX_C .out)
set(CMAKE_C_SIZE_TOOL arm-none-eabi-size)
# Required to prevent "The C Compiler is not able to compile a simple test program"
# error due to cross-compiling.
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_BINARY_DIR build)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(blinky_pca10056 LANGUAGES C CXX ASM)
set(SDK_ROOT ${CMAKE_SOURCE_DIR}/lib/nrf5_sdk)
set(PROJ_DIR ${CMAKE_SOURCE_DIR}/src)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/nrf52840_s140_v7.ld)
set(SRC_FILES
src/driver/i2c.cpp
src/driver/oled.cpp
src/main.cpp
)
include_directories(
src # TODO: hide from library cmake files
src/config
)
set(MCU_FLAGS
-O3
-g3
-mcpu=cortex-m4
-mthumb
-mabi=aapcs
-mfloat-abi=hard
-mfpu=fpv4-sp-d16
-ffunction-sections
-fdata-sections
-fno-strict-aliasing
-fno-builtin
-fshort-enums
)
string(JOIN " " MCU_FLAGS_STR ${MCU_FLAGS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MCU_FLAGS_STR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MCU_FLAGS_STR}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${MCU_FLAGS_STR}")
add_executable(blinky ${SRC_FILES}) # TODO: rename target
include(lib/submodules.cmake)
add_submodules(blinky)
target_compile_options(blinky PRIVATE
-Wall
-Werror
-Wextra
)
target_link_options(blinky PRIVATE
-L${SDK_ROOT}/modules/nrfx/mdk
-T${LINKER_SCRIPT}
-Wl,--gc-sections
--specs=nano.specs
-Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/blinky.map
)
target_link_libraries(blinky PRIVATE
c
nosys
m
)
add_custom_command(
TARGET blinky POST_BUILD
COMMAND ${CMAKE_C_SIZE_TOOL} ARGS blinky
COMMENT "Size of blinky"
)
add_custom_command(
TARGET blinky POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ARGS -O binary blinky blinky.bin
COMMENT "Generating blinky.bin"
)
add_custom_command(
TARGET blinky POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ARGS -O ihex blinky blinky.hex
COMMENT "Generating blinky.hex"
)
add_custom_command(
TARGET blinky POST_BUILD
COMMAND cksum ARGS blinky.bin
COMMENT "Checksum of blinky.bin"
)