-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
CMakeLists.txt
365 lines (292 loc) · 11 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
cmake_minimum_required(VERSION 3.23)
cmake_policy(SET CMP0135 NEW)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/scripts/cmake/CMakeToolchainDeluge.cmake)
project(Deluge
LANGUAGES CXX C ASM
VERSION 1.3.0
)
include(FetchContent)
include(ProcessorCount)
ProcessorCount(HOST_NUM_CORES)
# Create our version string
set(RELEASE_TYPE "dev" CACHE STRING "The type of releasepack to build")
set_property(CACHE RELEASE_TYPE PROPERTY STRINGS dev nightly alpha beta rc release)
if(RELEASE_TYPE STREQUAL "release")
set(SEMVER_PRERELEASE_ID "")
else()
set(SEMVER_PRERELEASE_ID "-${RELEASE_TYPE}")
endif()
if(CMAKE_HOST_WIN32)
# Find python by ourselves, since on windows the find_package lookup
# seems to fail
set(Python_EXECUTABLE "$ENV{DBT_TOOLCHAIN_ROOT}/python/python.exe")
IF(EXISTS ${Python_EXECUTABLE})
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import platform; print(platform.python_version())"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE Python_VERSION
RESULT_VARIABLE Python_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${Python_RESULT} AND NOT ${Python_VERSION} STREQUAL "")
set(Python_Interpreter_FOUND 1)
else()
message(FATAL_ERROR "Python found at ${Python_EXECUTABLE} but failed to get version number")
endif()
else()
set(Python_Interpreter_FOUND 0)
endif()
else()
find_package(Python COMPONENTS Interpreter)
endif()
if (Python_Interpreter_FOUND)
message(VERBOSE "python found: ${Python_EXECUTABLE} version ${Python_VERSION}")
else()
message(FATAL_ERROR "Python not found")
endif(Python_Interpreter_FOUND)
find_package(Git)
if(GIT_FOUND)
message(VERBOSE "git found: ${GIT_EXECUTABLE} version ${GIT_VERSION_STRING}")
else()
message(FATAL_ERROR "Git not found. Check your path.")
endif(GIT_FOUND)
# Get the result of "git rev-parse --short HEAD"
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the result of "git status --porcelain"
execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Today's date
string(TIMESTAMP DATE_TODAY "%Y.%m.%d")
# Build our version string
if(RELEASE_TYPE STREQUAL "release")
set(BUILD_VERSION_SUFFIX "-c${PROJECT_VERSION}") # Used for filename
else()
set(BUILD_VERSION_SUFFIX "-v${PROJECT_VERSION}${SEMVER_PRERELEASE_ID}+${DATE_TODAY}-${GIT_COMMIT_SHORT}") # Used for filename
endif()
string(REPLACE "." "_" BUILD_VERSION_SUFFIX ${BUILD_VERSION_SUFFIX})
if(NOT "${GIT_STATUS}" STREQUAL "")
if(NOT RELEASE_TYPE STREQUAL "release")
string(APPEND BUILD_VERSION_STRING "-dirty")
endif()
endif()
message(STATUS "Deluge version: v${BUILD_VERSION_STRING}")
option(ENABLE_VERSIONED_OUTPUT "Tag the resulting output files with a semver label" OFF)
if(ENABLE_VERSIONED_OUTPUT)
set(EXECUTABLE_VERSION_SUFFIX ${BUILD_VERSION_SUFFIX})
else()
set(EXECUTABLE_VERSION_SUFFIX "")
endif(ENABLE_VERSIONED_OUTPUT)
# RTT option
option(ENABLE_RTT "Enable RTT output" ON)
# SYSEX Load option
option(ENABLE_SYSEX_LOAD "Enable loading firmware over midi sysex" OFF)
# MATRIX DRIVER pad logging
option(ENABLE_MATRIX_DEBUG "Enable logging of pad events" OFF)
# Colored output
set(CMAKE_COLOR_DIAGNOSTICS ON)
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-fansi-escape-codes>)
# ##### Documentation generation #######
# check if Doxygen is installed
find_package(Doxygen
OPTIONAL_COMPONENTS dot mscgen dia
)
if(DOXYGEN_FOUND)
FetchContent_Declare(doxygen-awesome-css
URL https://github.com/jothepro/doxygen-awesome-css/archive/refs/tags/v2.2.1.tar.gz
URL_HASH MD5=340d3a206794ac01a91791c2a513991f
)
FetchContent_MakeAvailable(doxygen-awesome-css)
if(NOT ${DOXYGEN_HAVE_DOT})
message(
"Can't find GraphViz DOT tool for generating images."
"Make sure it's on your PATH or install GraphViz")
endif()
set(DOXYGEN_PROJECT_NAME "Deluge Firmware")
set(DOXYGEN_RECURSIVE YES)
set(DOXYGEN_EXAMPLE_RECURSIVE YES)
set(DOXYGEN_NUM_PROC_THREADS ${HOST_NUM_CORES})
# From doxygen-awesome
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_DISABLE_INDEX NO)
set(DOXYGEN_FULL_SIDEBAR NO)
set(DOXYGEN_HTML_COLORSTYLE LIGHT)
set(DOXYGEN_HTML_EXTRA_STYLESHEET "${doxygen-awesome-css_SOURCE_DIR}/doxygen-awesome.css")
set(DOXYGEN_CREATE_SUBDIRS YES)
set(DOXYGEN_EXTRACT_PRIVATE YES)
set(DOXYGEN_INTERNAL_DOCS YES)
set(DOXYGEN_SOURCE_BROWSER YES)
# set(DOXYGEN_CLANG_ASSISTED_PARSING YES)
# SET(DOXYGEN_CLANG_DATABASE_PATH build)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)
file(GLOB markdown_SOURCES *.md)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/html/)
doxygen_add_docs(doxygen ${markdown_SOURCES} docs src/deluge build/src/deluge)
else(DOXYGEN_FOUND)
message(WARNING
"Doxygen needs to be installed to generate documentation."
"Please install from https://github.com/doxygen/doxygen/releases")
endif(DOXYGEN_FOUND)
# Global compilation options
add_compile_options(
# Feature flags
-fdiagnostics-parseable-fixits
-fsigned-char
-D_GNU_SOURCE # for strcasestr
# Debug symbols, also for release so we get a full ELF
$<$<CONFIG:DEBUG,RELEASE,RELWITHDEBINFO>:-ggdb3> # Include
# Optimization level
$<$<CONFIG:DEBUG>:-Og>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-O2>
# does not block inlining, just blocks considering all functions for inlining
# https://developer.arm.com/documentation/100067/0600/Compiler-Command-line-Options/-finline-functions---fno-inline-functions?lang=en
-fno-inline-functions
# Link time optimizations
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-flto=auto>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-fuse-linker-plugin>
-ffunction-sections
-fdata-sections
-DUSE_TASK_MANAGER
# C++ stuff
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
$<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>
# ASM stuff
$<$<COMPILE_LANGUAGE:ASM>:-x>
$<$<COMPILE_LANGUAGE:ASM>:assembler-with-cpp>
)
# Add libraries
add_subdirectory(lib)
# Add the main executable target
add_executable(deluge)
# Link external libraries
target_link_libraries(deluge PUBLIC
argon
)
option(MAINTAINER_MODE "Enables all warnings and errors" OFF)
# Project-only compile options (warnings, etc.)
set(DELUGE_C_STANDARD 23)
set(DELUGE_CXX_STANDARD 23)
list(APPEND DELUGE_COMMON_COMPILE_OPTIONS
$<$<AND:$<BOOL:${MAINTAINER_MODE}>,$<CXX_COMPILER_ID:GNU>>:-fanalyzer> # static analysis
# Warnings
$<$<BOOL:${MAINTAINER_MODE}>:-Wextra>
$<$<BOOL:${MAINTAINER_MODE}>:-Wall>
$<$<BOOL:${MAINTAINER_MODE}>:-Wabi>
$<$<BOOL:${MAINTAINER_MODE}>:-Wpedantic>
$<$<CONFIG:DEBUG>:-Wnull-dereference>
$<$<CONFIG:DEBUG>:-Wno-psabi>
$<$<CONFIG:DEBUG>:-Wno-unused-parameter>
$<$<CONFIG:DEBUG>:-Werror=write-strings>
# Offsetof for non standard types is supported in GCC,
# if another compiler does not support it they are obligated to error
# Stack usage
# tracked for diagnostic usage. We have a 32k stack so it's not that important
# primarily concerned with unbounded stack use
$<$<CONFIG:DEBUG>:-Wstack-usage=2000>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-Wstack-usage=2000>
)
target_compile_options(deluge PUBLIC ${DELUGE_COMMON_COMPILE_OPTIONS})
set_target_properties(deluge
PROPERTIES
C_STANDARD ${DELUGE_C_STANDARD}
C_STANDARD_REQUIRED ON
CXX_STANDARD ${DELUGE_CXX_STANDARD}
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
SUFFIX "${EXECUTABLE_VERSION_SUFFIX}.elf"
)
set(BIN_FILE $<CONFIG>/deluge${EXECUTABLE_VERSION_SUFFIX}.bin)
set(HEX_FILE $<CONFIG>/deluge${EXECUTABLE_VERSION_SUFFIX}.hex)
set(MAP_FILE $<CONFIG>/deluge${EXECUTABLE_VERSION_SUFFIX}.map)
# set(OBJDUMP_FILE $<CONFIG>/deluge${EXECUTABLE_VERSION_SUFFIX}.objdump)
set(NMDUMP_FILE $<CONFIG>/deluge${EXECUTABLE_VERSION_SUFFIX}.nmdump)
# add link options to generate memory map
target_link_options(deluge PUBLIC
# use newlib nano
--specs=nano.specs
-T ${PROJECT_SOURCE_DIR}/linker_script_rz_a1l.ld
LINKER:-Map=${MAP_FILE}
LINKER:--cref
LINKER:--gc-sections
LINKER:--entry=start # Set the entrypoint to 'start' (see RZA1/compiler/asm/start.S)
# Enabled to generate a full ELF, objcopy will do the stripping
# $<$<CONFIG:RELEASE>:LINKER:--strip-all> # Strip
-nostartfiles # Don't emit startfiles
# Print details
LINKER:--warn-common
LINKER:--stats
# $<$<CXX_COMPILER_ID:GNU>:LINKER:--print-memory-usage>
# Link-Time Optimization
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-flto=auto>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-fuse-linker-plugin>
# Coloring
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
)
# generate .bin firmware file
add_custom_command(TARGET deluge
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary -S $<TARGET_FILE:deluge> ${BIN_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Objcopying deluge to firmware ${BIN_FILE}"
DEPENDS deluge
BYPRODUCTS ${BIN_FILE})
# generate .hex firmware file
add_custom_command(TARGET deluge
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex -S $<TARGET_FILE:deluge> ${HEX_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Objcopying deluge to firmware ${HEX_FILE}"
DEPENDS deluge
BYPRODUCTS ${HEX_FILE})
# # generate .objdump file
# add_custom_command(TARGET deluge
# POST_BUILD
# COMMAND ${CMAKE_OBJDUMP} -t $<TARGET_FILE:deluge> > ${OBJDUMP_FILE}
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Objdumping deluge firmware ${OBJDUMP_FILE}"
# DEPENDS deluge
# BYPRODUCTS ${OBJDUMP_FILE})
# generate .nmdump file
add_custom_command(TARGET deluge
POST_BUILD
COMMAND ${CMAKE_NM} -t d -S -C -r --special-syms --size-sort $<TARGET_FILE:deluge> > ${NMDUMP_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "NM dumping deluge firmware ${NMDUMP_FILE}"
DEPENDS deluge
BYPRODUCTS ${NMDUMP_FILE}
)
# Print size
add_custom_command(TARGET deluge
POST_BUILD
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:deluge>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS deluge
)
# Clean up artefacts
set_target_properties(deluge
PROPERTIES
ADDITIONAL_CLEAN_FILES ${BIN_FILE} ${MAP_FILE} ${HEX_FILE}
)
# Deluge sources
add_subdirectory(src)
# find_program(PRETTYSIZE_CMD prettysize prettysize.py)
# if(NOT PRETTYSIZE_CMD STREQUAL "PRETTYSIZE_CMD-NOTFOUND")
# add_custom_command(
# TARGET deluge POST_BUILD
# COMMAND prettysize
# -l ${CMAKE_CURRENT_LIST_DIR}/linker_script_rz_a1l.ld
# -s ${CMAKE_SIZE} $<TARGET_FILE:deluge>
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Displaying usage graph for deluge")
# endif()