cmake_minimum_required(VERSION 3.20)

project(nebula-shell LANGUAGES CXX)

if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
    message(FATAL_ERROR
        "nebula-shell is a Linux Wayland shell using LayerShellQt.\n"
        "Build and run it on the Ubuntu NebulaOS VM. Windows is not a supported target, "
        "and LayerShellQt is not stubbed with other platform APIs.")
endif()



set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(Qt6 6.4 REQUIRED COMPONENTS Core Gui Qml Quick)
find_package(LayerShellQt REQUIRED)

qt_standard_project_setup(REQUIRES 6.4)

set(QT_QML_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/qml")

add_subdirectory(
    "${CMAKE_CURRENT_SOURCE_DIR}/../../../packages/nebula-ui"
    "${CMAKE_CURRENT_BINARY_DIR}/nebula-ui"
)

qt_add_executable(nebula-shell
    src/main.cpp
)

set(NEBULA_SHELL_QML_FILES
    qml/Main.qml
    qml/ShellState.qml
    qml/surfaces/DesktopSurface.qml
    qml/surfaces/TopBarSurface.qml
    qml/surfaces/LauncherSurface.qml
    qml/components/TopBar.qml
    qml/components/NebulaButton.qml
    qml/components/Clock.qml
    qml/components/SystemArea.qml
    qml/components/Launcher.qml
    qml/components/AppItem.qml
    qml/mock/MockApps.qml
)

foreach(qml_file IN LISTS NEBULA_SHELL_QML_FILES)
    get_filename_component(qml_name "${qml_file}" NAME)
    set_source_files_properties("${qml_file}" PROPERTIES
        QT_RESOURCE_ALIAS "${qml_name}"
    )
endforeach()

set_source_files_properties(qml/ShellState.qml PROPERTIES
    QT_QML_SINGLETON_TYPE TRUE
    QT_RESOURCE_ALIAS ShellState.qml
)
set_source_files_properties(qml/mock/MockApps.qml PROPERTIES
    QT_QML_SINGLETON_TYPE TRUE
    QT_RESOURCE_ALIAS MockApps.qml
)

qt_add_qml_module(nebula-shell
    URI Nebula.Shell
    VERSION 1.0
    RESOURCE_PREFIX /qt/qml
    QML_FILES ${NEBULA_SHELL_QML_FILES}
    DEPENDENCIES
        QtQuick
        Nebula.UI
)

target_link_libraries(nebula-shell
    PRIVATE
        Qt6::Core
        Qt6::Gui
        Qt6::Qml
        Qt6::Quick
        LayerShellQt::Interface
        NebulaUI
)

if(TARGET NebulaUIplugin)
    target_link_libraries(nebula-shell PRIVATE NebulaUIplugin)
endif()

set_target_properties(nebula-shell PROPERTIES
    OUTPUT_NAME nebula-shell
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)

if(COMMAND qt_import_qml_plugins)
    
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    target_compile_options(nebula-shell PRIVATE -Wall -Wextra)
endif()
