# SPDX-FileCopyrightText: 2026 fuddlesworth
# SPDX-License-Identifier: GPL-3.0-or-later
#
# PlasmaZones Shared QML Components

# Static QML module is linked into shared objects (KCM, editor) so all
# targets created by qt_add_qml_module (including resource sub-targets)
# must be compiled with -fPIC. Setting this before the call ensures all
# generated targets inherit it.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Suppress -Wmissing-include-dirs for every target defined in this
# subdirectory (main module, qmlplugin, qmlplugin_init, resource_1/_2,
# qmltyperegistration — all generated implicitly by qt_add_qml_module).
# KDECompilerSettings enables -Wmissing-include-dirs globally, and
# Qt adds `<target>_autogen/include` to each sub-target's -I list. That
# directory is populated by AUTOMOC as a build-time side effect; since
# sharedqmlplugin.cpp carries no Q_OBJECT declarations, MOC produces
# nothing and the include dir ends up either empty or — after
# `--clean-first` — missing entirely. cc1plus then fires the warning
# before AUTOMOC has a chance to recreate the path.
#
# Applying the suppression at the DIRECTORY level ensures every target
# generated by qt_add_qml_module picks it up, without having to enumerate
# the ever-changing list of resource / type-registration sub-targets by
# name. The warning is meaningful for human-authored -I paths, not for
# Qt-managed autogen scratch dirs, so scoping the suppression here keeps
# the rest of the project's warning discipline intact.
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Wno-missing-include-dirs")

# Registered as a QML singleton (mirrors the CurvePresets.qml pattern in
# src/settings/CMakeLists.txt): the source property must be set before the
# qt_add_qml_module call so the generated qmldir marks the type singleton.
set_source_files_properties(ZoneColorDefaults.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE)

qt_add_qml_module(plasmazones_shared_qml
    URI org.plasmazones.common
    VERSION 1.0
    STATIC
    RESOURCE_PREFIX /qt/qml
    SOURCES
        sharedqmlplugin.cpp
    QML_FILES
        AspectRatioBadge.qml
        AxisChevron.qml
        CapabilityBadgeRow.qml
        CategoryBadge.qml
        LayoutCard.qml
        PopupFrame.qml
        ShaderCompileErrorBanner.qml
        ShaderPreviewPlaceholder.qml
        SurfaceDecoration.qml
        StripEmptyState.qml
        ParameterEditor.qml
        ShaderParamsEditor.qml
        ParameterRow.qml
        ParameterSection.qml
        CategoryMenuButton.qml
        DecorationPreviewCard.qml
        ZoneColorDefaults.qml
        ZonePreview.qml
        ZoneShaderRenderer.qml
    OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml/org/plasmazones/common
)

target_link_libraries(plasmazones_shared_qml
    PUBLIC
        Qt6::Quick
        Qt6::QuickControls2
        PhosphorAnimation::PhosphorAnimation  # motion runtime + QML module
        PhosphorAnimationQmlplugin  # Generated by qt_add_qml_module (STATIC)
)

# Make headers available
target_include_directories(plasmazones_shared_qml
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
