#-----------------------------------------------------------------------------
#
# Copyright (C) 2022 Bjarne von Horn <vh@igh.de>
#
# This file is part of the PdQmlWidgets library.
#
# The PdQmlWidgets library is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# The PdQmlWidgets library 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 Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the PdQmlWidgets Library. If not, see
# <http://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.10)

project(QmlTest)
include(GNUInstallDirs)

# load Qt
find_package(Qt5 REQUIRED
    COMPONENTS Charts Gui Quick QuickControls2 Svg Xml
)
find_package(Qt5
    OPTIONAL_COMPONENTS QuickCompiler
)
# load Widgets with QML files
if (NOT TARGET EtherLab::PdQmlWidgets2)
    find_package(PdQmlWidgets2 REQUIRED)
endif()

# compile qml files (of this project) if compiler available
if(COMMAND qtquick_compiler_add_resources)
    qtquick_compiler_add_resources(EXAMPLE_RCC_SOURCES resources.qrc)
else()
    qt5_add_resources(EXAMPLE_RCC_SOURCES resources.qrc)
endif()

set(SOURCES
    src/ScalarSeries.h
    src/QmlBuddy.h
    src/ScalarSeries.cpp
    src/QmlBuddy.cpp
    src/main.cpp

    ${EXAMPLE_RCC_SOURCES}
)

add_executable(${PROJECT_NAME} ${SOURCES})

set_target_properties(${PROJECT_NAME} PROPERTIES
    AUTOUIC 0
    AUTOMOC 1
    AUTORCC 0
)

# link in Qt, the PdWidgets and the PdWidgets QML files

target_link_libraries(${PROJECT_NAME} PUBLIC
    EtherLab::PdQmlWidgets2
    Qt5::Charts
    Qt5::Quick
    Qt5::QuickControls2
)

install(TARGETS ${PROJECT_NAME}
    ARCHIVE DESTINATION       "${CMAKE_INSTALL_LIBDIR}"
    LIBRARY DESTINATION       "${CMAKE_INSTALL_LIBDIR}"
    RUNTIME DESTINATION       "${CMAKE_INSTALL_BINDIR}"
)
