forked from TheThingsIndustries/generic-node-se
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
212 lines (203 loc) · 6.42 KB
/
CMakeLists.txt
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Copyright © 2021 The Things Industries B.V.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------
# Cmake Setup
#-------------------
cmake_minimum_required(VERSION 3.16.1)
if(NOT CMAKE_TOOLCHAIN_FILE)
message(FATAL_ERROR "[ERRR] CMAKE_TOOLCHAIN_FILE not specified")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
message(WARNING "[WARN] CMAKE_BUILD_TYPE not specified: Using ${CMAKE_BUILD_TYPE} by default")
endif()
if(NOT TARGET_APP)
set(TARGET_APP basic CACHE STRING "Choose the target app." FORCE)
message(WARNING "[WARN] TARGET_APP not specified: Using ${TARGET_APP} app by default")
endif()
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
#-------------------
# Project Setup
#-------------------
enable_language(C ASM)
project(${TARGET_APP})
set (APP_BUILD_DIR app/${TARGET_APP})
set (APP_LIST
"app_template"
"basic"
"basic_lorawan"
"basic_bootloader"
"basic_freertos"
"freefall_lorawan"
"freertos_lorawan"
"secure_element_lorawan"
"basic_azurertos"
"sensors_lorawan"
"basic_fuota")
#-------------------
# MCU Setup
#-------------------
set(MCU STM32WL55xx)
set(MCU_DIR target)
set(MCU_SPEC cortex-m4)
set(STARTUP_FILE ${MCU_DIR}/startup_stm32wl55xx.s)
set(SYSTEM_FILE ${MCU_DIR}/system_stm32wlxx.c)
set(LINKER_SCRIPT_MEM ${MCU_DIR}/memory_map.ld)
# Adjust stm32wl55xx_flash.ld to app.ld or bootloader.ld when using a bootloader
set(LINKER_SCRIPT ${MCU_DIR}/stm32wl55xx_flash.ld)
#-------------------
# HAL Setup
#-------------------
set(HAL_DIR target/stm32wlxx_hal_driver)
#-------------------
# LoRaWAN Setup
#-------------------
set(LORAWAN_DIR lib/STM32WLxx_LoRaWAN)
#-------------------
# CMSIS Setup
#-------------------
# Set the path to the CMSIS folder
set(CMSIS_DIR target/CMSIS)
#-------------------
# General Flags
#-------------------
set(OBJECT_GEN_FLAGS " \
-fno-builtin \
-Wall \
-ffunction-sections -fdata-sections \
-fomit-frame-pointer \
" CACHE INTERNAL "Common flags for C/CXX/ASM/Linker")
#-------------------
# CFLAGS
#-------------------
set(CMAKE_C_FLAGS " \
" CACHE INTERNAL "C Compiler options")
#-------------------
# ASMFLAGS for cross
#-------------------
set(CMAKE_ASM_FLAGS " \
-x assembler-with-cpp \
" CACHE INTERNAL "ASM Compiler options")
#-------------------
# LFLAGS for cross
#-------------------
set(CMAKE_EXE_LINKER_FLAGS " \
-Wl,-Map=${PROJECT_NAME}.map \
-Wl,--print-memory-usage \
-Wl,--gc-sections \
" CACHE INTERNAL "Linker options")
#------------------
# Debug Flags
#------------------
set(CMAKE_C_FLAGS_DEBUG "-Og -g -gdwarf-3 -gstrict-dwarf " CACHE INTERNAL "C Compiler options for debug build type")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -gdwarf-3 -gstrict-dwarf " CACHE INTERNAL "C++ Compiler options for debug build type")
set(CMAKE_ASM_FLAGS_DEBUG "-Og -g -gdwarf-3 -gstrict-dwarf " CACHE INTERNAL "ASM Compiler options for debug build type")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type")
#------------------
# Release Flags
#-----------------
set(CMAKE_C_FLAGS_RELEASE "-Os -flto " CACHE INTERNAL "C Compiler options for release build type")
set(CMAKE_CXX_FLAGS_RELEASE "-Os -flto " CACHE INTERNAL "C++ Compiler options for release build type")
set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto " CACHE INTERNAL "Linker options for release build type")
#------------------
# Cross Compilation Flags
#-----------------
message(STATUS "[INFO] Cross compiling for ${MCU}")
message(STATUS "[INFO] Startup file used is ${STARTUP_FILE}")
# Control ARM Semihosting support
if(NOT SEMIHOSTING)
set(SEMIHOSTING 0)
message(WARNING "[WARN] Semihosting support not specified: Disabling by default")
endif()
#-------------------
# General Flags for cross
#-------------------
string(APPEND OBJECT_GEN_FLAGS " \
-mcpu=${MCU_SPEC} \
-mthumb \
-mthumb-interwork \
-mabi=aapcs \
${FLOAT_SPEC} \
")
#-------------------
# CFLAGS for cross
#-------------------
string(APPEND CMAKE_C_FLAGS " \
${OBJECT_GEN_FLAGS} \
")
#-------------------
# ASMFLAGS for cross
#-------------------
string(APPEND CMAKE_ASM_FLAGS " \
${OBJECT_GEN_FLAGS} \
")
#-------------------
# LFLAGS for cross
#-------------------
string(APPEND CMAKE_EXE_LINKER_FLAGS " \
${OBJECT_GEN_FLAGS} \
")
find_file(LINKER_SCRIPT_PATH
NAMES "${LINKER_SCRIPT}"
PATHS
${CMAKE_CURRENT_LIST_DIR}
)
if(DEFINED LINKER_SCRIPT_PATH)
message(STATUS "[INFO] Using linker file at ${LINKER_SCRIPT_PATH}")
string(APPEND CMAKE_EXE_LINKER_FLAGS "-T${LINKER_SCRIPT_PATH} ")
else()
message(FATAL_ERROR "[ERRR] Could not find linker script ${LINKER_SCRIPT}")
endif()
find_file(LINKER_SCRIPT_MEM_PATH
NAMES "${LINKER_SCRIPT_MEM}"
PATHS
${CMAKE_CURRENT_LIST_DIR}
)
if(DEFINED LINKER_SCRIPT_MEM_PATH)
message(STATUS "[INFO] Using memory map linker at ${LINKER_SCRIPT_MEM_PATH}")
string(APPEND CMAKE_EXE_LINKER_FLAGS "-L${PROJECT_SOURCE_DIR}/${MCU_DIR} ")
endif()
if("${SEMIHOSTING}" STREQUAL "1")
string(APPEND CMAKE_EXE_LINKER_FLAGS "--specs=rdimon.specs -lc -lrdimon ")
else()
string(APPEND CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs ")
endif()
#-------------------
# Build target application
#-------------------
if(TARGET_APP IN_LIST APP_LIST)
add_subdirectory(target)
add_subdirectory(${APP_BUILD_DIR})
target_compile_definitions(${PROJECT_NAME}.elf
PUBLIC
${MCU}
SEMIHOSTING=${SEMIHOSTING}
-DGNSE_APP_NAME="${TARGET_APP}"
)
# Create output in hex and binary format
create_hex_output(${PROJECT_NAME} ${APP_BUILD_DIR})
create_bin_output(${PROJECT_NAME} ${APP_BUILD_DIR})
# Add additional files to the make clean
set_property(DIRECTORY PROPERTY ADDITIONAL_CLEAN_FILES
"${APP_BUILD_DIR}/${PROJECT_NAME}.map"
"${APP_BUILD_DIR}/${PROJECT_NAME}.bin"
"${APP_BUILD_DIR}/${PROJECT_NAME}.hex"
)
else()
message(FATAL_ERROR "Given TARGET_APP unknown")
endif()
# Unset all cache
unset(SEMIHOSTING)
unset(CMAKE_TOOLCHAIN_FILE)
unset(CMAKE_BUILD_TYPE)
unset(TARGET_APP)
unset(APP_BUILD_DIR)