# file      : tests/cc/modules/common.testscript
# license   : MIT; see accompanying LICENSE file

crosstest = false
test.arguments = config.cxx=$quote($recall($cxx.path) $cxx.config.mode)

.include ../../common.testscript

+cat <<EOI >+build/bootstrap.build
using test
EOI

+cat <<EOI >=build/root.build
using in

using cxx.guess

# Force modules.
#
cxx.std = experimental
cxx.features.symexport = true

# @@ TMP revise
#
# Note: there are some issues with enabling modules in Apple Clang 15 so
# for now we only test vanilla Clang.
#
if (($cxx.id == 'gcc'   && $cxx.version.major >= 11)     || \
    ($cxx.id == 'clang' && $cxx.version.major >= 16)     || \
    ($cxx.id == 'msvc'  && ($cxx.version.major > 19 ||      \
                            ($cxx.version.major == 19 &&    \
                             $cxx.version.minor >= 36))))
  cxx.features.modules = true

using cxx

hxx{*}: extension = hxx
mxx{*}: extension = mxx
cxx{*}: extension = cxx

cxx.poptions =+ "-I$out_root" "-I$src_root"

if ($cxx.target.class == 'windows')
  bmis{*}: cxx.poptions += '-DLIBFOO_EXPORT=__declspec(dllexport)'

exe{*}: test = true
EOI

# Determine if we have named modules and header units support.
#
+$* noop <<EOI | set modules
print $cxx.features.modules
EOI

+$* noop <<EOI | set headers
print ($cxx.features.modules && $cxx.id == 'gcc')
EOI

# @@ TMP: try symexport with MinGW GCC (modules support seems to work otherwise)
# @@ TMP: try modules with Clang on Windows (symexport seems to work).
#
if ($cxx.target.class == 'windows' && \
    ($cxx.id == 'gcc' || $cxx.id.type == 'clang'))
{
  modules = false
  headers = false
}
