cmake_minimum_required(VERSION 3.20)

set(MODULE_NAME "MyModule")
project(${MODULE_NAME} LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)
set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)

file(GLOB QML_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.qml)
source_group("Qml Files" FILES ${QML_SOURCES})

//! [add library]
qt_add_library(MyModule STATIC)

qt6_add_qml_module(MyModule
    URI MyModule
    VERSION 1.0
    QML_FILES ${QML_SOURCES}
)
//! [add library]

set_target_properties(MyModule PROPERTIES
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE FALSE
)

target_link_libraries(MyModule PRIVATE
    Qt::Core
    Qt::Gui
    Qt::Qml
    Qt::Quick
)

target_include_directories(MyModule PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
