Imported Upstream version 2.3.0
[platform/upstream/libsrtp.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2
3 project(libsrtp2 LANGUAGES C)
4
5 set(PACKAGE_VERSION 2.3.0)
6 set(PACKAGE_STRING "${CMAKE_PROJECT_NAME} ${PACKAGE_VERSION}")
7
8 include(TestBigEndian)
9 include(CheckIncludeFile)
10 include(CheckFunctionExists)
11 include(CheckTypeSize)
12 include(CheckCSourceCompiles)
13
14 test_big_endian(WORDS_BIGENDIAN)
15
16 if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
17   set (HAVE_X86 TRUE)
18 else ()
19   set (HAVE_X86 FALSE)
20 endif ()
21
22 check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
23 check_include_file(byteswap.h HAVE_BYTESWAP_H)
24 check_include_file(inttypes.h HAVE_INTTYPES_H)
25 check_include_file(machine/types.h HAVE_MACHINE_TYPES_H)
26 check_include_file(netinet/in.h HAVE_NETINET_IN_H)
27 check_include_file(stdint.h HAVE_STDINT_H)
28 check_include_file(stdlib.h HAVE_STDLIB_H)
29 check_include_file(sys/int_types.h HAVE_SYS_INT_TYPES_H)
30 check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
31 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
32 check_include_file(unistd.h HAVE_UNISTD_H)
33 check_include_file(windows.h HAVE_WINDOWS_H)
34 check_include_file(winsock2.h HAVE_WINSOCK2_H)
35
36 check_function_exists(sigaction HAVE_SIGACTION)
37 check_function_exists(inet_aton HAVE_INET_ATON)
38 check_function_exists(usleep HAVE_USLEEP)
39
40 check_type_size(uint8_t UINT8_T)
41 check_type_size(uint16_t UINT16_T)
42 check_type_size(uint32_t UINT32_T)
43 check_type_size(uint64_t UINT64_T)
44 check_type_size(int32_t INT32_T)
45 check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
46 check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
47
48 check_c_source_compiles("inline void func(); void func() { } int main() { func(); return 0; }" HAVE_INLINE)
49 if(NOT HAVE_INLINE)
50   check_c_source_compiles("__inline void func(); void func() { } int main() { func(); return 0; }" HAVE___INLINE)
51 endif()
52
53 set(ENABLE_DEBUG_LOGGING OFF CACHE BOOL "Enable debug logging in all modules")
54 set(ERR_REPORTING_STDOUT OFF CACHE BOOL "Enable logging to stdout")
55 set(ERR_REPORTING_FILE "" CACHE FILEPATH "Use file for logging")
56 set(ENABLE_OPENSSL OFF CACHE BOOL "Enable OpenSSL crypto engine")
57 set(TEST_APPS ON CACHE BOOL "Build test applications")
58 option(BUILD_SHARED_LIBS "Build shared library" OFF)
59
60 if(ENABLE_OPENSSL)
61   find_package(OpenSSL REQUIRED)
62   include_directories(${OPENSSL_INCLUDE_DIR})
63 endif()
64 set(OPENSSL ${ENABLE_OPENSSL} CACHE BOOL INTERNAL)
65 set(GCM ${ENABLE_OPENSSL} CACHE BOOL INTERNAL)
66
67 set(CONFIG_FILE_DIR ${CMAKE_CURRENT_BINARY_DIR})
68 include_directories(${CONFIG_FILE_DIR})
69
70 configure_file(config_in_cmake.h ${CONFIG_FILE_DIR}/config.h)
71 add_definitions(-DHAVE_CONFIG_H)
72
73 set(SOURCES_C
74   srtp/ekt.c
75   srtp/srtp.c
76 )
77
78 set(CIPHERS_SOURCES_C
79   crypto/cipher/cipher.c
80   crypto/cipher/null_cipher.c
81 )
82
83 if(ENABLE_OPENSSL)
84   list(APPEND CIPHERS_SOURCES_C
85     crypto/cipher/aes_icm_ossl.c
86     crypto/cipher/aes_gcm_ossl.c
87   )
88 else()
89   list(APPEND  CIPHERS_SOURCES_C
90     crypto/cipher/aes.c
91     crypto/cipher/aes_icm.c
92   )
93 endif()
94
95 set(HASHES_SOURCES_C
96     crypto/hash/auth.c
97     crypto/hash/null_auth.c
98 )
99
100 if(ENABLE_OPENSSL)
101   list(APPEND HASHES_SOURCES_C
102     crypto/hash/hmac_ossl.c
103   )
104 else()
105   list(APPEND  HASHES_SOURCES_C
106     crypto/hash/hmac.c
107     crypto/hash/sha1.c
108   )
109 endif()
110
111 set(KERNEL_SOURCES_C
112   crypto/kernel/alloc.c
113   crypto/kernel/crypto_kernel.c
114   crypto/kernel/err.c
115   crypto/kernel/key.c
116 )
117
118 set(MATH_SOURCES_C
119   crypto/math/datatypes.c
120   crypto/math/stat.c
121 )
122
123 set(REPLAY_SOURCES_C
124   crypto/replay/rdb.c
125   crypto/replay/rdbx.c
126   crypto/replay/ut_sim.c
127 )
128
129 set(SOURCES_H
130   crypto/include/aes.h
131   crypto/include/aes_icm.h
132   crypto/include/alloc.h
133   crypto/include/auth.h
134   crypto/include/cipher.h
135   crypto/include/cipher_types.h
136   crypto/include/crypto_kernel.h
137   crypto/include/crypto_types.h
138   crypto/include/datatypes.h
139   crypto/include/err.h
140   crypto/include/hmac.h
141   crypto/include/integers.h
142   crypto/include/key.h
143   crypto/include/null_auth.h
144   crypto/include/null_cipher.h
145   crypto/include/rdb.h
146   crypto/include/rdbx.h
147   crypto/include/sha1.h
148   crypto/include/stat.h
149   include/srtp.h
150   include/srtp_priv.h
151   include/ut_sim.h
152   ${CONFIG_FILE_DIR}/config.h
153 )
154
155 if(BUILD_SHARED_LIBS AND WIN32)
156   list(APPEND SOURCES_C
157     srtp.def
158   )
159 endif()
160
161 source_group("src" FILES ${SOURCES_C})
162 source_group("src\\Ciphers" FILES ${CIPHERS_SOURCES_C})
163 source_group("src\\Hashes" FILES ${HASHES_SOURCES_C})
164 source_group("src\\Kernel" FILES ${KERNEL_SOURCES_C})
165 source_group("src\\Math" FILES ${MATH_SOURCES_C})
166 source_group("src\\Replay" FILES ${REPLAY_SOURCES_C})
167 source_group("include" FILES ${SOURCES_H})
168
169 add_library(srtp2
170   ${SOURCES_C}
171   ${CIPHERS_SOURCES_C}
172   ${HASHES_SOURCES_C}
173   ${KERNEL_SOURCES_C}
174   ${MATH_SOURCES_C}
175   ${REPLAY_SOURCES_C}
176   ${SOURCES_H}
177 )
178
179 target_include_directories(srtp2 PUBLIC crypto/include include)
180 if(ENABLE_OPENSSL)
181   target_link_libraries(srtp2 OpenSSL::Crypto)
182 endif()
183 if(WIN32)
184   target_link_libraries(srtp2 ws2_32)
185 endif()
186
187 install(TARGETS srtp2 DESTINATION lib)
188 install(FILES include/srtp.h crypto/include/auth.h
189   crypto/include/cipher.h
190   crypto/include/cipher_types.h
191   DESTINATION include/srtp2)
192
193 if(TEST_APPS)
194   enable_testing()
195
196 if(NOT (BUILD_SHARED_LIBS AND WIN32))
197   add_executable(test_srtp test/test_srtp.c)
198   target_link_libraries(test_srtp srtp2)
199   add_test(test_srtp test_srtp)
200 endif()
201
202   add_executable(srtp_driver test/srtp_driver.c
203     test/util.c test/getopt_s.c)
204   target_link_libraries(srtp_driver srtp2)
205   add_test(srtp_driver srtp_driver -v)
206 endif()