# The Craftr build system
# Copyright (C) 2016  Niklas Rosenstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

cxx = load('craftr.lang.cxx')
curlpp = load('craftr.lib.curlpp')
dlib = load('craftr.lib.dlib')
tinyxml2 = load('craftr.lib.tinyxml2')

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

try:
  qt5 = load('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.executable(
  inputs = cxx.compile_cpp(
    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 = runtarget(main, local('example.ini'),
  environ = {'PATH': append_PATH(qt5.bin_dir if qt5 else None)}
)
