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