qt.version = $config.libbuild2_qt_tests.qt

using qt.moc

switch $qt.version
{
  case 0
    libs =
  case 5
    import libs = libQt5Core%lib{Qt5Core}
  case 6
    import libs = libQt6Core%lib{Qt6Core}
}

# All of the project's source files.
#
# Put hxx{source} in ./source/ to test that subdirectories are handled
# correctly.
#
src = hxx{source/source sink nomoc} cxx{sink driver}

exe{driver}: $src automoc{driver} libue{QtCoreMeta}

# The automoc{} target scans its hxx{} and cxx{} prerequisites for Qt
# meta-object macros and runs moc on those that match.
#
# Note that the corresponding moc output targets (cxx{moc_*} and moc{*}) are
# not explicitly referred to anywhere but may be if necessary, as long as
# there are no prerequisites or they are compatible with the would-be
# synthesized dependency (first prerequisite is the input header/source file,
# etc).
#
automoc{driver}: $src libue{QtCoreMeta}

# Header containing the compiler's predefined macros.
#
[rule_hint=cxx.predefs] hxx{moc_predefs}:
{
  # Cause this macro to be defined in the predefs header. Used to trigger
  # build errors unless a valid predefs header is being passed to moc.
  #
  cxx.coptions += -DAUTOMOC_TEST_PREDEFS_INCLUDED
}

# Test that non-ad hoc generated source files are updated before the Qt
# meta-object macro scan is done. (The link rule only updates headers and ad
# hoc source files during match.)
#
cxx{sink}: in{sink}

# A generated header that does not contain any meta-object macros and, in
# particular, should be cleaned if the automoc{} target is cleaned directly.
#
hxx{nomoc}: in{nomoc}

# Note: the rule hint is for when libs is empty (see above).
#
[rule_hint=cxx] libue{QtCoreMeta}: $libs

# Set the include path prefix.
#
qt.moc.options = -p automoc

# Arrange for hxx{moc_predefs} to be parsed as a #include before the source
# file (using moc's --include option) for all members of the automoc group.
#
automoc{driver}: hxx{moc_predefs}: include = adhoc
automoc{driver}:
{
  qt.moc.auto_predefs = false

  qt.moc.options += --include $out_base/moc_predefs.hxx
}

# Set a target-specific include path prefix (merging with the group's
# options).
#
# Note that this also tests the buildfile-declared group member case (as
# opposed to being synthesized by the automoc rule).
#
cxx{source/moc_source}: qt.moc.options += $(automoc{driver}: qt.moc.options) \
                                          -p automoc/source

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