# On mingw32, build2 stages DLLs as POSIX-style symlinks that native Windows
# tools such as addr2line cannot follow. Link everything statically so all code
# lands in unittest.exe and addr2line only has to resolve against one real file.
if ($cxx.target.system == 'mingw32')
  import libs = \
    libcpptrace%liba{cpptrace} \
    gtest%liba{gtest} \
    gmock%liba{gmock}
else
  import libs = \
    libcpptrace%lib{cpptrace} \
    gtest%lib{gtest} \
    gmock%lib{gmock}

exe{*}: test.arguments = --gtest_brief=1

# NOTE: the executable must be named "unittest" to match the substring the
# object_trace tests check for in the binary path.
exe{unittest}: src/{hxx ixx txx cxx}{**} $libs testscript{**}

# Upstream suppresses these warnings on the unit test target.
#
if ($cxx.class != 'msvc')
  cxx.coptions += -Wno-pedantic -Wno-attributes
if ($cxx.id == 'gcc')
  cxx.coptions += -Wno-infinite-recursion

# Upstream builds unit tests at -O0 (Debug) (the tests assume no inlining of
# throw-site lambdas and check for specific filenames and line numbers in
# traces).
#
if ($cxx.class == 'msvc')
  cxx.coptions += /Zi /Od
elif ($cxx.id == 'clang' && $cxx.target.system == 'darwin')
  # Clang on darwin generates DWARF5 with __debug_names tables that Apple's
  # CoreSymbolication (used by atos) cannot parse. Force DWARF4 so the
  # compiler emits __apple_names tables instead, which atos handles correctly.
  cxx.coptions += -g -gdwarf-4 -O0
else
  cxx.coptions += -g -O0

# All non-MinGW Windows targets (MSVC and clang) need /DEBUG so the linker
# emits a PDB that dbghelp can use for symbol resolution.
if ($cxx.target.class == 'windows' && $cxx.target.system != 'mingw32')
  exe{unittest}: cxx.loptions += /DEBUG
