-
Notifications
You must be signed in to change notification settings - Fork 74
/
CMakeLists.txt
260 lines (231 loc) · 8.27 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
cmake_minimum_required(VERSION 3.9)
set(CMAKE_CXX_STANDARD 14)
project(agora-electron-sdk)
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG")
if (MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd /Zi /arch:SSE2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT /Zi /arch:SSE2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MT /Zi /arch:SSE2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /Zi /arch:SSE2")
endif ()
else ()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g")
endif ()
if (APPLE AND NOT IOS)
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET "10.10")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10)
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym")
elseif (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIC")
endif ()
include_directories(${CMAKE_JS_INC})
set(BUILD_TYPE ${CMAKE_BUILD_TYPE})
message(====agora_electron_sdk==== build config: build_type=${BUILD_TYPE}, CMAKE_JS_INC==${CMAKE_JS_INC} arch: ${CMAKE_OSX_ARCHITECTURES}, platform: ${CMAKE_SYSTEM_NAME})
# library name
set(AGORA_NODE_EXT_NAME agora_node_ext)
set(OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build)
message(=====Node js include ===== ${CMAKE_JS_SRC} == lib === ${CMAKE_JS_LIB})
# source code path
set(SOURCE_CODE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/source_code
)
# common file
set(COMMON_FILE_DIR
${SOURCE_CODE_PATH}/common
)
file(GLOB COMMON_FILE
${COMMON_FILE_DIR}/*.cpp
)
# different target file
set(TARGET_AGORA_NODE_EXT_FILE_DIR
${SOURCE_CODE_PATH}/agora_node_ext
)
file(GLOB TARGET_AGORA_NODE_EXT_FILE
${TARGET_AGORA_NODE_EXT_FILE_DIR}/*
)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(AGORA_IRIS_PROJECT_ARCH "MAC")
set(AGORA_RTC_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/native/Agora_Native_SDK_for_Mac_FULL/libs
)
# native rtc sdk library
set(AGORA_RTC_SDK_LIBRARY
${AGORA_RTC_SDK_PATH}/*.xcframework/macos-arm64_x86_64/*.framework
)
# iris sdk path
set(AGORA_IRIS_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/iris/MAC/Release
)
# iris sdk library
set(AGORA_IRIS_SDK_LIBRARY
${AGORA_IRIS_SDK_PATH}/*.framework
)
# iris sdk include file
set(AGORA_IRIS_SDK_HEADER_FILE_DIR
${AGORA_IRIS_SDK_PATH}/AgoraRtcWrapper.framework/Headers
)
set(AGORA_IRIS_FRAMEWORKS
"-framework AgoraRtcWrapper"
)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if (${CMAKE_OSX_ARCHITECTURES} STREQUAL "i386")
set(AGORA_RTC_PROJECT_ARCH "x86")
set(AGORA_IRIS_PROJECT_ARCH "Win32")
set(AGORA_DCG_SDK_ARCH_FILE_NAME "Win32/Release")
elseif (${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64")
set(AGORA_RTC_PROJECT_ARCH "x86_64")
set(AGORA_IRIS_PROJECT_ARCH "x64")
set(AGORA_DCG_SDK_ARCH_FILE_NAME "x64/Release")
endif ()
# native rtc sdk path
set(AGORA_RTC_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/native)
file(GLOB AGORA_RTC_SDK_LIBRARY
${AGORA_RTC_SDK_PATH}/Agora_Native_SDK_for_Windows_FULL/sdk/${AGORA_RTC_PROJECT_ARCH}/*.dll
)
# iris sdk path
set(AGORA_IRIS_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/iris
)
file(GLOB AGORA_IRIS_SDK_LIB
${AGORA_IRIS_SDK_PATH}/${AGORA_DCG_SDK_ARCH_FILE_NAME}/*.lib
)
file(GLOB AGORA_IRIS_SDK_LIBRARY
${AGORA_IRIS_SDK_PATH}/${AGORA_IRIS_PROJECT_ARCH}/Release/*.dll
)
# iris sdk include file
set(AGORA_IRIS_SDK_HEADER_FILE_DIR
${AGORA_IRIS_SDK_PATH}/${AGORA_IRIS_PROJECT_ARCH}/include
)
set(AGORA_IRIS_SDK_LIB
${AGORA_IRIS_SDK_PATH}/${AGORA_DCG_SDK_ARCH_FILE_NAME}/AgoraRtcWrapper.lib
)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# if(${CMAKE_OSX_ARCHITECTURES} STREQUAL "i386")
# set(AGORA_RTC_PROJECT_ARCH "x86")
# set(AGORA_IRIS_PROJECT_ARCH "Win32")
# elseif(${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64")
# set(AGORA_RTC_PROJECT_ARCH "x86_64")
# set(AGORA_IRIS_PROJECT_ARCH "x64")
# endif()
# native rtc sdk path
set(AGORA_RTC_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/iris/RTC/sdk
)
set(AGORA_RTC_SDK_LIBRARY
${AGORA_RTC_SDK_PATH}/x86_64/*.so
)
# iris sdk path
set(AGORA_IRIS_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/iris
)
set(AGORA_IRIS_SDK_LIBRARY
${AGORA_IRIS_SDK_PATH}/x86_64/*
)
# iris sdk include file
set(AGORA_IRIS_SDK_HEADER_FILE_DIR
${AGORA_IRIS_SDK_PATH}/${AGORA_IRIS_PROJECT_ARCH}/include
)
endif ()
message(=====iris include ===== ${AGORA_IRIS_SDK_HEADER_FILE_DIR})
message(=======iris windows lib= IRIs == ${AGORA_IRIS_SDK_LIB})
file(GLOB COMMON_FILE2
${AGORA_IRIS_SDK_HEADER_FILE_DIR}/*.h
)
function(build_target_agora_node_ext)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
add_library(${AGORA_NODE_EXT_NAME} SHARED
${COMMON_FILE2}
${COMMON_FILE}
${COMMON_RAW_DATA_FILE}
${TARGET_AGORA_NODE_EXT_FILE}
${CMAKE_JS_SRC}
)
set_target_properties(${AGORA_NODE_EXT_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden
LINK_FLAGS "-Wl -F ${AGORA_RTC_SDK_PATH} -F ${AGORA_IRIS_SDK_PATH} -rpath @loader_path"
)
target_link_libraries(${AGORA_NODE_EXT_NAME}
${AGORA_IRIS_FRAMEWORKS}
${CMAKE_JS_LIB}
)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
add_library(${AGORA_NODE_EXT_NAME} SHARED
${COMMON_FILE}
${COMMON_RAW_DATA_FILE}
${TARGET_AGORA_NODE_EXT_FILE}
${CMAKE_JS_SRC}
)
target_link_libraries(${AGORA_NODE_EXT_NAME}
${AGORA_IRIS_SDK_LIB}
${CMAKE_JS_LIB}
)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
set(CMAKE_INSTALL_RPATH "\${ORIGIN}")
message(=======CMAKE_JS_LIB=${CMAKE_JS_LIB} =====origin_path==== ${ORIGIN} === RTC === ${AGORA_RTC_SDK_LIB} == IRIs == ${AGORA_IRIS_SDK_LIB})
add_library(libagora_iris_sdk SHARED IMPORTED)
set_target_properties(
libagora_iris_sdk
PROPERTIES IMPORTED_LOCATION
${AGORA_IRIS_SDK_PATH}/x86_64/libAgoraRtcWrapper.so
)
add_library(${AGORA_NODE_EXT_NAME} SHARED
${COMMON_FILE2}
${COMMON_FILE}
${COMMON_RAW_DATA_FILE}
${TARGET_AGORA_NODE_EXT_FILE}
${CMAKE_JS_SRC}
)
target_link_libraries(${AGORA_NODE_EXT_NAME}
PRIVATE
libagora_iris_sdk
)
endif ()
target_include_directories(${AGORA_NODE_EXT_NAME} PUBLIC
${NODE_ADDON_API_DIR}
${COMMON_FILE_DIR}
${COMMON_PROCESS_FILE_DIR}
${TARGET_AGORA_NODE_EXT_FILE_DIR}
${AGORA_RTC_SDK_HEADER_FILE_DIR}
${AGORA_IRIS_SDK_HEADER_FILE_DIR}
)
set_target_properties(${AGORA_NODE_EXT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}"
LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}"
RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}"
PDB_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}"
PREFIX ""
SUFFIX ".node"
)
endfunction(build_target_agora_node_ext)
function(copy_library)
if (WIN32)
add_custom_command(
TARGET ${AGORA_NODE_EXT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${AGORA_RTC_SDK_LIBRARY}
"$<TARGET_FILE_DIR:${AGORA_NODE_EXT_NAME}>/"
COMMAND ${CMAKE_COMMAND} -E copy
${AGORA_IRIS_SDK_LIBRARY}
"$<TARGET_FILE_DIR:${AGORA_NODE_EXT_NAME}>/"
)
else ()
add_custom_command(
TARGET ${AGORA_NODE_EXT_NAME}
POST_BUILD
COMMAND cp -RP
"${AGORA_RTC_SDK_LIBRARY}"
"$<TARGET_FILE_DIR:${AGORA_NODE_EXT_NAME}>/"
COMMAND cp -RP
"${AGORA_IRIS_SDK_LIBRARY}"
"$<TARGET_FILE_DIR:${AGORA_NODE_EXT_NAME}>/"
)
endif ()
endfunction(copy_library)
build_target_agora_node_ext()
copy_library()