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