This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
326 lines (289 loc) · 8.29 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# Low Latency IPC Library for high-speed traffic
# Copyright (C) 2019 Michael Fabian Dirks <info@xaymar.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#================================================================================#
# Define Project
#================================================================================#
cmake_minimum_required(VERSION 3.15.0)
# Automatic Versioning
set(VERSION_MAJOR 0)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)
set(VERSION_TWEAK 0)
set(PROJECT_COMMIT "N/A")
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
set(GIT_RESULT "")
set(GIT_OUTPUT "")
execute_process(
COMMAND git rev-list --count --topo-order ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}..HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
RESULT_VARIABLE GIT_RESULT
OUTPUT_VARIABLE GIT_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)
if(GIT_RESULT EQUAL 0)
set(VERSION_TWEAK ${GIT_OUTPUT})
endif()
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
RESULT_VARIABLE GIT_RESULT
OUTPUT_VARIABLE GIT_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)
if(GIT_RESULT EQUAL 0)
set(PROJECT_COMMIT ${GIT_OUTPUT})
endif()
endif()
# Define Project
project(
datapath
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_TWEAK}
)
set(PROJECT_FULL_NAME "DataPath IPC Library")
set(PROJECT_DESCRIPTION "High Performance Synchronous and Asynchronous IPC Library")
set(PROJECT_AUTHORS "Michael Fabian 'Xaymar' Dirks <info@xaymar.com>")
set(PROJECT_COPYRIGHT_YEARS "2018 - 2020")
#================================================================================#
# CMake Tools & Modules
#================================================================================#
# CMake Modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/clang")
include("util")
include("Clang")
# Detect Build Type
if(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(PropertyPrefix "${PROJECT_NAME}_")
else()
set(PropertyPrefix "")
endif()
# Detect Architecture
math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}")
if("${BITS}" STREQUAL "32")
set(ARCH "x86")
else()
set(ARCH "x64")
endif()
#================================================================================#
# Options
#================================================================================#
# Static or Dynamic?
option(${PropertyPrefix}MAKE_DYNAMIC "Create dynamically linked library instead of static library." OFF)
option(${PropertyPrefix}MAKE_MODULE "Create dynamically linked module instead of dynamically linked library." OFF)
option(${PropertyPrefix}BUILD_SAMPLES "Build Samples" ON)
#================================================================================#
# Sources
#================================================================================#
# Configure Version Header
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/version.hpp.in"
"${PROJECT_BINARY_DIR}/generated/version.hpp"
)
# Source Files
set(PROJECT_PUBLIC "")
list(APPEND PROJECT_PUBLIC
"include/datapath.hpp"
"include/error.hpp"
"include/bitmask.hpp"
"include/event.hpp"
"include/isocket.hpp"
"include/iserver.hpp"
"include/itask.hpp"
"include/waitable.hpp"
"include/permissions.hpp"
"include/threadpool.hpp"
)
set(PROJECT_PRIVATE "")
list(APPEND PROJECT_PRIVATE
"source/threadpool.cpp"
)
set(PROJECT_TEMPLATES "")
list(APPEND PROJECT_TEMPLATES
"${PROJECT_SOURCE_DIR}/cmake/version.hpp.in"
)
set(PROJECT_GENERATED "")
list(APPEND PROJECT_GENERATED
"${PROJECT_BINARY_DIR}/generated/version.hpp"
)
set(PROJECT_DATA "")
list(APPEND PROJECT_DATA
"README.md"
"LICENSE"
)
set(PROJECT_LIBRARIES "")
set(PROJECT_DEFINES "")
# Platforms
if(WIN32)
# Windows
list(APPEND PROJECT_LIBRARIES
advapi32
)
list(APPEND PROJECT_DEFINES
_CRT_SECURE_NO_WARNINGS
WIN32_LEAN_AND_MEAN
NOGPICAPMASKS
NOVIRTUALKEYCODES
NOWINMESSAGES
NOWINSTYLES
NOSYSMETRICS
NOMENUS
NOICONS
NOKEYSTATES
NOSYSCOMMANDS
NORASTEROPS
NOSHOWWINDOW
NOATOM
NOCLIPBOARD
NOCOLOR
NOCTLMGR
NODRAWTEXT
NOGDI
NOKERNEL
#NOUSER
#NONLS
NOMB
NOMEMMGR
NOMETAFILE
NOMINMAX
NOMSG
NOOPENFILE
NOSCROLL
NOSERVICE
NOSOUND
NOTEXTMETRIC
NOWH
NOWINOFFSETS
NOCOMM
NOKANJI
NOHELP
NOPROFILER
NODEFERWINDOWPOS
NOMCX
NOIME
NOMDI
NOINOUT
)
list(APPEND PROJECT_PRIVATE
"source/windows/datapath.cpp"
"source/windows/overlapped.hpp"
"source/windows/overlapped.cpp"
"source/windows/socket.hpp"
"source/windows/socket.cpp"
"source/windows/server.hpp"
"source/windows/server.cpp"
"source/windows/task.hpp"
"source/windows/task.cpp"
"source/windows/utility.hpp"
"source/windows/waitable.cpp"
)
elseif(APPLE)
# MacOSX
list(APPEND PROJECT_PRIVATE
)
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
# Linux
list(APPEND PROJECT_PRIVATE
)
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
# FreeBSD
list(APPEND PROJECT_PRIVATE
)
endif()
# Grouping
source_group(TREE "${PROJECT_SOURCE_DIR}" PREFIX "Data Files" FILES ${PROJECT_DATA})
source_group(TREE "${PROJECT_SOURCE_DIR}/cmake" PREFIX "Template Files" FILES ${PROJECT_TEMPLATES})
source_group(TREE "${PROJECT_BINARY_DIR}/generated" PREFIX "Generated Files" FILES ${PROJECT_GENERATED})
source_group(TREE "${PROJECT_SOURCE_DIR}/include" PREFIX "Exported Files" FILES ${PROJECT_PUBLIC})
# Filter Sources
set(_TMP_SOURCE ${PROJECT_PRIVATE})
list(FILTER _TMP_SOURCE INCLUDE REGEX "\.(c|cpp)$")
source_group(TREE "${PROJECT_SOURCE_DIR}/source" PREFIX "Source Files" FILES ${_TMP_SOURCE})
# Filter Headers
set(_TMP_HEADER ${PROJECT_PRIVATE})
list(FILTER _TMP_HEADER INCLUDE REGEX "\.(h|hpp)$")
source_group(TREE "${PROJECT_SOURCE_DIR}/source" PREFIX "Header Files" FILES ${_TMP_HEADER})
#================================================================================#
# Building
#================================================================================#
# Library definition
set(_BUILD_TYPE)
if(${PropertyPrefix}MAKE_DYNAMIC)
if(${PropertyPrefix}MAKE_MODULE)
set(_BUILD_TYPE MODULE)
else()
set(_BUILD_TYPE SHARED)
endif()
else()
set(_BUILD_TYPE STATIC)
endif()
add_library(${PROJECT_NAME} ${_BUILD_TYPE}
${PROJECT_PUBLIC}
${PROJECT_PRIVATE}
${PROJECT_GENERATED}
${PROJECT_TEMPLATES}
${PROJECT_DATA}
)
# Clang
if("${PropertyPrefix}" STREQUAL "")
clang_format(
TARGETS ${PROJECT_NAME}
DEPENDENCY
VERSION 9.0.0
)
endif()
# Includes
target_include_directories(${PROJECT_NAME}
INTERFACE
"${PROJECT_SOURCE_DIR}/include"
PUBLIC
"${PROJECT_SOURCE_DIR}/include"
PRIVATE
"${PROJECT_SOURCE_DIR}/source"
)
# Defines
target_compile_definitions(${PROJECT_NAME}
PRIVATE ${PROJECT_DEFINES}
)
# Linking Directories
link_directories(
)
# Linking
target_link_libraries(${PROJECT_NAME}
${PROJECT_LIBRARIES}
)
# File Version
if(WIN32)
set_target_properties(
${PROJECT_NAME}
PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}
)
else()
set_target_properties(
${PROJECT_NAME}
PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}
)
endif()
#================================================================================#
# Samples
#================================================================================#
if(${PropertyPrefix}BUILD_SAMPLES)
add_subdirectory(${PROJECT_SOURCE_DIR}/samples)
endif()