Warning, /algorithms/core/tests/CMakeLists.txt is written in an unsupported language. File is not indexed.
0001 # SPDX-License-Identifier: LGPL-3.0-or-later
0002 # Copyright (C) 2026 Wouter Deconinck
0003
0004 ################################################################################
0005 # Package: algorithms core utilities - tests
0006 ################################################################################
0007
0008 find_package(Catch2 3)
0009 if(NOT Catch2_FOUND)
0010 message(WARNING "Catch2 v3 not found, skipping ${LIBRARY} tests")
0011 return()
0012 endif()
0013 include(Catch)
0014 find_package(Threads REQUIRED)
0015
0016 # One executable per test source, so tests of process-wide singleton services
0017 # (ServiceSvc, LogSvc, RandomSvc, GeoSvc) do not affect each other
0018 file(GLOB TEST_SRC CONFIGURE_DEPENDS *.cpp)
0019
0020 foreach(SRC ${TEST_SRC})
0021 get_filename_component(NAME ${SRC} NAME_WE)
0022 set(TEST_NAME "${LIBRARY}_${NAME}_test")
0023
0024 add_executable(${TEST_NAME} ${SRC})
0025 target_link_libraries(${TEST_NAME}
0026 PRIVATE
0027 algorithms::${LIBRARY}
0028 Catch2::Catch2WithMain
0029 Threads::Threads)
0030 target_compile_definitions(${TEST_NAME}
0031 PRIVATE
0032 TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
0033
0034 # Prepend the build directory to LD_LIBRARY_PATH, so tests use the library that
0035 # was just built rather than an installed version found through LD_LIBRARY_PATH
0036 if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
0037 set(DL_PATHS DL_PATHS $<TARGET_FILE_DIR:${LIBRARY}>)
0038 endif()
0039 catch_discover_tests(${TEST_NAME} TEST_PREFIX "${LIBRARY}/${NAME}/" ${DL_PATHS})
0040 endforeach()