Skip to content

Commit dc3537c

Browse files
committed
Added and built tests
1 parent bf0a0a4 commit dc3537c

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

CMakeLists.txt

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.14)
22

33
project("liburing")
44
set(libname "uring")
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
56

7+
############################
8+
## Add headers to library ##
9+
############################
610
function(add_headers VAR dir)
711
set(headers ${${VAR}})
812
foreach (header ${ARGN})
@@ -11,10 +15,6 @@ function(add_headers VAR dir)
1115
set(${VAR} ${headers} PARENT_SCOPE)
1216
endfunction()
1317

14-
############################
15-
## Add headers to library ##
16-
############################
17-
1818
add_headers(
1919
liburing_headers # Variable name
2020
src/include # Directory to find headers
@@ -32,3 +32,49 @@ target_include_directories(
3232
PUBLIC
3333
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/include/>
3434
$<INSTALL_INTERFACE:include>)
35+
36+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
37+
include(CTest)
38+
39+
# Tests need to be linked against pthreads
40+
set(THREADS_PREFER_PTHREAD_FLAG ON)
41+
find_package(Threads REQUIRED)
42+
43+
set(liburing_test_flags
44+
-include "${PROJECT_SOURCE_DIR}/config-host.h"
45+
-g
46+
-O2
47+
-D_GNU_SOURCE
48+
-D__SANE_USERSPACE_TYPES__
49+
-Wall
50+
-Wextra
51+
-Wno-unused-parameter
52+
-Wno-sign-compare
53+
-Wstringop-overflow=0
54+
-Warray-bounds=0)
55+
file(GLOB liburing_tests "test/*.c")
56+
# Remove the helpers.c, which doesn't contain a main
57+
list(FILTER liburing_tests EXCLUDE REGEX "helpers.c")
58+
foreach(test_file ${liburing_tests})
59+
60+
# Get the name of the target
61+
get_filename_component(target ${test_file} NAME_WLE)
62+
message("Adding test '${target}' from test/${target}.c")
63+
64+
# Create an executable target for the test; add test/helpers.c as a source
65+
add_executable(${target} ${test_file} test/helpers.c)
66+
67+
# Target liburing and pthreads
68+
target_link_libraries(
69+
${target}
70+
PRIVATE
71+
${libname}
72+
Threads::Threads)
73+
74+
# Add additional compiler options and definitions
75+
target_compile_options(${target} PRIVATE ${liburing_test_flags})
76+
77+
# Register the test with ctest
78+
add_test(NAME "test-${target}" COMMAND "${target}")
79+
endforeach()
80+
endif()

0 commit comments

Comments
 (0)