-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeson.build
94 lines (84 loc) · 3 KB
/
meson.build
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
project(
'edamame-bootloader',
'c',
'cpp',
version: '0.0.3',
default_options: [ 'c_std=c11', 'cpp_std=gnu++11' ]
)
assert(meson.is_cross_build(), 'This project can only be built in a cross build environment.')
# Import binary helpers
stinfo = find_program('st-info')
stflash = find_program('st-flash')
python = find_program('python3', required: false)
objcopy = '@0@'.format(find_program('objcopy').path())
size = '@0@'.format(find_program('size').path())
# Build time defines
option_defines = []
if get_option('COPYBINARY').enabled()
option_defines += '-DCOPYBINARY'
endif
# Startup and system files
system_files = files([
'startup.s',
'system.c'
])
system_inc = include_directories([
'CMSIS/Include',
'CMSIS/Device/ST/STM32F1xx/Include'
])
c_args = [ option_defines, '-Os' ]
link_args = '-Wl,-T,@0@/@1@'.format(meson.current_source_dir(), 'linker.ld')
# Add src dependancies
subdir('src')
mcu_inc = get_variable('mcu_inc')
mcu_files = get_variable('mcu_files')
# Generate elf file for MCU
main_elf = executable(
'main',
[ system_files, mcu_files, 'main.cpp', 'src/System_stm32f1.cpp' ],
name_suffix : 'elf',
include_directories : [ system_inc, mcu_inc ],
cpp_args : [ c_args ],
c_args : [ c_args ],
link_args : [ link_args ]
)
if (meson.is_subproject() != true)
# Build custom targets MCU
main_bin = custom_target(
'main_bin',
output : [ 'main.bin' ],
build_by_default : true,
command : [ objcopy, '-O', 'binary', '-S', 'main.elf', 'main.bin' ],
depends : [ main_elf ]
)
main_hex = custom_target(
'main_hex',
output : [ 'main.hex' ],
build_by_default : false,
command : [ objcopy, '-O', 'ihex', 'main.elf', 'main.hex' ],
depends : [ main_elf ]
)
# Add CppUTest dependancy
cpputest = subproject('cpputest')
cpputest_dep = cpputest.get_variable('cpputest_dep')
# Build native test executable
subdir('test')
test_files = get_variable('test_files')
main_test = executable(
'tests',
[ mcu_files, test_files ],
include_directories : [ system_inc, mcu_inc ],
dependencies : [ cpputest_dep ],
c_args: option_defines,
cpp_args: option_defines,
native : true,
build_by_default : false
)
test('Bootloader test', main_test)
# Custom run commands
run_target('erase', command: [ stflash, 'erase' ])
run_target('lint', command: [ python, '.clang-format.py', '-r', '-e', 'src', 'src' ])
run_target('fix', command: [ python, '.clang-format.py', '-r', '-s', '-e', 'src', 'src' ])
run_target('flash', command: [ stflash, '--reset', 'write', main_bin, '0x08000000' ], depends: main_bin)
run_target('size', command: [ size, main_hex ], depends: main_hex)
endif