# Copyright (C) 2024 Maciej Sopyło <me@klh.io>
#
# SPDX-License-Identifier: GPL-3.0-only
#
# This file is part of Lomiri Weather App
#
# Lomiri Weather App is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# Lomiri Weather App 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/>.

set(PLUGIN "LomiriWeather")

set(SRC
    weather_data_provider.h
    plugin.cpp
    data_point.cpp
    data_day.cpp
    provider.cpp
    open_meteo/open_meteo_weather_provider.cpp
)

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/open_meteo/weather_api_generated.h"
    COMMAND flatbuffers::flatc --cpp --gen-object-api -o "${CMAKE_CURRENT_BINARY_DIR}/open_meteo" weather_api.fbs
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/open_meteo/weather_api.fbs"
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/open_meteo"
)
add_custom_target(generate-weather-api DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/open_meteo/weather_api_generated.h")

add_library(${PLUGIN} MODULE ${SRC})
add_dependencies(${PLUGIN} generate-weather-api)

target_include_directories(${PLUGIN} PUBLIC "${CMAKE_SOURCE_DIR}/src")

set_target_properties(${PLUGIN} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN})
target_link_libraries(${PLUGIN} Qt5::Gui Qt5::Qml Qt5::Location flatbuffers::flatbuffers)

install(TARGETS ${PLUGIN} DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN}/)
install(FILES qmldir DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN}/)
