forked from baresip/baresip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
393 lines (320 loc) · 8.55 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#
# CMakeLists.txt
#
# Copyright (C) 2010 - 2022 Alfred E. Heggestad
# Copyright (C) 2022 Sebastian Reimers
# Copyright (C) 2023 Christian Spielberger
#
##############################################################################
#
# Versioning
#
cmake_minimum_required(VERSION 3.14)
project(baresip VERSION 3.15.0)
set(PROJECT_SOVERSION 17) # bump if ABI breaks
# Pre-release identifier, comment out on a release
# Increment for breaking changes (dev2, dev3...)
#set(PROJECT_VERSION_PRE dev)
if(PROJECT_VERSION_PRE)
set(PROJECT_VERSION_FULL ${PROJECT_VERSION}-${PROJECT_VERSION_PRE})
else()
set(PROJECT_VERSION_FULL ${PROJECT_VERSION})
endif()
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)
list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES
"${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" IS_SYSTEM_DIR)
if(IS_SYSTEM_DIR STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
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_FULL}"
VER_MAJOR=${PROJECT_VERSION_MAJOR}
VER_MINOR=${PROJECT_VERSION_MINOR}
VER_PATCH=${PROJECT_VERSION_PATCH}
)
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}/baresip/modules")
endif()
if(SHARE_PATH)
add_definitions(-DSHARE_PATH="${SHARE_PATH}")
else()
add_definitions(-DSHARE_PATH="${CMAKE_INSTALL_FULL_DATADIR}/baresip")
endif()
if(DEFAULT_CAFILE)
add_definitions(-DDEFAULT_CAFILE="${DEFAULT_CAFILE}")
endif()
if(DEFAULT_CAPATH)
add_definitions(-DDEFAULT_CAPATH="${DEFAULT_CAPATH}")
endif()
if(DEFAULT_AUDIO_DEVICE)
add_definitions(-DDEFAULT_AUDIO_DEVICE="${DEFAULT_AUDIO_DEVICE}")
endif()
if(STATIC)
add_definitions(-DSTATIC)
endif()
##############################################################################
#
# Source section
#
set(SRCS
src/account.c
src/aucodec.c
src/audio.c
src/aufilt.c
src/auplay.c
src/aureceiver.c
src/ausrc.c
src/baresip.c
src/bundle.c
src/call.c
src/cmd.c
src/conf.c
src/config.c
src/contact.c
src/custom_hdrs.c
src/descr.c
src/dial_number.c
src/bevent.c
src/jbuf.c
src/http.c
src/log.c
src/mediadev.c
src/mediatrack.c
src/menc.c
src/message.c
src/metric.c
src/mnat.c
src/module.c
src/net.c
src/peerconn.c
src/play.c
src/reg.c
src/rtprecv.c
src/rtpstat.c
src/sdp.c
src/sipreq.c
src/stream.c
src/stunuri.c
src/timestamp.c
src/ua.c
src/uag.c
src/ui.c
src/vidcodec.c
src/video.c
src/vidfilt.c
src/vidisp.c
src/vidsrc.c
src/vidutil.c
)
set(HEADERS
include/baresip.h
)
##############################################################################
#
# Modules
#
include(modules)
set(MODULES_DETECTED "")
foreach(mod IN LISTS MODULES)
add_subdirectory(modules/${mod})
endforeach()
foreach(mod IN LISTS APP_MODULES)
add_subdirectory(
${APP_MODULES_DIR}/${mod}
${CMAKE_CURRENT_BINARY_DIR}/app_modules/${mod}
)
list(APPEND MODULES_DETECTED ${mod})
endforeach()
list(REMOVE_DUPLICATES MODULES_DETECTED)
foreach(mod IN LISTS MODULES_DETECTED)
set_target_properties(${mod} PROPERTIES PREFIX "")
endforeach()
message("MODULES_DETECTED=${MODULES_DETECTED}")
if(STATIC)
foreach(mod IN LISTS MODULES_DETECTED)
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_DETECTED)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(${mod} PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup")
endif()
endforeach()
endif()
##############################################################################
#
# Main target library
#
set(LINKLIBS ${RE_LIBRARIES} ${RE_LIBS})
if(WIN32)
list(APPEND LINKLIBS winmm gdi32 crypt32 strmiids ole32 oleaut32)
endif()
if(STATIC)
add_library(baresip STATIC ${SRCS} ${HEADERS})
target_link_libraries(baresip PUBLIC ${LINKLIBS} ${MODULES_DETECTED})
target_include_directories(baresip PUBLIC include)
else()
add_library(baresip SHARED ${SRCS} ${HEADERS})
target_link_libraries(baresip PRIVATE ${LINKLIBS})
set_target_properties(baresip PROPERTIES VERSION
${PROJECT_SOVERSION}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
set_target_properties(baresip PROPERTIES SOVERSION ${PROJECT_SOVERSION})
endif()
if(MSVC)
set_target_properties(baresip PROPERTIES OUTPUT_NAME "libbaresip")
endif()
set_target_properties(baresip PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(baresip PROPERTIES PUBLIC_HEADER "${HEADERS}")
##############################################################################
#
# Target baresip executable
#
add_executable(baresip_exe src/main.c)
set_target_properties(baresip_exe PROPERTIES OUTPUT_NAME baresip)
target_link_libraries(baresip_exe PRIVATE baresip ${LINKLIBS})
##############################################################################
#
# Packaging section
#
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_subdirectory(packaging)
endif()
configure_file(packaging/libbaresip.pc.in libbaresip.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbaresip.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT Development
)
##############################################################################
# Test and webrtc
#
add_subdirectory(webrtc)
add_subdirectory(test)
##############################################################################
# Symlink modules to build dir (needed for test and baresip_exe)
#
if(NOT STATIC AND UNIX)
foreach(mod IN LISTS MODULES_DETECTED)
set(mod_lib ${mod}${CMAKE_SHARED_MODULE_SUFFIX})
add_custom_command(
TARGET baresip_exe POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_CURRENT_BINARY_DIR}/modules/${mod}/${mod_lib}
${CMAKE_CURRENT_BINARY_DIR}/${mod_lib}
)
endforeach()
foreach(mod IN LISTS APP_MODULES)
set(mod_lib ${mod}${CMAKE_SHARED_MODULE_SUFFIX})
add_custom_command(
TARGET baresip_exe POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_CURRENT_BINARY_DIR}/app_modules/${mod}/${mod_lib}
${CMAKE_CURRENT_BINARY_DIR}/${mod_lib}
)
endforeach()
endif()
##############################################################################
#
# Install section
#
install(TARGETS baresip_exe baresip
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Applications
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
NAMELINK_SKIP
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT Development
)
if(NOT STATIC)
foreach(mod IN LISTS MODULES_DETECTED)
install(TARGETS ${mod}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}/baresip/modules
COMPONENT Applications
)
endforeach()
endif()
install(TARGETS baresip
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT Development
)
file(GLOB SHARE_FILES "${PROJECT_SOURCE_DIR}/share/*")
install(FILES ${SHARE_FILES}
DESTINATION ${CMAKE_INSTALL_DATADIR}/baresip
COMPONENT Applications
)