cmake_minimum_required(VERSION 3.16)
project(LibraryManager 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 Sql)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Sql)
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(LibraryManager WIN32 main.cpp appearance.h mainwindow.cpp mainwindow.h librarystore.cpp librarystore.h mainwindow.ui)
target_include_directories(LibraryManager PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(LibraryManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql)
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_LibraryManager tests/test_LibraryManager.cpp mainwindow.cpp mainwindow.h
                   librarystore.cpp librarystore.h mainwindow.ui)
    target_include_directories(test_LibraryManager PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
    target_link_libraries(test_LibraryManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql Qt${QT_VERSION_MAJOR}::Test)
    if(WIN32)
        set(TEST_PLATFORM windows)
    else()
        set(TEST_PLATFORM offscreen)
    endif()
    add_test(NAME LibraryManager COMMAND test_LibraryManager -platform ${TEST_PLATFORM} -o ${CMAKE_CURRENT_BINARY_DIR}/test_report.txt,txt)
    set_tests_properties(LibraryManager PROPERTIES TIMEOUT 30)
endif()

