-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmeson.build
More file actions
119 lines (105 loc) · 4.42 KB
/
meson.build
File metadata and controls
119 lines (105 loc) · 4.42 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# This is the main build script.
# This is where we configure how ZestCode is built.
# It's used in combination with scripts/v5.ini, which tells Meson (the build system)
# what tools to use and what platform the program is built for.
# project configuration
project(
'zestcode', # project name (zestcode)
['c', 'cpp'], # written in both C and C++ (for now)
version : '0.0.0',
meson_version: '>= 1.2.0', # we use splitlines which was introduced in meson v1.2.0
default_options: [
'c_std=gnu2x', # latest c standard supported in gcc v13
'cpp_std=gnu++23', # latest c++ standard supported in gcc v13
'warning_level=3', # 0, 1, 2, 3, or everything. Higher means more warnings
'optimization=s', # minimize binary size to minimize upload times. We have a ton of performance overhead
'debug=true', # debug symbols are not included in the final .bin file, so they don't increase upload time at all
'force_fallback_for=v5, v5_header'
],
)
# patches the .clangd file so the system includes work.
# runs whenever meson is configured
python = find_program('python3')
patch_clangd = files('scripts' / 'patch_clangd.py')
run_command(python, patch_clangd, meson.get_compiler('c'), check: true)
# possible source file extensions
file_exts = [
'*.s', # assembly
'*.S', # assembly
'*.c', # C
'*.h', # C
'*.cpp', # C++
'*.hpp' # C++
]
get_files = files('scripts' / 'get_files.py')
# get all source files
get_files_result = run_command(python, get_files, 'src', file_exts, check: true)
source = get_files_result.stdout().strip().splitlines()
# optimization flags passed to the compiler
optimization_flags = [
'-ffunction-sections', # used in combination with --gc-sections to reduce binary size
'-fdata-sections', # used in combination with --gc-sections to reduce binary size
'-fno-strict-aliasing', # needed due to bad coding practices in the FreeRTOS source
]
# formatting flags passed to the compiler and linker
formatting_flags = [
'-fdiagnostics-color', # makes the compiler output easier to read, by using colors!
]
add_global_arguments(formatting_flags, language: 'c')
add_global_arguments(formatting_flags, language: 'cpp')
add_global_link_arguments(formatting_flags, language: 'c')
add_global_link_arguments(formatting_flags, language: 'cpp')
# miscellaneous flags passed to the linker
linker_flags = [
'-Wl,--gc-sections', # used in combination with -ffunction-sections and -fdata-sections to reduce binary size
'-Wl,--no-warn-rwx-segments' # silences a warning that does not make a difference for our use case
]
# system libraries we depend on
system_deps = [
'-nostartfiles', # we still need to implement some newlib stubs
'-lstdc++exp',
]
add_global_link_arguments( system_deps, language: 'c')
add_global_link_arguments(system_deps, language: 'cpp')
# configuration of the standard library
stdlib_conf = [
'-D_POSIX_MONOTONIC_CLOCK', # enable the POSIX monotonic clock
]
# warning flags
warning_flags = [
'-Wno-psabi' # all libraries (except libv5) are compiled from source, making this warning useless
]
# apply all these flags and configs
add_global_arguments(optimization_flags, formatting_flags, warning_flags, stdlib_conf, language: 'c')
add_global_arguments(optimization_flags, formatting_flags, warning_flags, stdlib_conf, language: 'cpp')
add_global_link_arguments(optimization_flags, linker_flags, formatting_flags, warning_flags, system_deps, language: 'c')
add_global_link_arguments(optimization_flags, linker_flags, formatting_flags, warning_flags, system_deps, language: 'cpp')
# include directories.
# we only specify the top level in order to enforce paths in include directives.
include = include_directories('./include')
# this is what user projects will link against, so we use declare_dependency instead of static_library
zestcode = static_library(
'zestcode',
sources: source,
include_directories: include,
dependencies: dependency('v5_header'),
)
# TODO: figure out a better way to do this in a future Tests PR
elf = executable(
'program.elf',
sources: './tests/examples/basic.cpp',
include_directories: include,
dependencies: [
dependency('v5'),
],
link_whole: zestcode
)
# meson won't create the binary file for uploading, so we have to do it ourselves
objcopy = find_program('arm-none-eabi-objcopy')
custom_target(
'program.bin',
output: 'program.bin',
input: elf,
build_by_default: true, # otherwise it won't be built
command: [objcopy, ['-O', 'binary', '-S', '@INPUT@', '@OUTPUT@']],
)