-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
105 lines (89 loc) · 2.93 KB
/
CMakeLists.txt
File metadata and controls
105 lines (89 loc) · 2.93 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright 2026 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(TARGET_NAME svs_c_api_test)
# Check if Catch2 is available
find_package(Catch2 3 QUIET)
if(NOT Catch2_FOUND)
message(STATUS "Catch2 not found, fetching from GitHub...")
include(FetchContent)
# Do wide printing for the console logger for Catch2
set(CATCH_CONFIG_CONSOLE_WIDTH "100" CACHE STRING "" FORCE)
set(CATCH_BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(CATCH_CONFIG_ENABLE_BENCHMARKING OFF CACHE BOOL "" FORCE)
set(CATCH_CONFIG_FAST_COMPILE OFF CACHE BOOL "" FORCE)
set(CATCH_CONFIG_PREFIX_ALL ON CACHE BOOL "" FORCE)
set(PRESET_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
set(CMAKE_CXX_STANDARD 20)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.11.0
)
FetchContent_MakeAvailable(Catch2)
set(CMAKE_CXX_STANDARD ${PRESET_CMAKE_CXX_STANDARD})
endif()
# Define test sources
set(C_API_TEST_SOURCES
c_api_error.cpp
c_api_algorithm.cpp
c_api_storage.cpp
c_api_search_params.cpp
c_api_index_builder.cpp
c_api_index.cpp
c_api_dynamic_index.cpp
)
# Create test executable
add_executable(${TARGET_NAME} ${C_API_TEST_SOURCES})
# Link with C API library and Catch2
target_link_libraries(${TARGET_NAME} PRIVATE
svs_c_api
Catch2::Catch2WithMain
)
# Set C++ standard
target_compile_features(${TARGET_NAME} PRIVATE cxx_std_20)
set_target_properties(${TARGET_NAME} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)
# Include directories
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
# Add test to CTest
include(CTest)
enable_testing()
# Add the test to CTest
add_test(NAME ${TARGET_NAME} COMMAND ${TARGET_NAME})
# Set test properties
set_tests_properties(${TARGET_NAME} PROPERTIES
LABELS "c_api"
)
# Add Catch2 CMake module path
if(NOT Catch2_FOUND)
# Catch2 was fetched, use its source directory
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
else()
# Catch2 was found via find_package, use its module directory
list(APPEND CMAKE_MODULE_PATH ${Catch2_DIR})
endif()
include(Catch)
catch_discover_tests(${TARGET_NAME})
# Add a custom target to run tests
add_custom_target(run_c_api_tests
COMMAND ${TARGET_NAME}
DEPENDS ${TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running C API tests..."
)