summaryrefslogtreecommitdiff
path: root/test/CMakeLists.txt
blob: 73968fe0a65539814880042dc4a62b7c531fb143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
include(FetchContent)

if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
    set(CVG_FLAGS -Wno-long-long -fsanitize=address -fsanitize=undefined -fprofile-arcs -ftest-coverage)
else()

endif()

set(gtest_URL https://github.com/google/googletest.git)
set(gtest_TAG v1.14.0)

FetchContent_Declare(
  googletest
  GIT_REPOSITORY ${gtest_URL}
  GIT_TAG        ${gtest_TAG}
)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)

enable_testing()

set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)

function(fud_add_test test_name)
    set(options NO_OPTIONS)
    set(oneValueArgs NO_ONE_VALUE_ARGS)
    set(multiValueArgs SOURCES)
    cmake_parse_arguments(FUD_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    add_executable(${test_name} test_common.cpp ${FUD_ADD_TEST_SOURCES})

    target_include_directories(${test_name} PUBLIC $<TARGET_PROPERTY:fud>)

    target_link_libraries(${test_name} PUBLIC GTest::gtest_main fud)

    target_compile_options(${test_name} PRIVATE ${CVG_FLAGS})
    target_link_options(${test_name} PRIVATE ${CVG_FLAGS})

    set_target_properties(
        ${test_name} PROPERTIES
        CXX_STANDARD 20
        C_STANDARD 23
        CXX_EXTENSIONS OFF
        C_EXTENSIONS OFF
        CXX_STANDARD_REQUIRED ON)

    gtest_discover_tests(${test_name})
endfunction()

fud_add_test(test_result SOURCES test_result.cpp)
fud_add_test(test_string SOURCES test_string.cpp)
fud_add_test(test_sqlite SOURCES test_sqlite.cpp)
# fud_add_test(test_deserialize_number SOURCES test_deserialize_number.cpp)
# fud_add_test(test_ext_algorithm SOURCES test_algorithm.cpp)
# fud_add_test(test_ext_array SOURCES
#     test_ext_array.cpp
#     test_ext_unique_array.cpp)
# fud_add_test(test_ext_utf8 SOURCES
#     test_ext_utf8.cpp)
# fud_add_test(test_ext_string SOURCES
#     test_ext_string.cpp
#     test_ext_string_cxx.cpp)
# fud_add_test(test_ext_string_format SOURCES
#     test_ext_string_format.cpp)

# fud_add_test(test_c_file SOURCES test_c_file.cpp)