cmake_minimum_required(VERSION 3.16)
project(RaffleGroups VERSION 1.0 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
if(QT_VERSION_MAJOR EQUAL 5 AND Qt5Core_VERSION VERSION_LESS 5.14.2)
    message(FATAL_ERROR "Qt 5.14.2 or newer is required.")
endif()
if(QT_VERSION_MAJOR EQUAL 6)
    set(CMAKE_CXX_STANDARD 17)
endif()
if(MSVC)
    add_compile_options(/utf-8)
else()
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()
add_executable(RaffleGroups WIN32 main.cpp appearance.h mainwindow.cpp mainwindow.h roster.cpp roster.h mainwindow.ui)
target_link_libraries(RaffleGroups PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
option(BUILD_TEACHING_TESTS "Build teaching project tests" OFF)
if(BUILD_TEACHING_TESTS)
    enable_testing()
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test)
    add_executable(test_RaffleGroups tests/test_RaffleGroups.cpp mainwindow.cpp mainwindow.h
                   roster.cpp roster.h mainwindow.ui)
    target_include_directories(test_RaffleGroups PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
    target_link_libraries(test_RaffleGroups PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Test)
    add_test(NAME RaffleGroups COMMAND test_RaffleGroups -platform offscreen)
endif()

