2023-08-30 22:20:37 +02:00
|
|
|
cmake_minimum_required(VERSION 3.11)
|
2019-07-01 02:06:09 +03:00
|
|
|
project(spdlog_utests CXX)
|
|
|
|
|
|
2020-09-26 15:34:05 +03:00
|
|
|
if(NOT TARGET spdlog)
|
2020-05-02 11:42:08 +03:00
|
|
|
# Stand-alone build
|
|
|
|
|
find_package(spdlog REQUIRED)
|
2020-09-26 15:34:05 +03:00
|
|
|
endif()
|
2020-02-07 15:39:26 +01:00
|
|
|
|
2019-07-01 15:03:53 +03:00
|
|
|
include(../cmake/utils.cmake)
|
|
|
|
|
|
2019-06-28 17:29:52 +03:00
|
|
|
find_package(PkgConfig)
|
2020-09-26 15:34:05 +03:00
|
|
|
if(PkgConfig_FOUND)
|
2020-05-02 11:42:08 +03:00
|
|
|
pkg_check_modules(systemd libsystemd)
|
2020-09-26 15:34:05 +03:00
|
|
|
endif()
|
2019-06-28 17:29:52 +03:00
|
|
|
|
2023-03-01 12:51:04 +01:00
|
|
|
find_package(Catch2 3 QUIET)
|
2023-06-07 13:23:44 +03:00
|
|
|
if(Catch2_FOUND)
|
2023-03-01 12:51:04 +01:00
|
|
|
message(STATUS "Packaged version of Catch will be used.")
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Bundled version of Catch will be downloaded and used.")
|
|
|
|
|
include(FetchContent)
|
2025-05-08 14:02:00 +03:00
|
|
|
FetchContent_Declare(
|
|
|
|
|
Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
|
|
|
|
GIT_TAG 53d0d913a422d356b23dd927547febdf69ee9081 # v3.5.0
|
2023-12-22 18:15:50 +02:00
|
|
|
)
|
2023-03-01 12:51:04 +01:00
|
|
|
FetchContent_MakeAvailable(Catch2)
|
|
|
|
|
endif()
|
|
|
|
|
|
2018-02-11 20:45:56 +01:00
|
|
|
set(SPDLOG_UTESTS_SOURCES
|
2020-09-26 15:34:05 +03:00
|
|
|
test_file_helper.cpp
|
|
|
|
|
test_file_logging.cpp
|
|
|
|
|
test_daily_logger.cpp
|
|
|
|
|
test_misc.cpp
|
|
|
|
|
test_eventlog.cpp
|
|
|
|
|
test_pattern_formatter.cpp
|
|
|
|
|
test_async.cpp
|
|
|
|
|
test_registry.cpp
|
|
|
|
|
test_macros.cpp
|
|
|
|
|
utils.cpp
|
|
|
|
|
main.cpp
|
|
|
|
|
test_mpmc_q.cpp
|
|
|
|
|
test_dup_filter.cpp
|
|
|
|
|
test_fmt_helper.cpp
|
|
|
|
|
test_stdout_api.cpp
|
|
|
|
|
test_backtrace.cpp
|
|
|
|
|
test_create_dir.cpp
|
2023-01-19 21:16:34 +03:30
|
|
|
test_custom_callbacks.cpp
|
2020-09-26 15:34:05 +03:00
|
|
|
test_cfg.cpp
|
|
|
|
|
test_time_point.cpp
|
2023-08-05 17:03:04 +03:00
|
|
|
test_stopwatch.cpp
|
2025-01-11 16:21:39 +01:00
|
|
|
test_circular_q.cpp
|
|
|
|
|
test_bin_to_hex.cpp)
|
2018-02-11 20:45:56 +01:00
|
|
|
|
2020-09-26 15:34:05 +03:00
|
|
|
if(NOT SPDLOG_NO_EXCEPTIONS)
|
2020-05-02 11:42:08 +03:00
|
|
|
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
2020-09-26 15:34:05 +03:00
|
|
|
endif()
|
2019-08-19 11:31:33 +03:00
|
|
|
|
2020-09-26 15:34:05 +03:00
|
|
|
if(systemd_FOUND)
|
2020-05-02 11:42:08 +03:00
|
|
|
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
2020-09-26 15:34:05 +03:00
|
|
|
endif()
|
2019-06-28 17:29:52 +03:00
|
|
|
|
2018-08-14 21:33:47 +02:00
|
|
|
enable_testing()
|
2019-05-29 00:04:36 +03:00
|
|
|
|
2019-10-25 10:19:15 +03:00
|
|
|
function(spdlog_prepare_test test_target spdlog_lib)
|
2020-05-02 11:42:08 +03:00
|
|
|
add_executable(${test_target} ${SPDLOG_UTESTS_SOURCES})
|
|
|
|
|
spdlog_enable_warnings(${test_target})
|
|
|
|
|
target_link_libraries(${test_target} PRIVATE ${spdlog_lib})
|
2020-09-26 15:34:05 +03:00
|
|
|
if(systemd_FOUND)
|
2020-05-02 11:42:08 +03:00
|
|
|
target_link_libraries(${test_target} PRIVATE ${systemd_LIBRARIES})
|
2020-09-26 15:34:05 +03:00
|
|
|
endif()
|
2023-03-01 12:51:04 +01:00
|
|
|
target_link_libraries(${test_target} PRIVATE Catch2::Catch2WithMain)
|
2020-09-26 15:34:05 +03:00
|
|
|
if(SPDLOG_SANITIZE_ADDRESS)
|
2024-11-01 15:14:27 +02:00
|
|
|
spdlog_enable_addr_sanitizer(${test_target})
|
2025-05-08 14:02:00 +03:00
|
|
|
elseif(SPDLOG_SANITIZE_THREAD)
|
2024-11-01 15:14:27 +02:00
|
|
|
spdlog_enable_thread_sanitizer(${test_target})
|
2025-05-08 14:02:00 +03:00
|
|
|
endif()
|
2020-05-02 11:42:08 +03:00
|
|
|
add_test(NAME ${test_target} COMMAND ${test_target})
|
|
|
|
|
set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON)
|
2019-10-25 10:19:15 +03:00
|
|
|
endfunction()
|
2019-10-24 22:57:47 +03:00
|
|
|
|
|
|
|
|
# The compiled library tests
|
2020-09-26 15:34:05 +03:00
|
|
|
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
|
2020-05-02 11:42:08 +03:00
|
|
|
spdlog_prepare_test(spdlog-utests spdlog::spdlog)
|
2020-09-26 15:34:05 +03:00
|
|
|
endif()
|
2019-05-29 00:04:36 +03:00
|
|
|
|
|
|
|
|
# The header-only library version tests
|
2020-09-26 15:34:05 +03:00
|
|
|
if(SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
|
2020-05-02 11:42:08 +03:00
|
|
|
spdlog_prepare_test(spdlog-utests-ho spdlog::spdlog_header_only)
|
2020-09-26 15:34:05 +03:00
|
|
|
endif()
|