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

# Every target qt_add_qml_module creates for this STATIC module (including
# the resource sub-targets) is compiled with -fPIC, so its objects can be
# linked into any position-independent consumer: the daemon, editor and
# settings executables today, and a shared library should one adopt the
# module. 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, including the several that qt_add_qml_module generates
# implicitly. They are deliberately NOT enumerated here: the set changes
# between Qt versions, and a stale list reads as a promise this directory
# cannot keep. See the DIRECTORY-scope note below.
# 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
        ShaderErrorBanner.qml
        ShaderPreviewPlaceholder.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}>
)
