-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
CMakeLists.txt
108 lines (88 loc) · 3.86 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
cmake_minimum_required(VERSION 3.1)
include(${CMAKE_CURRENT_LIST_DIR}/third_party/coreHTTP/httpFilePaths.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/third_party/coreMQTT/mqttFilePaths.cmake)
if (DEFINED ENV{IDF_PATH})
file(GLOB ESP32_CODES "./src/*.c")
idf_component_register(
SRCS ${ESP32_CODES} ${HTTP_SOURCES} ${MQTT_SOURCES} ${MQTT_SERIALIZER_SOURCES}
INCLUDE_DIRS "./src" ${HTTP_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS}
REQUIRES mbedtls srtp json esp_netif
)
add_definitions("-DCONFIG_USE_LWIP=1" "-DCONFIG_USE_USRSCTP=0" "-DCONFIG_AUDIO_BUFFER_SIZE=8096" "-DCONFIG_DATA_BUFFER_SIZE=102400" "-DHTTP_DO_NOT_USE_CUSTOM_CONFIG" "-DMQTT_DO_NOT_USE_CUSTOM_CONFIG")
return()
endif()
project(peer)
option(ENABLE_TESTS "Enable tests" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ADDRESS_SANITIZER "Build with AddressSanitizer." OFF)
option(MEMORY_SANITIZER "Build with MemorySanitizer." OFF)
option(THREAD_SANITIZER "Build with ThreadSanitizer." OFF)
option(UNDEFINED_BEHAVIOR_SANITIZER "Build with UndefinedBehaviorSanitizer." OFF)
include(ExternalProject)
include_directories(${CMAKE_BINARY_DIR}/dist/include ${CMAKE_BINARY_DIR}/dist/include/cjson)
link_directories(${CMAKE_BINARY_DIR}/dist/lib)
set(DEP_LIBS "srtp2" "usrsctp" "mbedtls" "mbedcrypto" "mbedx509" "cjson")
# Extended debug information (symbols, source code, and macro definitions)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
function(enableSanitizer SANITIZER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fsanitize=${SANITIZER} -fno-omit-frame-pointer -fno-optimize-sibling-calls" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZER}" PARENT_SCOPE)
endfunction()
if(ADDRESS_SANITIZER)
enableSanitizer("address")
endif()
if(MEMORY_SANITIZER)
enableSanitizer("memory")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-track-origins")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-memory-track-origins")
endif()
if(THREAD_SANITIZER)
enableSanitizer("thread")
endif()
if(UNDEFINED_BEHAVIOR_SANITIZER)
enableSanitizer("undefined")
endif()
add_definitions("-Wunused-variable -Werror=sequence-point -Werror=pointer-sign -Werror=return-type -Werror=sizeof-pointer-memaccess -Wincompatible-pointer-types -DHTTP_DO_NOT_USE_CUSTOM_CONFIG -DMQTT_DO_NOT_USE_CUSTOM_CONFIG")
add_subdirectory(src)
add_subdirectory(examples)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()
ExternalProject_Add(cjson
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/cJSON
CMAKE_ARGS
-DCMAKE_C_FLAGS="-fPIC"
-DBUILD_SHARED_LIBS=off
-DENABLE_CJSON_TEST=off
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
ExternalProject_Add(mbedtls
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mbedtls
CMAKE_ARGS
-DCMAKE_C_FLAGS="-fPIC"
-DENABLE_TESTING=off
-DENABLE_PROGRAMS=off
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mbedtls/include/mbedtls/mbedtls_config.h INPUT_CONTENT)
string(REPLACE "//#define MBEDTLS_SSL_DTLS_SRTP" "#define MBEDTLS_SSL_DTLS_SRTP" MODIFIED_CONTENT ${INPUT_CONTENT})
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mbedtls/include/mbedtls/mbedtls_config.h ${MODIFIED_CONTENT})
ExternalProject_Add(srtp2
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libsrtp
CMAKE_ARGS
-DCMAKE_C_FLAGS="-fPIC"
-DTEST_APPS=off
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
ExternalProject_Add(usrsctp
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/usrsctp
CMAKE_ARGS
-DCMAKE_C_FLAGS="-fPIC"
-Dsctp_build_programs=off
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/dist
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)