-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
404 lines (326 loc) · 11.4 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
cmake_minimum_required (VERSION 3.0)
# projectname is the same as the main-executable
project(RTCProject)
set(TARGET ${PROJECT_NAME})
set(LIB_NAME "RTCEngine")
option(CMAKE_BUILD_TYPE "Build Type." Release)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
message(WARNING "Build Type: ${CMAKE_BUILD_TYPE}")
option(BUILD_WITH_LIBS "Build With Libs." ON)
message(WARNING "Build With Libs: ${BUILD_WITH_LIBS}")
option(BUILD_WITH_VIEW "Build With View." OFF)
message(WARNING "Build With View: ${BUILD_WITH_VIEW}")
# 生成compile_commands.json,用于在VSCode等编辑器/IDE中给C/C++代码做函数定义跳转支持
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# 设置c++的编译选项
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has C++17 support.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Debug Type.")
add_definitions("-Wall")
add_definitions("-fPIC")
add_definitions("-Wl,-lm")
add_definitions("-Wno-dev")
if(NOT WIN32)
add_definitions("-Wextra")
add_definitions("-Wpedantic")
endif()
endif()
#-------------------------------------------------------------------------------
function(deleteFiles)
foreach(FILE IN LISTS ARGN)
if ("${FILE}" MATCHES ".DS_Store")
message(WARNING "删除文件: ${FILE}")
file(REMOVE ${FILE})
endif()
endforeach()
endfunction()
file(GLOB_RECURSE delete_seerch_all_file "*")
deleteFiles(${delete_seerch_all_file})
# default was /src
set(sourceGroupPrefixName "")
# 按文件层次结构显示
function(sourceGroup prefix)
#message("prefix: ${prefix}")
foreach(FILE IN LISTS ARGN)
get_filename_component(PARENT_DIR "${FILE}" DIRECTORY)
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" GROUP "${PARENT_DIR}")
string(REPLACE "${prefix}" "" GROUP "${GROUP}")
string(REPLACE "/" "\\" GROUP "${GROUP}")
if ("${FILE}" MATCHES ".*\\.cpp" AND ".*\\.cc" AND ".*\\.c")
set(GROUP "Source Files${GROUP}")
elseif("${FILE}" MATCHES ".*\\.h" AND ".*\\.hpp")
set(GROUP "Header Files${GROUP}")
endif()
source_group("${GROUP}" FILES "${FILE}")
endforeach()
endfunction()
#-------------------------------------------------------------------------------
if(WIN32)
message(WARNING "Now is windows")
elseif(APPLE)
message(STATUS "Now is Apple systens.")
# Check whether we are running under Rosetta on arm64 hardware.
execute_process(COMMAND sysctl -q hw.optional.arm64
OUTPUT_VARIABLE _sysctl_stdout
ERROR_VARIABLE _sysctl_stderr
RESULT_VARIABLE _sysctl_result
)
if(_sysctl_result EQUAL 0 AND _sysctl_stdout MATCHES "hw.optional.arm64: 1")
set(CMAKE_HOST_SYSTEM_PROCESSOR "arm64")
endif()
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
add_definitions("-D__x86_64__=1")
set(CMAKE_OSX_ARCHITECTURES "x86_64")
else()
set(CMAKE_OSX_ARCHITECTURES arm64)
endif()
message(STATUS "OSX Architectures: ${CMAKE_OSX_ARCHITECTURES}")
message(WARNING "Host System Processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
add_definitions("-DWEBRTC_MAC=1")
add_definitions("-DWEBRTC_POSIX=1")
list(APPEND DEPS_LIBS "-framework Foundation")
list(APPEND DEPS_LIBS "-framework OpenGL")
list(APPEND DEPS_LIBS "-framework GLUT")
list(APPEND DEPS_LIBS "-framework CoreServices")
list(APPEND DEPS_LIBS "-framework Metal")
list(APPEND DEPS_LIBS "-framework AVFoundation")
list(APPEND DEPS_LIBS "-framework VideoToolbox")
list(APPEND DEPS_LIBS "-framework AudioUnit")
list(APPEND DEPS_LIBS "-framework AudioToolbox")
list(APPEND DEPS_LIBS "-framework CoreAudio")
list(APPEND DEPS_LIBS "-framework ApplicationServices")
elseif(UNIX)
message(WARNING "Now is UNIX-like OS's. Including aPPLE os x and CygWin")
endif()
message(WARNING "Operation System: ${CMAKE_SYSTEM}")
#-------------------------------------------------------------------------------
set(src_dir "${PROJECT_SOURCE_DIR}/src")
set(libs_dir "${PROJECT_SOURCE_DIR}/libs")
include_directories(
"${src_dir}"
"${libs_dir}"
)
# 相当于g++命令的-L选项的作用
link_directories(
"/usr/local"
"${src_dir}"
"${libs_dir}"
)
# 添加依赖
if(EXISTS "${PROJECT_SOURCE_DIR}/deps.cmake")
include("deps.cmake")
endif()
# modules
include("${src_dir}/core/CMakeLists.txt")
include("${src_dir}/log/CMakeLists.txt")
include("${src_dir}/platform/CMakeLists.txt")
include("${src_dir}/util/CMakeLists.txt")
include("${src_dir}/network/CMakeLists.txt")
include("${src_dir}/engine/CMakeLists.txt")
include("${src_dir}/foundation/CMakeLists.txt")
include("${src_dir}/view/CMakeLists.txt")
# libs
include("${libs_dir}/nlohmann/CMakeLists.txt")
include("${libs_dir}/nlohmann_json_reflect/CMakeLists.txt")
include("${libs_dir}/asio/CMakeLists.txt")
include("${libs_dir}/websocketpp/CMakeLists.txt")
include("${libs_dir}/kcp/CMakeLists.txt")
include("${libs_dir}/lua/CMakeLists.txt")
include("${libs_dir}/sigslot/CMakeLists.txt")
include("${libs_dir}/httplib/CMakeLists.txt")
include("${libs_dir}/magic_enum/CMakeLists.txt")
include("${libs_dir}/sdptransform/CMakeLists.txt")
set(MODULES
${core_all_file}
${log_all_file}
${platform_all_file}
${util_all_file}
${network_all_file}
${engine_all_file}
${foundation_all_file}
)
set(DEPENDS_LIBS
${asio_all_file}
${kcp_all_file}
${lua_all_file}
${websocketpp_all_file}
${nlohmann_json_all_file}
${nlohmann_json_reflect_all_file}
${sigslot_all_file}
${httplib_all_file}
${magic_enum_all_file}
${sdptransform_all_file}
)
list(APPEND ALL_SOURCES ${MODULES} ${DEPENDS_LIBS})
#-------------------------------------------------------------------------------
file (GLOB_RECURSE WebRTC ./webrtc/include/**/*.h)
file (GLOB_RECURSE include_third_party ./webrtc/include_third_party/**/*.h)
set(HEADERS
${WebRTC}
${include_third_party}
${Deps_Include}
)
set(SOURCES
${Deps_Source}
)
set(EXECUTE_SOURCES
src/app.h
src/app.cc
src/main.cc
)
source_group(TREE "${CMAKE_SOURCE_DIR}" FILES ${HEADERS} ${SOURCES} ${EXECUTE_SOURCES})
#-------------------------------------------------------------------------------
# 相当于g++选项中的-I参数的作用
include_directories(
"${CMAKE_SOURCE_DIR}/webrtc/include"
"${CMAKE_SOURCE_DIR}/webrtc/include_third_party"
)
set(WebRTCLib "${CMAKE_SOURCE_DIR}/webrtc/lib/libwebrtc.a")
message(STATUS "WebRTC lis was ${CMAKE_BUILD_TYPE}: ${WebRTCLib}")
list(APPEND DEPS_LIBS "${WebRTCLib}")
#-------------------------------------------------------------------------------
set(RESOURCES
webrtc_static_lib.py
builddeps.py
deps.json
deps.cmake
README.md
LICENSE
)
source_group(Resources FILES ${RESOURCES})
#-------------------------------------------------------------------------------
set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR}/Lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR}/Lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}/Bin)
message(STATUS "OUTPUT_DIR: ${OUTPUT_DIR}")
message(STATUS "ARCHIVE_OUTPUT_DIRECTORY: ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
message(STATUS "LIBRARY_OUTPUT_DIRECTORY: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
message(STATUS "RUNTIME_OUTPUT_DIRECTORY: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
if(BUILD_WITH_LIBS)
set(TARGET_LIB "${LIB_NAME}")
add_library(${TARGET_LIB} STATIC ${ALL_SOURCES} ${HEADERS} ${SOURCES})
#add_library(${TARGET_LIB} SHARED ${ALL_SOURCES} ${HEADERS} ${SOURCES})
else()
list(APPEND EXECUTE_SOURCES ${ALL_SOURCES} ${HEADERS} ${SOURCES})
endif()
if(BUILD_WITH_VIEW)
file (GLOB_RECURSE ASSETS "assets/*")
sourceGroup("" ${ASSETS})
qt_add_executable(${TARGET} MANUAL_FINALIZATION
${view_all_file}
${EXECUTE_SOURCES}
${ASSETS}
${RESOURCES}
)
set_target_properties(${TARGET} PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
set_target_properties(${TARGET} PROPERTIES
AUTOMOC TRUE
AUTOUIC TRUE
AUTORCC TRUE
)
if(APPLE AND NOT IOS)
set_target_properties(${TARGET} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/assets/plist/Info.plist.in"
)
elseif(IOS)
set_target_properties(${TARGET} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/assets/plist/Info.plist.in"
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
#MACOSX_BUNDLE_SHORT_VERSION_STRING ${VERSION}
)
endif()
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/assets"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/../Resources/assets"
)
target_link_libraries(${TARGET} PRIVATE
${QtModuleLibs}
${TARGET_LIB}
${DEPS_LIBS}
)
qt_finalize_executable(${TARGET})
else()
add_executable(${TARGET} ${EXECUTE_SOURCES} ${RESOURCES})
target_link_libraries(${TARGET} PRIVATE ${TARGET_LIB} ${DEPS_LIBS})
endif()
#-------------------------------------------------------------------------------
# 单元测试
option(ENABLE_UNIT_TESTS "Enable Unit Tests." ON)
include("${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
#-------------------------------------------------------------------------------
message(STATUS "origin installed directory: ${CMAKE_INSTALL_PREFIX}")
if(${CMAKE_INSTALL_PREFIX} MATCHES "/usr/local")
set(install_directory "${PROJECT_SOURCE_DIR}/install")
file(MAKE_DIRECTORY ${install_directory})
set(CMAKE_INSTALL_PREFIX ${install_directory})
message(STATUS "Create installed directory: ${CMAKE_INSTALL_PREFIX}")
endif()
message(STATUS "Project will be installed to ${CMAKE_INSTALL_PREFIX}")
install(
TARGETS ${TARGET} ${TARGET_LIB}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
BUNDLE DESTINATION bundle
)
set(output_head_files
"${src_dir}/app.h"
"${src_dir}/engine/engine_interface.h"
)
install(FILES ${output_head_files} DESTINATION include)
install(DIRECTORY src/foundation
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ)
set(output_libs_head_files_directory
webrtc/include/
webrtc/include_third_party/
${DEPS_INCLUDE_DIR}
)
install(
DIRECTORY ${output_libs_head_files_directory}
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
)
install(
DIRECTORY ${DEPS_LIB_DIR}
DESTINATION lib
PATTERN "cmake" EXCLUDE
PATTERN "pkgconfig" EXCLUDE
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
)
install(
FILES ${WebRTCLib}
DESTINATION lib
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
)
#-------------------------------------------------------------------------------
add_custom_target(run
COMMAND ./${TARGET}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMENT "Intermediate Run target: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
)