#
# Configuration file for running the libunwind tests against the static library.
#

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

compile_flags = []
link_flags = []

if @LIBUNWIND_ENABLE_THREADS@:
    link_flags.append('-lpthread')

if @LIBUNWIND_ENABLE_CET@:
    compile_flags.append('-fcf-protection=full')

if @LIBUNWIND_ENABLE_GCS@:
    compile_flags.append('-mbranch-protection=standard')

# On ELF platforms, link tests with -Wl,--export-dynamic if supported by the linker.
if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
    link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')

if '@CMAKE_DL_LIBS@':
    link_flags.append('-l@CMAKE_DL_LIBS@')

# Stack unwinding tests need unwinding tables and these are not generated by default on all targets.
compile_flags.append('-funwind-tables')

local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@'
config.substitutions.append(('%{flags}',
    '-isysroot {}'.format(local_sysroot) if local_sysroot else ''
))
config.substitutions.append(('%{compile_flags}',
    '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags))
))
config.substitutions.append(('%{link_flags}',
    '%{{lib}}/libunwind.a {}'.format(' '.join(link_flags))
))
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
)
