cmake_minimum_required(VERSION 3.21)

project(%{ProjectName} VERSION 0.1 LANGUAGES CXX)

enable_testing()

@if !%{HasQSPSetup}
set(CMAKE_AUTOMOC ON)
@endif
set(CMAKE_CXX_STANDARD_REQUIRED ON)

@if "%{TestFrameWork}" == "QtTest"
@if "%{RequireGUI}" == "true"
find_package(Qt6 REQUIRED COMPONENTS Gui Test)
@else
find_package(Qt6 REQUIRED COMPONENTS Test)
@endif
@endif
@if "%{TestFrameWork}" == "QtQuickTest"
@if "%{UseSetupCode}" == "true"
find_package(Qt6 REQUIRED COMPONENTS QuickTest Qml)
@else
find_package(Qt6 REQUIRED COMPONENTS QuickTest)
@endif
@endif

@if "%{TestFrameWork}" == "QtTest"
qt_standard_project_setup()
@endif
@if "%{TestFrameWork}" == "QtQuickTest"
@if %{HasQSPSetup}
@if %{UsesAutoResourcePrefix}
qt_standard_project_setup(REQUIRES %{MinimumSupportedQtVersion})
@else
qt_standard_project_setup()
@endif
@endif
@endif

qt_add_executable(%{TestCaseName}
@if "%{TestFrameWork}" == "QtTest"
    %{TestCaseFileWithCppSuffix}
@endif
@if "%{TestFrameWork}" == "QtQuickTest"
    %{MainCppName}
@if "%{UseSetupCode}" == "true"
    setup.cpp setup.h
@endif
@endif
)
add_test(NAME %{TestCaseName} COMMAND %{TestCaseName})

@if "%{TestFrameWork}" == "QtQuickTest"
# no need to copy around qml test files for shadow builds - just set the respective define
add_definitions(-DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")

file(GLOB_RECURSE QML_FILES *.qml)
add_custom_target(%{TestCaseName}_qmlfiles SOURCES ${QML_FILES})
@endif

set_target_properties(%{TestCaseName} PROPERTIES
    MACOSX_BUNDLE FALSE
    WIN32_EXECUTABLE FALSE
)

target_link_libraries(%{TestCaseName}
@if "%{TestFrameWork}" == "QtTest"
@if "%{RequireGUI}" == "true"
    PRIVATE Qt6::Gui
@endif
    PRIVATE Qt6::Test
@endif
@if "%{TestFrameWork}" == "QtQuickTest"
@if "%{UseSetupCode}"
    PRIVATE Qt6::Qml
@endif
    PRIVATE Qt6::QuickTest
@endif
)
