if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
    message(FATAL_ERROR "MyStyle should be built as part of the 'attachedstyleproperties' project, and not in isolation.")
endif()

set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols/attachedstyleproperties")

qt_policy(SET QTP0001 NEW)
qt_add_qml_module(MyStyle
    URI MyStyle
    IMPORTS
        QtQuick.Controls.Material
    QML_FILES
        ApplicationWindow.qml
        Button.qml
        Label.qml
        Popup.qml
        Switch.qml
        ToolBar.qml
    SOURCES
        mystyle.cpp
        mystyle.h
)

include(GenerateExportHeader)
target_include_directories(MyStyle PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # find autogenerated header
generate_export_header(MyStyle)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml QuickControls2)

target_link_libraries(MyStyle PRIVATE
    Qt6::Core
    Qt6::Gui
    Qt6::Qml
    Qt6::QuickControls2
)

install(TARGETS MyStyle
    RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
    BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
    LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir
    DESTINATION "${INSTALL_EXAMPLEDIR}"
)
