-
Notifications
You must be signed in to change notification settings - Fork 51
/
CMakeLists.txt
389 lines (341 loc) · 13.9 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
cmake_minimum_required(VERSION 3.10)
set(EXTERN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/extern)
set(BOREALIS_LIBRARY ${EXTERN_PATH}/borealis/library)
# build options
include(${EXTERN_PATH}/cmake/commonOption.cmake)
# Dependencies
option(USE_SHARED_LIB "Whether to use shared libs provided by system" OFF)
cmake_dependent_option(USE_SYSTEM_FMT "" OFF "NOT USE_SHARED_LIB" ON)
cmake_dependent_option(USE_SYSTEM_TINYXML2 "" OFF "NOT USE_SHARED_LIB" ON)
if (APPLE AND PLATFORM_DESKTOP)
option(BUNDLE_MACOS_APP "Bundle a app for macOS" ON)
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0" CACHE STRING "" FORCE)
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
endif ()
if (PLATFORM_IOS OR PLATFORM_TVOS)
# set(ENABLE_ARC OFF)
endif ()
# toolchain
include(${EXTERN_PATH}/cmake/toolchain.cmake)
# Renderers
if (PLATFORM_IOS OR PLATFORM_TVOS)
# set(USE_METAL_RENDERER ON)
set(USE_GL_RENDERER ON)
else()
set(USE_GL_RENDERER ON)
endif ()
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${EXTERN_PATH}/cmake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${EXTERN_PATH}/cmake")
#find_package(PkgConfig REQUIRED)
# project info
project(Moonlight)
set(VERSION_MAJOR "1")
set(VERSION_MINOR "2")
set(VERSION_ALTER "2")
set(VERSION_BUILD "1")
set(PACKAGE_NAME "ru.xitrix.Moonlight")
set(PSN_TITLE_ID "MNTL00000")
set(PSN_VERSION "01.00")
set(PROJECT_AUTHOR "XITRIX")
set(PROJECT_ICON ${CMAKE_CURRENT_SOURCE_DIR}/resources/img/moonlight_icon.jpg)
set(PROJECT_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources)
add_definitions(
-DAPP_VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}"
-Dcimg_display=0
-Dcimg_use_png
-Dcimg_no_system_calls
-DBRLS_I18N_PREFIX=\"main/\")
if (PLATFORM_PSV OR PLATFORM_ANDROID)
set(USE_OPENSSL_CRYPTO ON)
else ()
set(USE_MBEDTLS_CRYPTO ON)
endif ()
if (PLATFORM_ANDROID OR PLATFORM_PSV)
set(MULTICAST_DISABLED ON)
endif ()
if (USE_LIBROMFS)
add_libromfs(${PROJECT_NAME} ${PROJECT_RESOURCES})
endif ()
if (USE_MBEDTLS_CRYPTO)
find_package(MbedTLS REQUIRED)
add_compile_definitions(USE_MBEDTLS_CRYPTO)
elseif (USE_OPENSSL_CRYPTO)
find_package(OpenSSL REQUIRED)
add_definitions(-DUSE_OPENSSL_CRYPTO)
endif ()
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
add_subdirectory(extern)
# setting src and include
file(GLOB_RECURSE MAIN_SRC app/src/*.cpp)
set(PLATFORM_OPTION)
if (PLATFORM_DESKTOP)
if (WIN32)
configure_file("${CMAKE_SOURCE_DIR}/app/resource.rc.in" "${CMAKE_BINARY_DIR}/resource.rc")
list(APPEND MAIN_SRC ${CMAKE_BINARY_DIR}/resource.rc)
elseif (BUNDLE_MACOS_APP)
# list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/app/borealis.icns)
endif ()
elseif (PLATFORM_SWITCH)
set(PLATFORM_LIBS
# needed by borealis
EGL glapi drm_nouveau
# base lib
nx m
)
list(APPEND MAIN_SRC
${BOREALIS_LIBRARY}/lib/platforms/switch/switch_wrapper.c
app/src/switch/wrapper.c
)
elseif (PLATFORM_PSV)
add_definitions(-D__psp2__ -D__PSV__)
elseif (PLATFORM_ANDROID)
elseif (PLATFORM_IOS OR PLATFORM_TVOS)
list(APPEND MAIN_SRC app/platforms/ios/apple_mdns.mm)
list(APPEND MAIN_SRC app/platforms/ios/apple_display.mm)
endif ()
if (USE_METAL_RENDERER)
list(APPEND MAIN_SRC app/src/streaming/video/Metal/MetalVideoRenderer.mm)
endif ()
# building target
program_target(${PROJECT_NAME} "${MAIN_SRC}")
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
# building release file
if (PLATFORM_DESKTOP)
if (BUNDLE_MACOS_APP)
set(IOS_ASSETS ${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/mac/Images.xcassets)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
# MACOSX_BUNDLE_ICON_FILE "borealis.icns"
MACOSX_BUNDLE_COPYRIGHT "Copyright 2023 ${PROJECT_AUTHOR}"
# RESOURCE "${CMAKE_SOURCE_DIR}/app/borealis.icns"
XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon"
MACOSX_BUNDLE_GUI_IDENTIFIER "${PACKAGE_NAME}"
MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION_BUILD}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}"
MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}"
XCODE_ATTRIBUTE_INFOPLIST_KEY_LSApplicationCategoryType "public.app-category.games" # Not work
XCODE_ATTRIBUTE_INSTALL_PATH $(LOCAL_APPS_DIR)
XCODE_EMBED_RESOURCES_CODE_SIGN_ON_COPY ON # Not work
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON # Not work
)
set_property(
SOURCE ${IOS_ASSETS}
PROPERTY MACOSX_PACKAGE_LOCATION "Resources"
)
target_sources(${PROJECT_NAME} PRIVATE
${IOS_ASSETS}
)
add_custom_target(${PROJECT_NAME}.data
COMMAND "${CMAKE_COMMAND}" -E copy_directory ${PROJECT_RESOURCES} ${PROJECT_NAME}.app/Contents/Resources/resources
)
else ()
add_custom_target(${PRxOJECT_NAME}.data
COMMAND "${CMAKE_COMMAND}" -E copy_directory ${PROJECT_RESOURCES} ${CMAKE_CURRENT_BINARY_DIR}/resources
)
endif ()
list(APPEND google_angle_libs
${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/mac/libEGL.dylib
${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/mac/libGLESv2.dylib
)
set_property(
SOURCE ${google_angle_libs}
PROPERTY MACOSX_PACKAGE_LOCATION "Frameworks"
)
target_sources(${PROJECT_NAME} PRIVATE
${google_angle_libs}
)
set_target_properties(${PROJECT_NAME} PROPERTIES
INSTALL_RPATH "@executable_path/../Frameworks"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks"
)
target_link_libraries(${PROJECT_NAME} PRIVATE
${google_angle_libs}
)
if (NOT USE_LIBROMFS)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.data)
endif ()
elseif (PLATFORM_PSV)
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d ATTRIBUTE2=12") # max heap size mode
vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME} UNSAFE)
if (USE_LIBROMFS)
vita_create_vpk(${PROJECT_NAME}.vpk ${PSN_TITLE_ID} ${PROJECT_NAME}.self
VERSION ${PSN_VERSION}
NAME ${PROJECT_NAME}
FILE ${CMAKE_SOURCE_DIR}/app/platforms/psv/sce_sys sce_sys
FILE ${CMAKE_SOURCE_DIR}/app/platforms/psv/module/ module
)
else()
vita_create_vpk(${PROJECT_NAME}.vpk ${PSN_TITLE_ID} ${PROJECT_NAME}.self
VERSION ${PSN_VERSION}
NAME ${PROJECT_NAME}
FILE ${CMAKE_SOURCE_DIR}/resources resources
FILE ${CMAKE_SOURCE_DIR}/app/platforms/psv/sce_sys sce_sys
FILE ${CMAKE_SOURCE_DIR}/app/platforms/psv/module/ module
)
endif()
elseif (PLATFORM_SWITCH)
if (USE_DEKO3D)
gen_dksh("${PROJECT_RESOURCES}/shaders")
endif ()
add_custom_target(${PROJECT_NAME}.nro DEPENDS ${PROJECT_NAME}
COMMAND ${NX_NACPTOOL_EXE} --create "${PROJECT_NAME}" "${PROJECT_AUTHOR}" "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}" ${PROJECT_NAME}.nacp --titleid=${PROJECT_TITLEID}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_RESOURCES} ${CMAKE_BINARY_DIR}/resources
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/resources/font
COMMAND ${NX_ELF2NRO_EXE} ${PROJECT_NAME}.elf ${PROJECT_NAME}.nro --icon=${PROJECT_ICON} --nacp=${PROJECT_NAME}.nacp --romfsdir=${CMAKE_BINARY_DIR}/resources
)
list(APPEND APP_PLATFORM_LIB dav1d z)
elseif (PLATFORM_ANDROID)
list(APPEND APP_PLATFORM_LIB android)
target_link_libraries(${PROJECT_NAME} PRIVATE
# ${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/android/arm64-v8a/libEGL_angle.so
# ${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/android/arm64-v8a/libGLESv2_angle.so
)
elseif (PLATFORM_IOS)
ios_bundle(
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/iphoneos/Splash.storyboard"
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/Images.xcassets"
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/iOSBundleInfo.plist.in"
${PROJECT_NAME}
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}"
"${VERSION_BUILD}")
list(APPEND IOS_FRAMEWORKS ${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/ios/MetalANGLE.framework)
set_target_properties(${PROJECT_NAME} PROPERTIES
INSTALL_RPATH @executable_path/Frameworks
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCSupportsGameMode YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCSupportsControllerUserInteraction YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCRequiresControllerUserInteraction YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_LSApplicationCategoryType "public.app-category.games"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks"
XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/ios/"
XCODE_ATTRIBUTE_INSTALL_PATH $(LOCAL_APPS_DIR))
elseif (PLATFORM_TVOS)
ios_bundle(
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/tvos/Splash.storyboard"
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/Images.xcassets"
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/iOSBundleInfo.plist.in"
${PROJECT_NAME}
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_ALTER}"
"${VERSION_BUILD}")
list(APPEND IOS_FRAMEWORKS ${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/tvos/MetalANGLE.framework)
set_target_properties(${PROJECT_NAME} PROPERTIES
INSTALL_RPATH @executable_path/Frameworks
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCSupportsGameMode YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCSupportsControllerUserInteraction YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCRequiresControllerUserInteraction YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_LSApplicationCategoryType "public.app-category.games"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks"
XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/extern/borealis/library/lib/extern/angle/tvos/"
XCODE_ATTRIBUTE_INSTALL_PATH $(LOCAL_APPS_DIR)
XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIconTvOS")
endif ()
target_include_directories(${PROJECT_NAME} PUBLIC
app/include
app/include/gestures
app/src/crypto
app/src/gestures
app/src/keyboards
app/src/libgamestream
app/src/streaming
app/src/streaming/audio
app/src/streaming/ffmpeg
app/src/streaming/switch
app/src/streaming/video
app/src/streaming/video/deko3d
app/src/streaming/video/OpenGL
app/src/streaming/video/Metal
app/src/utils
extern/CImg
${MBEDTLS_INCLUDE_DIRS}
${APP_PLATFORM_INCLUDE})
target_compile_options(${PROJECT_NAME} PRIVATE -ffunction-sections -fdata-sections ${APP_PLATFORM_OPTION})
find_package(CURL REQUIRED)
#find_package(MbedTLS REQUIRED)
if(NOT PLATFORM_ANDROID)
find_package(SDL2 REQUIRED)
endif()
find_package(Jansson REQUIRED)
find_package(EXPAT REQUIRED)
find_package(PNG REQUIRED)
find_library(OPUS_LIBRARY opus)
message("opus: ${OPUS_LIBRARY}")
if(PLATFORM_SWITCH)
target_link_libraries(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libavcodec.a
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libavformat.a
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libavutil.a
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libswresample.a
)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/include
)
else()
find_library(AVCODEC_LIBRARY avcodec)
message("avcodec: ${AVCODEC_LIBRARY}")
find_library(AVFORMAT_LIBRARY avformat)
message("avformat: ${AVFORMAT_LIBRARY}")
find_library(AVUTIL_LIBRARY avutil)
message("avutil: ${AVUTIL_LIBRARY}")
find_library(SWRESAMPLE_LIBRARY swresample)
message("swresample: ${SWRESAMPLE_LIBRARY}")
endif ()
# Recompiled CURL with Mbedtls support for Switch
if(PLATFORM_SWITCH)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libcurl.a)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)
endif ()
target_link_libraries(${PROJECT_NAME} PRIVATE
borealis
moonlight-common-c
Jansson::Jansson
EXPAT::EXPAT
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVFORMAT_LIBRARY}
${SWRESAMPLE_LIBRARY}
${OPUS_LIBRARY}
PNG::PNG
SDL2::SDL2
${APP_PLATFORM_LIB})
if (MULTICAST_DISABLED)
add_definitions(-DMULTICAST_DISABLED)
else ()
target_link_libraries(${PROJECT_NAME} PRIVATE mdns)
endif ()
if (USE_MBEDTLS_CRYPTO)
target_link_libraries(${PROJECT_NAME} PRIVATE
mbed::tls
mbed::x509
mbed::crypto)
else ()
target_link_libraries(${PROJECT_NAME} PRIVATE
OpenSSL::SSL
OpenSSL::Crypto)
endif ()
if (USE_GL_RENDERER)
if (PLATFORM_MACOS)
set(SUPPORT_HDR ON)
endif ()
add_definitions(-DUSE_GL_RENDERER)
endif ()
if (USE_METAL_RENDERER)
set(SUPPORT_HDR ON)
add_definitions(-DUSE_METAL_RENDERER)
endif ()
if (SUPPORT_HDR)
add_definitions(-DSUPPORT_HDR)
endif ()
if (PLATFORM_IOS OR PLATFORM_TVOS)
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_EMBED_FRAMEWORKS "${IOS_FRAMEWORKS}")
endif()
if (APPLE)
set(XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC OFF)
target_link_libraries(${PROJECT_NAME} PRIVATE "-framework CoreMedia" "-framework VideoToolbox" "-framework AVKit" "-framework MetalKit")
elseif (PLATFORM_PSV)
target_link_libraries(${PROJECT_NAME} PRIVATE mp3lame libGLESv2_stub)
endif ()