-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
280 lines (236 loc) · 7.14 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
cmake_minimum_required(VERSION 2.8)
set(libname libsrtp)
project(${libname})
option(DEBUG "Enable debugging" OFF)
option(ERROR_TO_FILE "Report errors to file instead of stderr" OFF)
option(ENABLE_GENERIC_AESICM "Enable generic AES ICM" OFF)
option(BUILD_FOR_RISK "Build for RISK cpu type" OFF)
option(SYSLOG_LOGGING "Enable syslog logging" OFF)
option(LIBSRTP_WITH_OPENSSL "Enable building with openssl" ON)
option(LIBSRTP_BUILD_SHARED_LIB "Enable building of shared library instead of the static" OFF)
option(LIBSRTP_INSTALL_TARGET "Should generate install instructions" ON)
# -- start of checks
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckTypeSize)
include(TestBigEndian)
TEST_BIG_ENDIAN(BIG_ENDIAN)
if (${ENABLE_GENERIC_AESICM})
set(GENERIC_AESICM 1)
endif()
if (${DEBUG})
set(ENABLE_DEBUGGING 1)
endif()
# TODO: determine if this is a X86 architecture
set(IS_X86 ON)
if (${IS_X86})
set(HAVE_X86 1)
endif()
# errors to log file
if (${ERROR_TO_FILE})
set(ERR_REPORTING_FILE "libsrtp_error.log")
set(USE_ERR_REPORTING_FILE 1)
else()
set(ERR_REPORTING_STDOUT 1)
endif()
if (${BUILD_FOR_RISK})
set(CPU_RISC 1)
else()
set(CPU_CISC 1)
endif()
if (${BIG_ENDIAN} EQUAL 0)
set(WORDS_BIGENDIAN 0)
else()
set(WORDS_BIGENDIAN 1)
endif()
if(EXISTS /dev/urandom)
set(DEV_URANDOM "/dev/urandom")
endif()
check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
check_include_files(byteswap.h HAVE_BYTESWAP_H)
check_function_exists(inet_aton HAVE_INET_ATON)
check_type_size(int16_t HAVE_INT16_T)
check_type_size(int32_t HAVE_INT32_T)
check_type_size(int8_t HAVE_INT8_T)
check_include_files(inttypes.h HAVE_INTTYPES_H)
check_library_exists(socket socket "" HAVE_LIBSOCKET)
check_include_files(machine/types.h HAVE_MACHINE_TYPES_H)
check_include_files(memory.h HAVE_MEMORY_H)
check_include_files(netinet/in.h HAVE_NETINET_IN_H)
check_function_exists(socket HAVE_SOCKET)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(stdlib.h HAVE_STDLIB_H)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(string.h HAVE_STRING_H)
check_include_files(syslog.h HAVE_SYSLOG_H)
check_include_files(sys/int_types.h HAVE_SYS_INT_TYPES_H)
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
check_include_files(sys/uio.h HAVE_SYS_UIO_H)
check_type_size(uint16_t HAVE_UINT16_T)
check_type_size(uint32_t HAVE_UINT32_T)
check_type_size(uint64_t HAVE_UINT64_T)
check_type_size(uint8_t HAVE_UINT8_T)
check_include_files(unistd.h HAVE_UNISTD_H)
check_function_exists(usleep HAVE_USLEEP)
check_include_files(windows.h HAVE_WINDOWS_H)
check_include_files(winsock2.h HAVE_WINSOCK2_H)
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
check_type_size(size_t SIZE_T_EXISTS)
if("${SIZE_T_EXISTS}" STREQUAL "")
message(STATUS "SIZE_T missing")
set(size_t 1)
set(size_t_type "unsigned")
endif()
# TODO: determine this with cmake
#set(NON_CONST_ANSI_CONFORM TRUE)
if(${NON_CONST_ANSI_CONFORM})
set(const 1)
set(CONST_WHAT "")
endif()
# check if openssl exists
if(${LIBSRTP_WITH_OPENSSL})
find_package(OpenSSL)
if(NOT ${OPENSSL_FOUND})
message(STATUS "OpenSSL was not found.. will continue WITHOUT_OPENSSL")
endif()
endif()
if(MSVC)
set(inline 1)
set(INLINE_KEYWORD "_inline")
endif()
if(NOT "${HAVE_SYSLOG_H}" STREQUAL "")
if (${SYSLOG_LOGGING})
set(USE_SYSLOG 1)
endif()
message(STATUS "Has syslog!")
endif()
file(STRINGS "VERSION" VERSION)
set(PACKAGE_NAME "libsrtp")
set(PACKAGE_VERSION "${VERSION}")
set(PACKAGE_STRING "${PACKAGE_NAME}_${VERSION}")
configure_file(config.h.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/include/srtp/config.h")
# ---- End of checks
if (LIBSRTP_BUILD_SHARED_LIB)
set(libtype SHARED)
if(WIN32)
set(pclibs "-lsrtp.dll")
endif()
# list(APPEND definitions "EXPORT_DLL")
else()
set(libtype STATIC)
set(pclibs "-lsrtp")
endif()
#set(libtype SHARED)
set(src
"srtp/srtp.c"
"srtp/ekt.c"
"crypto/kernel/alloc.c"
"crypto/hash/auth.c"
"crypto/kernel/err.c"
"crypto/math/datatypes.c"
"crypto/kernel/crypto_kernel.c"
"crypto/cipher/cipher.c"
"crypto/kernel/key.c"
"crypto/replay/rdbx.c"
"crypto/replay/rdb.c"
"crypto/math/stat.c"
"crypto/rng/ctr_prng.c"
"crypto/cipher/aes_cbc.c"
"crypto/cipher/null_cipher.c"
"crypto/hash/null_auth.c"
"crypto/cipher/aes.c"
)
set(config_header
"${CMAKE_CURRENT_BINARY_DIR}/include/srtp/config.h")
set(hdrs
"include/srtp/crypto/alloc.h"
"include/srtp/ekt.h"
"include/srtp/getopt_s.h"
"include/srtp/inttypes.h"
"include/srtp/rtp_priv.h"
"include/srtp/srtp_priv.h"
"include/srtp/stdint.h"
"include/srtp/crypto/crypto_kernel.h"
"include/srtp/crypto/auth.h"
"include/srtp/crypto/err.h"
"include/srtp/crypto/datatypes.h"
"include/srtp/crypto/aes.h"
"include/srtp/crypto/integers.h"
"include/srtp/crypto/aes_cbc.h"
"include/srtp/crypto/aes_icm.h"
"${config_header}"
)
if(OPENSSL_FOUND)
list(APPEND src "crypto/cipher/aes_gcm_ossl.c")
list(APPEND src "crypto/cipher/aes_icm_ossl.c")
list(APPEND src "crypto/hash/hmac_ossl.c")
list(APPEND src "crypto/rng/rand_source_ossl.c")
list(APPEND hdrs "include/srtp/crypto/aes_gcm_ossl.h")
list(APPEND hdrs "include/srtp/crypto/aes_icm_ossl.h")
list(APPEND include_dirs ${OPENSSL_INCLUDE_DIR})
list(APPEND otherlibs ${OPENSSL_LIBRARIES})
list(APPEND definitions "OPENSSL")
# TODO: Add openssl to pkgconfig output
#set(pclibs "{pclibs} ${OPENSSL_LIBRARIES}")
else()
# without openssl
list(APPEND src "crypto/cipher/aes_icm.c")
list(APPEND src "crypto/hash/sha1.c")
list(APPEND src "crypto/hash/hmac.c")
# determine os random source
if(LINUX)
list(APPEND src "crypto/rng/rand_linux_kernel.c")
else()
list(APPEND src "crypto/rng/rand_source.c")
endif()
endif()
list(APPEND hdrs
"include/srtp/srtp.h")
list(APPEND include_dirs "${CMAKE_CURRENT_BINARY_DIR}/include")
list(APPEND include_dirs "${CMAKE_CURRENT_SOURCE_DIR}/include")
if(WIN32)
list(APPEND platformlibs "wsock32.lib" "ws2_32.lib")
if (NOT LIBSRTP_BUILD_SHARED_LIB)
set(pclibs "${pclibs} -lwsock32")
endif()
endif()
list(APPEND libraries "${platformlibs}" "${otherlibs}")
list(APPEND definitions "SOME_DEFINES")
add_library(${libname} ${libtype} ${src} ${hdrs})
if(MSVC)
set_target_properties(${libname} PROPERTIES
COMPILE_FLAGS "/wd4018 /wd4244")
else()
configure_file(libsrtp.pc.in ${CMAKE_BINARY_DIR}/libsrtp.pc
@ONLY)
if(LIBSRTP_INSTALL_TARGET)
install(FILES "${CMAKE_BINARY_DIR}/libsrtp.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
endif()
endif()
set_target_properties(${libname} PROPERTIES
PUBLIC_HEADER "${config_header}"
INCLUDE_DIRECTORIES "${include_dirs}"
INTERFACE_INCLUDE_DIRECTORIES "${include_dirs}"
COMPILE_DEFINITIONS "${definitions}"
PREFIX ""
IMPORT_PREFIX ""
)
if(LIBSRTP_INSTALL_TARGET)
install(DIRECTORY include/ DESTINATION include
FILES_MATCHING PATTERN "*.h")
endif()
target_link_libraries(${libname} ${libraries})
if(LIBSRTP_INSTALL_TARGET)
install(TARGETS ${libname}
# EXPORT libname
PUBLIC_HEADER DESTINATION include/srtp COMPONENT dev
LIBRARY DESTINATION lib COMPONENT lib
ARCHIVE DESTINATION lib COMPONENT lib
RUNTIME DESTINATION bin COMPONENT lib)
endif()