-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
213 lines (173 loc) · 5.16 KB
/
CMakeLists.txt
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
cmake_minimum_required(VERSION 3.7)
project(caio
VERSION 5.1.1
LANGUAGES C
)
include(CMakeDependentOption)
# GCC and it's flags
set(CMAKE_C_COMPILER gcc)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fms-extensions")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
# Build type and debug symbols
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Include debug symbols" FORCE)
endif ()
if (CMAKE_BUILD_TYPE!=Release)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
endif ()
# Builtin modules
option(CAIO_MODULES "Enable caio modules system." ON)
if (CAIO_MODULES)
set(CAIO_MODULES_MAX 8 CACHE STRING "Maximum allowed modules.")
set_property(CACHE CAIO_MODULES_MAX PROPERTY STRINGS 4 8 32 64 128 256)
set(CAIO_MODULES_TICKTIMEOUT_SHORT_US 1000 CACHE
STRING "Modules short timeout in microseconds.")
set(CAIO_MODULES_TICKTIMEOUT_LONG_US 10000 CACHE
STRING "Modules short timeout in microseconds.")
else ()
unset(CAIO_MODULES_MAX CACHE)
endif ()
# Maximum allowed uring jobs per caio task
set(CAIO_URING_TASK_MAXWAITING 8 CACHE
STRING "Maximum allowed io_uring jobs per caio task.")
set_property(CACHE CAIO_URING_TASK_MAXWAITING PROPERTY
STRINGS 4 8 32 64 128 256)
# Builtin IO modules
cmake_dependent_option(CAIO_SIGNAL
"Enable caio signal modules."
ON "CAIO_MODULES" OFF)
cmake_dependent_option(CAIO_FDMON
"Enable caio IO modules."
ON "CAIO_MODULES" OFF)
cmake_dependent_option(CAIO_EPOLL
"Build and link epoll(7) caio IO module."
ON "CAIO_FDMON" OFF)
cmake_dependent_option(CAIO_SELECT
"Build and link select(2) caio IO module."
ON "CAIO_FDMON" OFF)
cmake_dependent_option(CAIO_URING
"Build and link io_uring(7) caio IO module."
ON "CAIO_FDMON" OFF)
# Menu config
add_custom_target(menu COMMAND ccmake ${PROJECT_BINARY_DIR} )
add_custom_target(fresh COMMAND cmake ${PROJECT_SOURCE_DIR} --fresh)
configure_file(caio/config.h.in caio/config.h @ONLY)
include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
add_library(caio STATIC SHARED)
target_sources(caio
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/caio/caio.h
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/caio/caio.c
${CMAKE_CURRENT_SOURCE_DIR}/caio/taskpool.h
${CMAKE_CURRENT_SOURCE_DIR}/caio/taskpool.c
${CMAKE_CURRENT_SOURCE_DIR}/caio/sleep.h
${CMAKE_CURRENT_SOURCE_DIR}/caio/sleep.c
)
add_library(caio_generic INTERFACE
caio/generic.h
caio/generic.c
)
if (CAIO_SIGNAL)
target_sources(caio
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/caio/signal.h
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/caio/signal.c
)
install(FILES caio/signal.h DESTINATION "include/caio")
endif ()
if (CAIO_FDMON)
target_sources(caio
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/caio/fdmon.h
${CMAKE_CURRENT_SOURCE_DIR}/caio/sleep.h
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/caio/sleep.c
)
install(FILES caio/fdmon.h DESTINATION "include/caio")
install(FILES caio/sleep.h DESTINATION "include/caio")
if (CAIO_EPOLL)
target_sources(caio
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/caio/epoll.h
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/caio/epoll.c
)
install(FILES caio/epoll.h DESTINATION "include/caio")
endif ()
if (CAIO_SELECT)
target_sources(caio
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/caio/select.h
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/caio/select.c
)
install(FILES caio/select.h DESTINATION "include/caio")
endif ()
endif ()
if (CAIO_URING)
target_sources(caio
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/caio/uring.h
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/caio/uring.c
)
target_link_libraries(caio PUBLIC uring)
install(FILES caio/uring.h DESTINATION "include/caio")
endif ()
# Install
install(TARGETS caio DESTINATION "lib")
install(FILES ${CMAKE_BINARY_DIR}/caio/config.h DESTINATION "include/caio")
install(FILES caio/caio.h DESTINATION "include/caio")
install(FILES caio/generic.h DESTINATION "include/caio")
install(FILES caio/generic.c DESTINATION "include/caio")
# Uninstall
add_custom_target("uninstall" COMMENT "Uninstall installed files")
add_custom_command(
TARGET "uninstall"
POST_BUILD
COMMENT "Uninstall files with install_manifest.txt"
COMMAND xargs rm -vf < install_manifest.txt || echo Nothing in
install_manifest.txt to be uninstalled!
)
# Lint
set(PRETTYC_FLAGS
--recursive
--verbose=0
--repository=.
--extensions=c,h,in
--linelength=80
--headers=h,in
--includeorder=standardcfirst
--root=.
#--quiet
${PROJECT_SOURCE_DIR}
)
add_custom_target(lint
COMMAND prettyc
${PRETTYC_FLAGS}
)
# CPack
set(CPACK_PACKAGE_FILE_NAME "libcaio-${PROJECT_VERSION}")
set(CPACK_SET_DESTDIR true)
set(CPACK_PACKAGE_NAME libcaio)
set(CPACK_PACKAGE_CONTACT "Vahid Mardani <[email protected]>")
set(CPACK_GENERATOR DEB)
include(CPack)
# Valgrind, Profiling
set(VALGRIND_FLAGS
-s
--tool=memcheck
--leak-check=yes
--show-reachable=yes
--num-callers=20
--track-fds=yes
)
# Examples
if (NOT DEFINED ENV{SKIP_EXAMPLES})
add_subdirectory(examples)
endif ()