# examples.cpp

load_module('craftr.lang.cxx.*')
load_module('craftr.lib.curlpp.*')
load_module('craftr.lib.dlib.*')
load_module('craftr.lib.tinyxml2.*')

defines = []
frameworks = [cURLpp, dlib, tinyxml2]

try:
  qt5 = load_module('craftr.lib.qt5')
except ModuleError as exc:
  logger.warn('note: Qt5 can not be found, disabling Qt5 example')
  logger.warn('note: message:', exc)
  qt5 = None
else:
  defines.append('HAVE_QT5')
  frameworks.append(qt5.framework('Qt5Widgets'))

main = cxx_binary(
  inputs = cpp_compile(
    sources = [local('main.cpp')],
    frameworks = frameworks,
    defines = defines
  ),
  output = 'main'
)

# Make a target that runs the application that we just compiled. If Qt5
# is available, the directory with binaries (with shared libraries) will
# be added to the PATH.
run = gentarget(
  commands = [[main, local('example.ini')]],
  explicit=True,
  environ = {'PATH': append_PATH(qt5.bin_dir if qt5 else None)}
)
