cmake_minimum_required(VERSION 3.5)

project(%{TestCaseName} LANGUAGES CXX)

@if "%{TestFrameWork}" == "QtTest"

find_package(Qt5Test REQUIRED)
@if "%{RequireGUI}" == "true"
find_package(Qt5Gui REQUIRED)
@endif

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
enable_testing()

add_executable(%{TestCaseName} %{TestCaseFileWithCppSuffix})
add_test(NAME %{TestCaseName} COMMAND %{TestCaseName})

@if "%{RequireGUI}" == "true"
target_link_libraries(%{TestCaseName} PRIVATE Qt5::Gui Qt5::Test)
@else
target_link_libraries(%{TestCaseName} PRIVATE Qt5::Test)
@endif

@endif
@if "%{TestFrameWork}" == "QtQuickTest"
find_package(Qt5QuickTest REQUIRED)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
enable_testing()

# 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}")

add_executable(%{TestCaseName} %{MainCppName})
add_test(NAME %{TestCaseName} COMMAND %{TestCaseName})

target_link_libraries(%{TestCaseName} PRIVATE Qt5::QuickTest)

@endif
@if  "%{TestFrameWork}" == "GTest"

@if "%{GTestCXX11}" == "true"
add_definitions(-DGTEST_LANGUAGE_CXX11)
@endif

find_package(Threads REQUIRED)

if ($ENV{GOOGLETEST_DIR})
    set(GOOGLETEST_DIR $ENV{GOOGLETEST_DIR})
else ()
    if (NOT "%{GTestRepository}" STREQUAL "")
        message(WARNING "Using googletest src dir specified at Qt Creator wizard")
    endif ()
    set(GOOGLETEST_DIR "%{GTestRepository}")
endif ()
if (EXISTS ${GOOGLETEST_DIR})
    set(GTestSrc ${GOOGLETEST_DIR}/googletest)
    set(GMockSrc ${GOOGLETEST_DIR}/googlemock)
elseif (UNIX AND EXISTS /usr/src/gtest)
    set(GTestSrc /usr/src/gtest)
    message(WARNING "Using gtest from system")
    if (EXISTS /usr/src/gmock)
        set(GMockSrc /usr/src/gmock)
    endif ()
else ()
    message( FATAL_ERROR "No googletest src dir found - set GOOGLETEST_DIR to enable!")
endif ()

set(GTestFiles ${GTestSrc}/src/gtest-all.cc)
set(GTestIncludes ${GTestSrc} ${GTestSrc}/include)
if (NOT ${GMockSrc} STREQUAL "")
    list(APPEND GTestFiles ${GMockSrc}/src/gmock-all.cc)
    list(APPEND GTestIncludes ${GMockSrc} ${GMockSrc}/include)
endif ()

include_directories(${GTestIncludes})

add_executable(%{TestCaseName} %{MainCppName} %{TestCaseFileWithHeaderSuffix}
               ${GTestFiles})
add_test(NAME %{TestCaseName} COMMAND %{TestCaseName})
target_link_libraries(%{TestCaseName} PRIVATE Threads::Threads)

@endif
@if "%{TestFrameWork}" == "BoostTest"
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
enable_testing()

add_executable(%{TestCaseName} %{MainCppName})
add_test(NAME %{TestCaseName} COMMAND %{TestCaseName})

if (DEFINED ENV{BOOST_INCLUDE_DIR})
    set(BOOST_INCLUDE_DIR $ENV{BOOST_INCLUDE_DIR})
else ()
    set(BOOST_INCLUDE_DIR "%{BoostIncDir}") # set by Qt Creator wizard
endif ()
if (BOOST_INCLUDE_DIR STREQUAL "")
    message("BOOST_INCLUDE_DIR is not set, assuming Boost can be found automatically in your system")
elseif (EXISTS ${BOOST_INCLUDE_DIR})
    include_directories(${BOOST_INCLUDE_DIR})
endif ()
@endif
