# The real minimum version will be checked by the qtbase project.
# 3.16 is the absolute minimum though.
cmake_minimum_required(VERSION 3.16...3.20)

# Include qtbase's .cmake.conf for access to QT_REPO_MODULE_VERSION
set(__qt6_qtbase_src_path "${CMAKE_CURRENT_SOURCE_DIR}/qtbase")
include("${__qt6_qtbase_src_path}/.cmake.conf")

# Run platform auto-detection /before/ the first project() call and thus
# before the toolchain file is loaded.
include("${__qt6_qtbase_src_path}/cmake/QtAutoDetect.cmake")

project(Qt
    VERSION "${QT_REPO_MODULE_VERSION}"
    DESCRIPTION "Qt Libraries"
    HOMEPAGE_URL "https://qt.io/"
    LANGUAGES CXX C ASM
)

# Required so we can call ctest from the root build directory
enable_testing()

set(qt_module_prop_prefix "__qt_prop_")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${__qt6_qtbase_src_path}/cmake")
list(APPEND CMAKE_MODULE_PATH
    "${__qt6_qtbase_src_path}/cmake/3rdparty/extra-cmake-modules/find-modules")
list(APPEND CMAKE_MODULE_PATH "${__qt6_qtbase_src_path}/cmake/3rdparty/kwin")

# Also make sure the CMake config files do not recreate the already-existing targets
set(QT_NO_CREATE_TARGETS TRUE)
set(QT_SUPERBUILD TRUE)

set(QT_BUILD_SUBMODULES "qtbase;qtsvg;qtwebsockets;qtshadertools;qtmultimedia;qtwayland" CACHE STRING "Submodules to build")

foreach(module IN LISTS QT_BUILD_SUBMODULES)
    message(NOTICE "Configuring '${module}'")
    add_subdirectory("${module}")

    if(module STREQUAL "qtbase")
        list(APPEND CMAKE_PREFIX_PATH "${QtBase_BINARY_DIR}/lib/cmake")
        list(APPEND CMAKE_FIND_ROOT_PATH "${QtBase_BINARY_DIR}")
    endif()
endforeach()

# Display a summary of everything
include(QtBuildInformation)
include(QtPlatformSupport)
qt_print_feature_summary()
qt_print_build_instructions()
