-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmeson.build
117 lines (98 loc) · 3.77 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#
# stm32-libopencm3-meson build
# Copyright (C) 2017 Amitesh Singh
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library;
# if not, see <http://www.gnu.org/licenses/>.
#
project('stm32f1-project', 'cpp')
compiler_obj = meson.get_compiler('cpp')
size = find_program('arm-none-eabi-size')
objcopy = find_program('arm-none-eabi-objcopy')
stinfo = find_program('st-info')
stflash = find_program('st-flash')
#define libopencm3 path here
libocm3Path = '/home/ami/work/repos/libopencm3'
#define cpu types here
cputype = 'cortex-m3'
cpudefine = 'STM32F1'
libocm3cputype = 'opencm3_stm32f1'
#Add your source files here
srcfiles = ['main.cpp']
libocm3IncPath = libocm3Path + '/include'
libocm3LibPath = libocm3Path + '/lib'
libocm3LdPath = libocm3Path + '/lib/stm32/f1'
# check for libopencm3 library
libocm3lib_obj = compiler_obj.find_library(libocm3cputype, required: true, dirs: libocm3LibPath)
if libocm3lib_obj.found() == true
message('Found libopencm3 library at ' + libocm3Path)
else
error('unable to find libopencm3 library')
endif
incdir = include_directories(libocm3IncPath)
stm32f1cargs = ['-Os',
'-ggdb',
'-mcpu=' + cputype,
'-mthumb',
'-msoft-float',
'-std=gnu++14',
'-Wall',
'-Wshadow',
'-ffunction-sections',
'-fdata-sections',
'-D' + cpudefine,
'-fno-exceptions',
#'-I' + libocm3IncPath
]
stm32f1linkargs = ['-Os',
'-ggdb',
'-D' + cpudefine,
'-fdata-sections',
'-mcpu=' + cputype,
'-mthumb',
'-msoft-float',
'-lc',
'-flto',
#'-T../libopencm3_f1.ld',
'-T' + meson.current_source_dir() + '/libopencm3_f1.ld',
'--specs=nosys.specs',
'-nostartfiles',
'-Wl,--gc-sections',
'-L' + libocm3LibPath,
'-L' + libocm3LdPath,
# '-l' + libocm3cputype,
]
p = ['blink', srcfiles, stm32f1cargs, stm32f1linkargs]
exe = executable(p[0], p[1],
cpp_args: p[2],
link_args: p[3],
include_directories : incdir,
dependencies: libocm3lib_obj,
build_by_default: true)
run_target('hex', command: [objcopy, ['-Obinary', exe.full_path(),
exe.full_path() + '.hex']], depends: exe)
run_target('size', command: [size, exe.full_path(), '-B'], depends: exe)
# STlink programmer related commands
run_target('probe', command: [stinfo, '--probe'])
run_target('upload', command: [stflash, 'write', exe.full_path() + '.hex', '0x08000000'], depends: exe)
if meson.is_cross_build()
message('cross compiling for ' + cputype)
message('''
ninja - generates elf file.
ninja hex - generates hex file.
ninja upload - upload hex file to stm32 via stlink programmer.
ninja probe - probe stlink programmer.
ninja size - gives the summary of hex file size.
(C) Amitesh Singh''')
endif