# SPDX-FileCopyrightText: %{CURRENT_YEAR} %{AUTHOR} <%{EMAIL}>
# SPDX-License-Identifier: BSD-3-Clause
# This file was generated automatically by Qleany's generator, edit at your own risk! 
# If you do, be careful to not overwrite it when you run the generator again.

cmake_minimum_required(VERSION 3.16)

project({{ application_name_lower }} VERSION 0.1)

# Compiler settings
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
{% if front_ends.qt_quick.enabled -%}
option(BUILD_QT_QUICK "Build the QtQuick front end" OFF)
{% endif %}
{% if front_ends.qt_widgets.enabled -%}
option(BUILD_QT_WIDGETS "Build the QtWidgets front end" OFF)
{% endif %}
{% if front_ends.kf6_kirigami.enabled -%}
option(BUILD_KF6_KIRIGAMI "Build the KF6Kirigami front end" OFF)
{% endif %}
{% if front_ends.kf6_widgets.enabled -%}
option(BUILD_KF6_WIDGETS "Build the KF6Widgets front end" OFF)
{% endif %}

if(NOT BUILD_QT_QUICK AND NOT BUILD_QT_WIDGETS AND NOT BUILD_KF6_KIRIGAMI AND NOT BUILD_KF6_WIDGETS)
    message(FATAL_ERROR "At least one front end must be enabled")
endif()

{% if front_ends.kf6_kirigami.enabled or front_ends.kf6_widgets.enabled -%}

if(BUILD_KF6_KIRIGAMI OR BUILD_KF6_WIDGETS)
    set(BUILD_KF6 ON)
endif()

if(BUILD_KF6)
    set(QT6_MIN_VERSION 6.5.0)
    set(KF6_MIN_VERSION 6.0.0)

    find_package(ECM ${KF6_MIN_VERSION} REQUIRED NO_MODULE)
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH})

    include(FeatureSummary)
    include(KDEInstallDirs)
    include(KDECMakeSettings)
    include(KDECompilerSettings NO_POLICY_SCOPE)
    include(ECMSetupVersion)
    include(ECMFindQmlModule)
    include(ECMInstallIcons)


    # enable -fexceptions
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")

    if(NOT ANDROID)
        include(KDEGitCommitHooks)
        include(KDEClangFormat)
    endif()

{% if front_ends.kf6_kirigami.enabled -%}
if(BUILD_KF6_KIRIGAMI)
    ecm_setup_version(${PROJECT_VERSION}
        VARIABLE_PREFIX {{ application_name_upper }}
        VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/{{ front_ends.kf6_kirigami.folder_path }}/version-{{ application_name_lower }}.h"
    )
endif()
{% endif %}
{% if front_ends.kf6_widgets.enabled -%}
if(BUILD_KF6_WIDGETS)
    ecm_setup_version(${PROJECT_VERSION}
        VARIABLE_PREFIX {{ application_name_upper }}
        VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/{{ front_ends.kf6_widgets.folder_path }}/version-{{ application_name_lower }}.h"
    )
endif()
{% endif %}
endif()
{% endif %}
{% if front_ends.qt_quick.enabled or front_ends.qt_widgets.enabled -%}

if(BUILD_QT_QUICK OR BUILD_QT_WIDGETS)
    set(QT6_MIN_VERSION 6.5.0)
endif()
{% endif %}


# Add QCoro
find_package(QCoro6 REQUIRED COMPONENTS Core)

# Set necessary compiler flags to enable coroutine support
qcoro_enable_coroutines()

find_package(Qt6 ${QT6_MIN_VERSION} REQUIRED COMPONENTS Core Gui Svg Sql Concurrent)
{% if front_ends.kf6_widgets.enabled -%}

if(BUILD_KF6_WIDGETS)
    find_package(Qt6 ${QT6_MIN_VERSION} REQUIRED COMPONENTS Widgets)
    find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS
        CoreAddons
        I18n
    )
endif()
{% endif %}
{% if front_ends.kf6_kirigami.enabled or front_ends.qt_quick.enabled -%}

if(BUILD_KF6_KIRIGAMI OR BUILD_QT_QUICK)
    find_package(Qt6 ${QT6_MIN_VERSION} REQUIRED COMPONENTS Qml QuickControls2)
    find_package(QCoro6 REQUIRED COMPONENTS Qml)

    set(QT_EXTRA_COMPONENTS)

    if(NOT ANDROID)
        list(APPEND QT_EXTRA_COMPONENTS Widgets)
    endif()

    find_package(Qt6 ${QT6_MIN_VERSION} REQUIRED COMPONENTS Qml QuickControls2 ${QT_EXTRA_COMPONENTS})
endif()
{% endif %}
{% if front_ends.kf6_kirigami.enabled -%}

if(BUILD_KF6_KIRIGAMI)
    find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS Kirigami CoreAddons Config I18n)

    if(ANDROID)
        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/android/version.gradle.in ${CMAKE_BINARY_DIR}/version.gradle)
    endif()

    qt_policy(SET QTP0001 NEW)

    ecm_find_qmlmodule(org.kde.kirigamiaddons.formcard 1.0)
endif()
{% endif %}

# handles the entities
add_subdirectory({{ entities_path }})

# stores the interfaces
add_subdirectory({{ contracts_path }})

# handles the data access from inside the system
add_subdirectory({{ persistence_path }})

# handles the data access from outside the system
add_subdirectory({{ contracts_dto_path }})

# handles the CQRS commands, queries and validators
add_subdirectory({{ contracts_cqrs_path }})

# handles the use cases
add_subdirectory({{ application_path }})

# handles the interaction between the system's inner layers (use cases, DTOs) and the external world
add_subdirectory({{ controller_path }})

# handles the Qt models
add_subdirectory({{ presenter_path }})

{% if front_ends.qt_quick.enabled -%}

if(BUILD_QT_QUICK)
    # handles the QtQuick front end
    add_subdirectory({{ front_ends.qt_quick.folder_path }})
endif()
{% endif %}
{% if  front_ends.qt_widgets.enabled -%}

if(BUILD_QT_WIDGETS)
    # handles the QtWidgets front end
    add_subdirectory({{ front_ends.qt_widgets.folder_path }})
endif()
{% endif %}
{% if front_ends.kf6_kirigami.enabled -%}

if(BUILD_KF6_KIRIGAMI)
    # handles the Kirigami front end
    add_subdirectory({{ front_ends.kf6_kirigami.folder_path }})
endif()
{% endif %}
{% if front_ends.kf6_widgets.enabled -%}

if(BUILD_KF6_WIDGETS)
    # handles the KF6Widgets front end
    add_subdirectory({{ front_ends.kf6_widgets.folder_path }})
endif()

{% endif %}

{% if front_ends.kf6_widgets.enabled -%}

if(BUILD_KF6_WIDGETS)
    add_subdirectory(icons)
endif()
{% endif %}

{% if front_ends.kf6_widgets.enabled or front_ends.kf6_kirigami.enabled -%}

if(BUILD_KF6)
    install(FILES org.kde.{{ application_name_lower }}.desktop DESTINATION ${KDE_INSTALL_APPDIR})
    install(FILES org.kde.{{ application_name_lower }}.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR})

    ki18n_install(po)

    feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)

    if(NOT ANDROID)
        file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES src/*.cpp src/*.h)
        kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
        kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)
    endif()
endif()
    {% endif %}
