forked from SynthstromAudible/DelugeFirmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
293 lines (235 loc) · 8.9 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
cmake_minimum_required(VERSION 3.23)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/scripts/cmake/CMakeToolchainDeluge.cmake)
project(Deluge
LANGUAGES CXX C ASM
VERSION 1.0.0
)
include(ProcessorCount)
ProcessorCount(HOST_NUM_CORES)
# Check for IPO support
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT error)
if(IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION
$<$<CONFIG:DEBUG>:OFF>
$<$<CONFIG:RELWITHDEBINFO>:ON>
$<$<CONFIG:RELEASE>:ON>
)
endif()
# 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()
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
set(BUILD_VERSION_STRING "${PROJECT_VERSION}${SEMVER_PRERELEASE_ID}-${GIT_COMMIT_SHORT}") # Used in firmware
set(BUILD_VERSION_SUFFIX "-v${PROJECT_VERSION}${SEMVER_PRERELEASE_ID}+${DATE_TODAY}-${GIT_COMMIT_SHORT}") # Used for filename
if(NOT "${GIT_STATUS}" STREQUAL "")
string(APPEND BUILD_VERSION_SUFFIX "-dirty")
string(APPEND BUILD_VERSION_STRING "-dirty")
endif()
message(VERBOSE "semver: ${BUILD_VERSION_SUFFIX}")
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)
# This function lets us add multiple firmware "configurations"
# that each have their own set of flags from the same source
# It is very much a hack and should be retired as soon as possible
function(add_firmware EXECUTABLE BASE)
get_target_property(BASE_SOURCES ${BASE} INTERFACE_SOURCES)
get_target_property(BASE_INCLUDES ${BASE} INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(BASE_LINKS ${BASE} INTERFACE_LINK_LIBRARIES)
get_target_property(BASE_DEFINITIONS ${BASE} INTERFACE_COMPILE_DEFINITIONS)
get_target_property(BASE_OPTIONS ${BASE} INTERFACE_COMPILE_OPTIONS)
add_executable(${EXECUTABLE})
target_sources(${EXECUTABLE} PRIVATE ${BASE_SOURCES})
target_include_directories(${EXECUTABLE} PRIVATE ${BASE_INCLUDES})
target_link_libraries(${EXECUTABLE} ${BASE_LINKS})
set_property(
TARGET ${EXECUTABLE}
APPEND PROPERTY
COMPILE_DEFINITIONS ${BASE_DEFINITIONS}
)
set_property(
TARGET ${EXECUTABLE}
APPEND PROPERTY
COMPILE_OPTIONS ${BASE_OPTIONS}
)
set_target_properties(${EXECUTABLE}
PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED ON
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
SUFFIX "${EXECUTABLE_VERSION_SUFFIX}.elf"
)
set(BIN_FILE $<CONFIG>/${EXECUTABLE}${EXECUTABLE_VERSION_SUFFIX}.bin)
set(HEX_FILE $<CONFIG>/${EXECUTABLE}${EXECUTABLE_VERSION_SUFFIX}.hex)
set(MAP_FILE $<CONFIG>/${EXECUTABLE}${EXECUTABLE_VERSION_SUFFIX}.map)
# add link options to generate memory map
target_link_options(${EXECUTABLE} PUBLIC
LINKER:-Map=${MAP_FILE}
LINKER:--cref
)
# generate .bin firmware file
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary -S $<TARGET_FILE:${EXECUTABLE}> ${BIN_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Objcopying ${EXECUTABLE} to firmware ${BIN_FILE}"
DEPENDS ${EXECUTABLE}
BYPRODUCTS ${BIN_FILE})
# generate .hex firmware file
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex -S $<TARGET_FILE:${EXECUTABLE}> ${HEX_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Objcopying ${EXECUTABLE} to firmware ${HEX_FILE}"
DEPENDS ${EXECUTABLE}
BYPRODUCTS ${HEX_FILE})
# Clean up artefacts
set_property(TARGET ${EXECUTABLE}
PROPERTY
ADDITIONAL_CLEAN_FILES ${BIN_FILE} ${MAP_FILE} ${HEX_FILE})
# find_program(PRETTYSIZE_CMD prettysize prettysize.py)
# if(NOT PRETTYSIZE_CMD STREQUAL "PRETTYSIZE_CMD-NOTFOUND")
# add_custom_command(
# TARGET ${EXECUTABLE} POST_BUILD
# COMMAND prettysize
# -l ${CMAKE_CURRENT_LIST_DIR}/linker_script_rz_a1l.ld
# -s ${CMAKE_SIZE} $<TARGET_FILE:${EXECUTABLE}>
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Displaying usage graph for ${EXECUTABLE}")
# endif()
endfunction(add_firmware)
# Global compilation options
add_compile_options(
# Feature flags
-fdiagnostics-parseable-fixits
-fsigned-char
# Debug symbols
$<$<CONFIG:DEBUG>:-g> # Include
$<$<CONFIG:DEBUG>:-ggdb> # Include
$<$<CONFIG:RELWITHDEBINFO>:-g> # Include
$<$<CONFIG:RELEASE>:-s> # Strip
# Optimization level
$<$<CONFIG:DEBUG>:-Og>
$<$<CONFIG:RELWITHDEBINFO>:-O2>
$<$<CONFIG:RELEASE>:-O2>
# Link time optimizations
$<$<CONFIG:RELWITHDEBINFO>:-flto>
$<$<CONFIG:RELEASE>:-flto>
-ffunction-sections
-fdata-sections
# 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_link_options(
-T ${PROJECT_SOURCE_DIR}/linker_script_rz_a1l.ld
LINKER:--gc-sections
-nostartfiles # Don't emit startfiles
-estart # Set the entrypoint to 'start' (see RZA1/compiler/asm/start.S)
)
# RTT Debug options
option(ENABLE_RTT "Enable RTT output" ON)
option(ENABLE_SYSEX_LOAD "Enable loading firmware over midi sysex" OFF)
# Colored output
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." ON)
if(FORCE_COLORED_OUTPUT)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Forcing colors for GCC")
add_compile_options(-fdiagnostics-color=always)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Forcing colors for Clang")
add_compile_options(-fcolor-diagnostics)
endif()
endif(FORCE_COLORED_OUTPUT)
# Add libraries
add_subdirectory(lib)
# Add our sources
add_subdirectory(src)
# Project-only compile options (warnings, etc.)
target_compile_options(deluge INTERFACE
# Warnings
# $<$<CONFIG:DEBUG>:-Wextra> # TODO: Enable when ready
# $<$<CONFIG:DEBUG>:-Wall> # TODO: Enable when ready
# $<$<CONFIG:DEBUG>:-Wpedantic> # TODO: Enable when ready
$<$<CONFIG:DEBUG>:-Wnull-dereference>
$<$<CONFIG:DEBUG>:-Wno-psabi>
$<$<CONFIG:DEBUG>:-Werror=write-strings>
# Stack usage
$<$<CONFIG:DEBUG>:-Wstack-usage=100>
$<$<CONFIG:RELWITHDEBINFO>:-Wstack-usage=1000>
$<$<CONFIG:RELEASE>:-Wstack-usage=1000>
)
# 7SEG configuration
add_firmware(deluge7SEG deluge)
# OLED Configuration
add_firmware(delugeOLED deluge)
target_compile_definitions(delugeOLED PUBLIC HAVE_OLED=1)
# ##### Documentation generation #######
# check if Doxygen is installed
find_package(Doxygen
OPTIONAL_COMPONENTS dot mscgen dia
)
if(DOXYGEN_FOUND)
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_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)
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)