# SPDX-FileCopyrightText: 2014-2020 Marco Martin <mart@kde.org>
# SPDX-FileCopyrightText: 2017-2021 Bhushan Shah <bshah@kde.org>
# SPDX-FileCopyrightText: 2019-2021 Nicolas Fella <nicolas.fella@kde.org>
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later

cmake_minimum_required(VERSION 3.24)

project(plasma-mobile)
set(PROJECT_VERSION "6.6.80")

set(PROJECT_DEP_VERSION "6.5.90")
set(QT_MIN_VERSION "6.10.0")
set(KF6_MIN_VERSION "6.22.0")
set(KDE_COMPILERSETTINGS_LEVEL "5.82")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(INSTALL_SYSTEMD_SERVICE "Install a systemd service file to start the session" OFF)
option(PLASMA_MOBILE_LOCAL_KAUTH_INSTALL "Install KAuth helpers and policies into CMAKE_INSTALL_PREFIX for local rootless development" OFF)

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

set(KF_IGNORE_PLATFORM_CHECK ON CACHE BOOL "Don't check platform that is being built on")

include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMOptionalAddSubdirectory)
include(ECMInstallIcons)
include(ECMSetupVersion)
include(ECMMarkNonGuiExecutable)
include(ECMGenerateHeaders)
include(ECMFindQmlModule)
include(ECMGenerateQmlTypes)
include(ECMConfiguredInstall)
include(ECMFindQmlModule)
include(ECMQtDeclareLoggingCategory)
include(GenerateExportHeader)
include(KDEGitCommitHooks)
include(KDEClangFormat)
include(FeatureSummary)

add_definitions(-DQT_NO_URL_CAST_FROM_STRING)

ecm_setup_version(${PROJECT_VERSION}
    VARIABLE_PREFIX PLASMA_MOBILE
    VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/version.h
)

find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED
    Core
    Qml
    Quick
    Gui
    Sensors
    WaylandClient
)

if(Qt6WaylandClient_VERSION VERSION_GREATER_EQUAL "6.10.0")
    find_package(Qt6 REQUIRED COMPONENTS WaylandClientPrivate)
endif()

find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS
    I18n
    GlobalAccel
    KIO
    Config
    DBusAddons
    ItemModels
    Service
    Notifications
    ModemManagerQt
    NetworkManagerQt
    KCMUtils
    Package
    JobWidgets
    WindowSystem
)

find_package(Plasma CONFIG REQUIRED)
find_package(PlasmaQuick CONFIG REQUIRED)
find_package(PlasmaActivities CONFIG REQUIRED)
find_package(LibTaskManager CONFIG REQUIRED)
find_package(KF6Screen CONFIG REQUIRED)
find_package(KWayland CONFIG REQUIRED)
find_package(KPipeWire ${PROJECT_DEP_VERSION} REQUIRED)

find_package(PkgConfig REQUIRED)

find_package(QCoro6 REQUIRED COMPONENTS DBus Qml)
qcoro_enable_coroutines()
kde_enable_exceptions()

find_package(KF6KirigamiAddons 0.6 REQUIRED)
find_package(epoxy REQUIRED)
find_package(XCB REQUIRED COMPONENTS XCB)
find_package(KWin ${PROJECT_DEP_VERSION} REQUIRED COMPONENTS
    kwin
)

find_package(LayerShellQt REQUIRED)
find_package(Wayland REQUIRED)
find_package(PlasmaWaylandProtocols 1.8 CONFIG)
set_package_properties(PlasmaWaylandProtocols PROPERTIES
    TYPE REQUIRED
    PURPOSE "Collection of Plasma-specific Wayland protocols"
    URL "https://invent.kde.org/libraries/plasma-wayland-protocols/"
)


find_package(LibKWorkspace CONFIG REQUIRED)
find_package(Libudev REQUIRED)
find_package(SDL3)

find_package(KWinDBusInterface)
set_package_properties(KWinDBusInterface PROPERTIES DESCRIPTION "KWin DBus interface"
    TYPE REQUIRED
    PURPOSE "Needed for virtual keyboard toggle button"
)

find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS Auth)
set_package_properties(KF6::AuthCore PROPERTIES
    TYPE REQUIRED
    PURPOSE "Allows SHIFT to configure Waydroid"
)

if(PLASMA_MOBILE_LOCAL_KAUTH_INSTALL)
    set(KAUTH_HELPER_INSTALL_DIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/kf6/kauth")
    set(KAUTH_HELPER_INSTALL_ABSOLUTE_DIR "${KAUTH_HELPER_INSTALL_DIR}")
    set(KAUTH_POLICY_FILES_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/polkit-1/actions")
    set(INSTALL_BROKEN_KAUTH_POLICY_FILES ON)
endif()

include(CheckIncludeFiles)

ecm_find_qmlmodule(org.kde.pipewire 0.1)

set(SHIFT_DEFAULT_WALLPAPER_URL "file://${KDE_INSTALL_FULL_WALLPAPERDIR}/SHIFT/contents/images_dark/5120x2880.png")
set(SHIFT_SHELL_PACKAGE_DIR "${CMAKE_CURRENT_BINARY_DIR}/shell")
file(REMOVE_RECURSE "${SHIFT_SHELL_PACKAGE_DIR}")
file(COPY shell/ DESTINATION "${SHIFT_SHELL_PACKAGE_DIR}" PATTERN "layout.js.in" EXCLUDE)
configure_file(shell/contents/layout.js.in "${SHIFT_SHELL_PACKAGE_DIR}/contents/layout.js" @ONLY)

plasma_install_package(lookandfeel org.shift.mobile look-and-feel lookandfeel)
plasma_install_package(${SHIFT_SHELL_PACKAGE_DIR} org.kde.plasma.mobileshell shells)

add_subdirectory(bin)
add_subdirectory(color-schemes)
add_subdirectory(cursors)
add_subdirectory(desktoptheme)
add_subdirectory(fonts)
add_subdirectory(icons)
add_subdirectory(tools/preview-stubs)
add_subdirectory(wallpapers)
add_subdirectory(components)
add_subdirectory(containments)
add_subdirectory(devices)
add_subdirectory(quicksettings)
add_subdirectory(kcms)
add_subdirectory(kded)
add_subdirectory(kwin)
add_subdirectory(envmanager)
add_subdirectory(initialstart)
add_subdirectory(layout-templates)
if(BUILD_TESTING)
    add_subdirectory(tests)
endif()

install(CODE "file(REMOVE \"\$ENV{DESTDIR}${KDE_INSTALL_FULL_METAINFODIR}/org.kde.plasma.mobileshell.metainfo.xml\")")
install(FILES org.shift.mobile.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR})

find_program(PlasmaOpenSettings plasma-open-settings)
set_package_properties(PlasmaOpenSettings PROPERTIES
                                          URL https://invent.kde.org/plasma/kde-cli-tools/
                                          DESCRIPTION "Opens KCMs properly"
                                          TYPE RUNTIME
                                          PURPOSE "Used on the top panel")

feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)

# add clang-format target for all our real source files
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)

ki18n_install(po)

install(CODE "
file(GLOB _stale_shift_lookandfeel_catalogs \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/locale/*/LC_MESSAGES/plasma_lookandfeel_org.kde.breeze.mobile.mo\")
foreach(_catalog IN LISTS _stale_shift_lookandfeel_catalogs)
    file(REMOVE \"\${_catalog}\")
endforeach()
")

if (INSTALL_SYSTEMD_SERVICE)
    install(FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/plasma-mobile.service
        DESTINATION ${KDE_INSTALL_SYSTEMDUNITDIR}/system
    )
endif()

ecm_qt_install_logging_categories(
    EXPORT PLASMA_MOBILE
    FILE plasmamobile.categories
    DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}
)
