-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
230 lines (188 loc) · 4.24 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
#
# CMakeLists.txt
#
# Copyright (C) 2023 Sebastian Reimers
#
##############################################################################
#
# Project and Versioning
#
cmake_minimum_required(VERSION 3.18)
project(restund VERSION 3.5.1 LANGUAGES C)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
##############################################################################
#
# Module/Package Includes
#
include(GNUInstallDirs)
include(CheckIncludeFile)
find_package(RE REQUIRED)
##############################################################################
#
# Compile options
#
if(WIN32)
option(STATIC "Build static" ON)
else()
option(STATIC "Build static" OFF)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)
if(MSVC)
add_compile_options("/W3")
else()
add_compile_options(
-Wall
-Wextra
)
set(c_flags
-pedantic
-Wcast-align
-Wbad-function-cast
-Wmissing-declarations
-Wmissing-prototypes
-Wnested-externs
-Wno-strict-aliasing
-Wold-style-definition
-Wshadow -Waggregate-return
-Wstrict-prototypes
-Wuninitialized
-Wvla
)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
list(APPEND c_flags
-Watomic-implicit-seq-cst
-Wshorten-64-to-32
-Wno-gnu-zero-variadic-macro-arguments
)
endif()
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:${c_flags}>"
)
endif()
find_package(re CONFIG REQUIRED HINTS ../re/cmake)
list(APPEND RE_DEFINITIONS
VERSION="${PROJECT_VERSION}"
)
add_compile_definitions(${RE_DEFINITIONS})
include_directories(
include
src
${RE_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
)
if(MOD_PATH)
add_definitions(-DMOD_PATH="${MOD_PATH}")
elseif(CMAKE_INSTALL_FULL_LIBDIR)
add_definitions(-DMOD_PATH="${CMAKE_INSTALL_FULL_LIBDIR}/restund/modules")
endif()
if(STATIC)
add_definitions(-DSTATIC)
endif()
##############################################################################
#
# Source section
#
set(SRCS
src/cmd.c
src/db.c
src/dtls.c
src/log.c
src/main.c
src/stun.c
src/tcp.c
src/udp.c
)
##############################################################################
#
# Modules
#
find_package(MySQL)
if(NOT DEFINED MODULES)
set(MODULES
auth
binding
drain
filedb
restauth
stat
status
syslog
turn
zrest
)
if(MySQL_FOUND)
list(APPEND MODULES mysql_ser)
endif()
endif()
foreach(mod IN LISTS MODULES)
add_subdirectory(modules/${mod})
set_target_properties(${mod} PROPERTIES PREFIX "")
endforeach()
if(STATIC)
foreach(mod IN LISTS MODULES)
set(MOD_EXPORTS
"${MOD_EXPORTS}extern const struct mod_export exports_${mod};\n")
set(MOD_EXPORT_TABLE
"${MOD_EXPORT_TABLE} &exports_${mod},\n")
endforeach()
configure_file(src/static.c.in src/static.c)
list(APPEND SRCS ${CMAKE_CURRENT_BINARY_DIR}/src/static.c)
else()
foreach(mod IN LISTS MODULES)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(${mod} PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup")
endif()
endforeach()
endif()
##############################################################################
#
# Target executable
#
set(LINKLIBS ${RE_LIBRARIES} Threads::Threads)
if(ZLIB_FOUND)
list(APPEND LINKLIBS ZLIB::ZLIB)
endif()
if(USE_OPENSSL)
list(APPEND LINKLIBS OpenSSL::SSL OpenSSL::Crypto)
endif()
if(WIN32)
list(APPEND LINKLIBS ws2_32 iphlpapi winmm gdi32 crypt32 strmiids
ole32 oleaut32 qwave dbghelp)
else()
list(APPEND LINKLIBS -lm ${RESOLV_LIBRARY})
endif()
add_executable(restund ${SRCS})
if(STATIC)
target_link_libraries(restund PUBLIC ${LINKLIBS} ${MODULES})
else()
target_link_libraries(restund PUBLIC ${LINKLIBS})
endif()
##############################################################################
#
# Install section
#
install(TARGETS restund
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Applications
)
if(NOT STATIC)
foreach(mod IN LISTS MODULES)
install(TARGETS ${mod}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}/restund/modules
COMPONENT Applications
)
endforeach()
endif()
set(ETC_FILES
etc/restund.conf
etc/restund.auth
)
install(FILES ${ETC_FILES}
DESTINATION etc
COMPONENT Applications
)