ch32v-template/meson.build

142 lines
3.4 KiB
Meson
Raw Permalink Normal View History

###############################################################################
# MESON SETUP
2022-11-26 01:20:14 +00:00
project(
'firmware',
['c', 'cpp'],
default_options: ['optimization=2', 'cpp_std=c++20', 'b_staticpic=false',
'b_lto=false', 'warning_level=3', 'default_library=static']
2022-11-26 01:20:14 +00:00
)
###############################################################################
# MAIN BUILD CONFIGURATION
flash_origin = 0
flash_size = 0
stack_size = 2048
bsp = 'bsp-BOARD'
target = get_option('build_target')
target_name = meson.project_name() + '_' + target
if target == 'main'
sources = [
'src/main.c',
]
includes = [
'src',
]
endif
###############################################################################
# SYSTEM DEPENDENCIES
2023-01-08 05:31:19 +00:00
## END USER MUST MODIFY: KEEP ONLY THE 10x or 30x BLOCK
ch32v10x_proj = subproject('ch32v10x', default_options: [
f'flash_size=@flash_size@',
f'flash_origin=@flash_origin@',
f'stack_size=@stack_size@',
])
2023-01-08 05:31:19 +00:00
ch32v10x_dep = ch32v10x_proj.get_variable('ch32v10x_dep')
ch32v10x_sys_dep = ch32v10x_proj.get_variable('ch32v10x_sys_dep')
dependencies = [ch32v10x_dep, ch32v10x_sys_dep]
## END USER MUST MODIFY: KEEP ONLY THE 10x or 30x BLOCK
ch32v30x_proj = subproject('ch32v30x', default_options: [
'variant=CH32V307',
f'flash_size=@flash_size@',
f'flash_origin=@flash_origin@',
f'stack_size=@stack_size@',
])
2023-01-08 05:31:19 +00:00
ch32v30x_dep = ch32v30x_proj.get_variable('ch32v30x_dep')
ch32v30x_sys_dep = ch32v30x_proj.get_variable('ch32v30x_sys_dep')
dependencies = [ch32v30x_dep, ch32v30x_sys_dep]
2022-11-26 01:20:14 +00:00
bsp_proj = subproject(bsp)
dependencies += bsp_proj.get_variable('bsp_dep')
info_dep = vcs_tag(
command: ['git', 'describe', '--always', '--dirty'],
fallback: 'no-git',
input: 'version.h.in',
output: 'version.h',
replace_string: 'GITINFO',
)
sources += info_dep
###############################################################################
# APPLICATION DEPENDENCIES
xutil_proj = subproject('xutil', default_options: [
'with_cpp=true',
'with_task=false',
])
dependencies += xutil_proj.get_variable('xutil_dep')
2022-11-26 01:20:14 +00:00
###############################################################################
# BUILD TARGETS
2022-11-26 01:20:14 +00:00
_incl_dirs = include_directories(includes)
objcopy = find_program('objcopy')
objdump = find_program('objdump')
size = find_program('size')
main = executable(
target_name + '.elf',
2022-11-26 01:20:14 +00:00
sources,
include_directories: _incl_dirs,
dependencies: dependencies,
)
main_hex = custom_target(
target_name + '.hex',
2022-11-26 01:20:14 +00:00
command: [
objcopy,
'-O', 'ihex',
'@INPUT@', '@OUTPUT@'
],
input: main,
output: target_name + '.hex',
2022-11-26 01:20:14 +00:00
build_by_default: true,
)
2022-11-26 05:18:20 +00:00
# Copy files to generic names that make can find
2022-11-26 01:20:14 +00:00
hex_for_make = custom_target(
2022-11-26 05:18:20 +00:00
'firmware-for-make.hex',
2022-11-26 01:20:14 +00:00
command: ['cp', '@INPUT@', '@OUTPUT@'],
input: main_hex,
2022-11-26 05:18:20 +00:00
output: 'firmware-for-make.hex',
build_by_default: true,
)
elf_for_make = custom_target(
'firmware-for-make.elf',
command: ['cp', '@INPUT@', '@OUTPUT@'],
input: main,
output: 'firmware-for-make.elf',
2022-11-26 01:20:14 +00:00
build_by_default: true,
)
main_disas = custom_target(
target_name + '.disas',
2022-11-26 01:20:14 +00:00
command: [
objdump,
'-SC', '--visualize-jumps', '@INPUT@'
2022-11-26 01:20:14 +00:00
],
input: main,
output: target_name + '.disas',
2022-11-26 01:20:14 +00:00
build_by_default: true,
capture: true,
)
main_size = custom_target(
'size',
build_always_stale: true,
build_by_default: true,
command: [
size, '@INPUT@'
],
input: main,
console: true,
output: 'size',
)