qt.version = $config.libbuild2_qt_tests.qt

using qt.rcc

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

# Use RCC to generate a C++ header, a C++ source file, and an external
# resource (binary data).
#
# The header is included by driver.cxx, the source file is compiled and linked
# into the driver executable, and the external resource is loaded at run time.
#
# The driver tests that all of these resources are accessible.
#

exe{driver}: cxx{driver} $libs

# Driver executable: dependencies on the RCC outputs.
#
exe{driver}: hxx{qrc_foo} cxx{qrc_bar}        # Embedded resources.

exe{driver}: file{baz.rcc}: include = posthoc # External resource.

# A generated resource.
#
file{bar.txt}: in{bar}

# Note that bar.qrc is generated only in order for it to be placed in the same
# directory as the generated resource, which is necessary because rcc
# interprets relative resource paths as relative to the qrc input file. (One
# could otherwise use absolute resource paths but then the driver program
# would also have to be updated to use them and the qrc file would still need
# to be generated.)
#
qrc{bar}: in{bar}

# RCC outputs: dependencies on their resource collection files.
#
hxx{qrc_foo}: qrc{foo} # Note: declares 3 resources.

# Note that generated resources (bar.txt, in this case) must be statically
# declared as prerequisites whereas regular, non-generated resources will be
# discovered and updated automatically.
#
cxx{qrc_bar}: qrc{bar} file{bar.txt}

file{baz.rcc}: qrc{baz}
{
  qt.rcc.options = --binary
}

# Ensure resources are distributed.
#
exe{driver}: file{foo.txt foo2.txt foo3.txt     \
                  bar.txt                       \
                  baz.txt}: include = adhoc

# Build options.
#
# $out_base is required to load the external resource.
#
# Use $representation() to ensure a trailing separator and also escape
# backslashes on Windows.
#
ob = $regex.replace($representation($out_base), '\\', '\\\\')
cxx.poptions += "-I$out_root" -DOUT_BASE="\"$ob\""
