cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)

#######################################################################
### append test cases here (file name without the ".cpp" suffix)
#######################################################################
set(test_cases
    test_info
    )

###################################################
### Set up tests using GoogleTest (GTest)
###################################################

# dependencies
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(KEEP_RPATHS)

# supress warnings during build of gtest
cmake_policy(SET CMP0054 NEW)
enable_testing()

# add special cmake functions for gtest
include(GoogleTest REQUIRED)

# loop over all test cases and add them to the test runner
list(LENGTH test_cases len_test_cases)
math(EXPR len_test_cases "${len_test_cases} - 1")
foreach (i RANGE "${len_test_cases}")
    list(GET test_cases ${i} test_case_name)
    add_executable(${test_case_name} ${test_case_name}.cpp)
    target_link_libraries(${test_case_name} PRIVATE ${CONAN_LIBS_CAOSDB}
        ${CONAN_LIBS_GTEST} ${CONAN_LIBS_GRPC} ${CONAN_LIBS_ABSEIL}
        ${CONAN_LIBS_OPENSSL} ${CONAN_LIBS_C-ARES} ${CONAN_LIBS_BZIP2}
        ${CONAN_LIBS_PROTOBUF} ${CONAN_LIBS_ZLIB})
    if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
        target_link_libraries(${test_case_name} PRIVATE caosdb_grpc)
    endif()
    target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS})
    set_target_properties(${test_case_name}
        PROPERTIES
        CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}"
        CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}")
    gtest_discover_tests(${test_case_name}
        PROPERTIES
            LABELS "caosdb-cpplib-int-tests")
endforeach ()
