############################################################################### # MESON SETUP project( 'firmware', ['c', 'cpp'], default_options: ['optimization=2', 'cpp_std=c++20', 'b_staticpic=false', 'b_lto=false', 'warning_level=3', 'default_library=static'] ) ############################################################################### # 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 ## 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@', ]) 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@', ]) ch32v30x_dep = ch32v30x_proj.get_variable('ch32v30x_dep') ch32v30x_sys_dep = ch32v30x_proj.get_variable('ch32v30x_sys_dep') dependencies = [ch32v30x_dep, ch32v30x_sys_dep] 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') ############################################################################### # BUILD TARGETS _incl_dirs = include_directories(includes) objcopy = find_program('objcopy') objdump = find_program('objdump') size = find_program('size') main = executable( target_name + '.elf', sources, include_directories: _incl_dirs, dependencies: dependencies, ) main_hex = custom_target( target_name + '.hex', command: [ objcopy, '-O', 'ihex', '@INPUT@', '@OUTPUT@' ], input: main, output: target_name + '.hex', build_by_default: true, ) # Copy files to generic names that make can find hex_for_make = custom_target( 'firmware-for-make.hex', command: ['cp', '@INPUT@', '@OUTPUT@'], input: main_hex, 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', build_by_default: true, ) main_disas = custom_target( target_name + '.disas', command: [ objdump, '-SC', '--visualize-jumps', '@INPUT@' ], input: main, output: target_name + '.disas', 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', )