lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')

libc_linker_script = '@CMAKE_INSTALL_PREFIX@/lib/picolibcpp.ld'

config.substitutions.append(('%{flags}', '--sysroot=@CMAKE_INSTALL_PREFIX@'))

config.substitutions.append(('%{compile_flags}',
    '-nostdinc++ -I %{include}'
))
config.substitutions.append(('%{link_flags}',
    '-fuse-ld=lld -nostdlib -nostdlib++ -L %{lib} -lunwind'
    ' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost' +
    ' -T {}'.format(libc_linker_script) +
    ' -Wl,--defsym=__flash=0x0'
    ' -Wl,--defsym=__flash_size=0x400000'
    ' -Wl,--defsym=__ram=0x21000000'
    ' -Wl,--defsym=__ram_size=0x1000000'
    ' -Wl,--defsym=__stack_size=0x1000'
))

config.executor = (
    '@LIBUNWIND_LIBCXX_PATH@/utils/qemu_baremetal.py'
    ' --qemu @QEMU_SYSTEM_ARM@'
    ' --machine mps2-an385'
    ' --cpu cortex-m3')
config.substitutions.append(('%{exec}',
    '%{executor}'
    ' --execdir %{temp}'
))

import os, site
site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
import libcxx.test.params, libcxx.test.config
libcxx.test.config.configure(
    libcxx.test.params.DEFAULT_PARAMETERS,
    libcxx.test.features.DEFAULT_FEATURES,
    config,
    lit_config
)
