Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
190 lines (172 loc) · 7.59 KB
/
Copy pathCMakeLists.txt
File metadata and controls
190 lines (172 loc) · 7.59 KB
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
cmake_minimum_required(VERSION 3.28)
# Build the in-tree C++ package (cpp/moq) by default. Release-only builds clear
# MOQ_LOCAL and must select a release archive explicitly, so this never
# silently drifts to an old static version.
set(MOQ_LOCAL "${CMAKE_CURRENT_SOURCE_DIR}/../.." CACHE PATH "Path to the moq repo (builds cpp/moq in-tree)")
set(MOQ_VERSION "" CACHE STRING "moq-cpp archive version (required without MOQ_LOCAL)")
set(MOQ_ARCHIVE_FILE "" CACHE FILEPATH "Local moq-cpp release archive instead of a download")
if(MOQ_ARCHIVE_FILE)
if(MOQ_LOCAL)
message(FATAL_ERROR "MOQ_ARCHIVE_FILE requires an empty MOQ_LOCAL")
endif()
if(NOT EXISTS "${MOQ_ARCHIVE_FILE}" OR IS_DIRECTORY "${MOQ_ARCHIVE_FILE}")
message(FATAL_ERROR "moq-cpp archive not found: ${MOQ_ARCHIVE_FILE}")
endif()
endif()
# One predicate for both the version derivation here and the link/fetch choice
# below, so the two can't drift apart.
set(_moq_local_build FALSE)
if(MOQ_LOCAL AND EXISTS "${MOQ_LOCAL}/cpp/moq/CMakeLists.txt")
set(_moq_local_build TRUE)
endif()
if(_moq_local_build)
file(STRINGS "${MOQ_LOCAL}/cpp/moq/VERSION" _moq_link_version LIMIT_COUNT 1)
if(NOT _moq_link_version MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$")
message(FATAL_ERROR "Unsupported version '${_moq_link_version}' in ${MOQ_LOCAL}/cpp/moq/VERSION")
endif()
else()
if(NOT MOQ_VERSION)
message(FATAL_ERROR "MOQ_VERSION is required when MOQ_LOCAL does not contain cpp/moq")
endif()
if(NOT MOQ_VERSION MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$")
message(FATAL_ERROR "Unsupported moq-cpp version: ${MOQ_VERSION}")
endif()
set(_moq_link_version "${MOQ_VERSION}")
if(MOQ_ARCHIVE_FILE)
get_filename_component(_moq_archive_name "${MOQ_ARCHIVE_FILE}" NAME)
if(NOT _moq_archive_name STREQUAL "moq-cpp-${MOQ_VERSION}-${MOQ_TARGET}.${MOQ_ARCHIVE}")
message(FATAL_ERROR "moq-cpp archive does not match version, target, and format: ${_moq_archive_name}")
endif()
endif()
endif()
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE)
# The template turns this on for every directory, which puts cpp/obs and cpp/moq on the
# include path; on case-insensitive filesystems their VERSION files then answer
# `#include <version>`. Every plugin include is a same-directory quoted one, so nothing needs it.
set(CMAKE_INCLUDE_CURRENT_DIR FALSE)
project(${_name} VERSION ${_version})
option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" OFF)
option(ENABLE_QT "Use Qt functionality" OFF)
include(compilerconfig)
include(defaults)
include(helpers)
add_library(obs-moq MODULE)
if(${BUILD_PLUGIN})
find_package(libobs REQUIRED)
# FFmpeg dependency (used by the MoQ source to decode subscribed video). On
# macOS and Windows, link the ffmpeg the obs-deps bundle ships -- the same one
# OBS itself uses at runtime -- via the vendored FindFFmpeg finder (obs-deps
# ship ffmpeg with no pkg-config .pc files, so it searches the prefix). On
# Linux there's no obs-deps; pkg-config finds the system ffmpeg.
if(WIN32 OR APPLE)
find_package(FFmpeg 5.1 REQUIRED COMPONENTS avcodec avutil swscale swresample)
target_link_libraries(obs-moq PRIVATE FFmpeg::avcodec FFmpeg::avutil FFmpeg::swscale FFmpeg::swresample)
else()
include(FindPkgConfig)
pkg_check_modules(FFMPEG REQUIRED libavcodec>=59.37 libavutil>=57.28 libswscale>=6.7 libswresample>=4.7)
target_include_directories(obs-moq PRIVATE ${FFMPEG_INCLUDE_DIRS})
target_link_directories(obs-moq PRIVATE ${FFMPEG_LIBRARY_DIRS})
target_link_libraries(obs-moq PRIVATE ${FFMPEG_LIBRARIES})
endif()
else()
find_package(FFmpeg 5.1 REQUIRED COMPONENTS avcodec avutil swscale swresample)
target_link_libraries(obs-moq PRIVATE FFmpeg::avcodec FFmpeg::avutil FFmpeg::swscale FFmpeg::swresample)
endif()
target_link_libraries(obs-moq PRIVATE OBS::libobs)
if(_moq_local_build)
add_subdirectory("${MOQ_LOCAL}/cpp/moq" moq-cpp)
else()
include(FetchContent)
if(MOQ_ARCHIVE_FILE)
file(SHA256 "${MOQ_ARCHIVE_FILE}" _moq_archive_hash)
set(_moq_archive "${MOQ_ARCHIVE_FILE}")
set(_moq_archive_options URL_HASH "SHA256=${_moq_archive_hash}")
else()
set(
_moq_archive
"https://github.com/moq-dev/moq/releases/download/cpp-v${_moq_link_version}/moq-cpp-${_moq_link_version}-${MOQ_TARGET}.${MOQ_ARCHIVE}"
)
endif()
FetchContent_Declare(moq-cpp URL "${_moq_archive}" ${_moq_archive_options})
FetchContent_MakeAvailable(moq-cpp)
find_package(moq-cpp REQUIRED PATHS ${moq-cpp_SOURCE_DIR} NO_DEFAULT_PATH)
endif()
# The package carries the system libraries its Rust staticlib needs, on every platform.
target_link_libraries(obs-moq PRIVATE moq::cpp)
# The obs-deps Qt6 build references the AGL framework transitively (via
# WrapOpenGL), but recent macOS SDKs ship no linkable AGL binary -- it exists
# only in the runtime dyld shared cache. Generate a stub whose install name
# points at the real framework so the link succeeds; dyld resolves AGL at load.
if(
(ENABLE_QT OR ENABLE_FRONTEND_API)
AND APPLE
AND NOT EXISTS "${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/AGL.framework/Versions/A/AGL"
)
set(_agl_stub_dir "${CMAKE_BINARY_DIR}/agl-stub")
set(_agl_stub_lib "${_agl_stub_dir}/AGL.framework/AGL")
if(NOT EXISTS "${_agl_stub_lib}")
file(MAKE_DIRECTORY "${_agl_stub_dir}/AGL.framework")
set(_agl_arch_flags "")
foreach(_arch IN LISTS CMAKE_OSX_ARCHITECTURES)
list(APPEND _agl_arch_flags "-arch" "${_arch}")
endforeach()
execute_process(
COMMAND
xcrun clang -dynamiclib ${_agl_arch_flags} -install_name /System/Library/Frameworks/AGL.framework/Versions/A/AGL
-o "${_agl_stub_lib}" -x c /dev/null
RESULT_VARIABLE _agl_stub_result
)
if(NOT _agl_stub_result EQUAL 0)
message(WARNING "Failed to build AGL stub (${_agl_stub_result}); Qt link may fail")
endif()
endif()
target_link_options(obs-moq PRIVATE "-F${_agl_stub_dir}")
endif()
if(ENABLE_FRONTEND_API)
find_package(obs-frontend-api REQUIRED)
target_link_libraries(obs-moq PRIVATE OBS::obs-frontend-api)
target_compile_definitions(obs-moq PRIVATE MOQ_FRONTEND_API)
endif()
if(ENABLE_QT)
find_package(Qt6 COMPONENTS Widgets Core)
target_link_libraries(obs-moq PRIVATE Qt6::Core Qt6::Widgets)
target_compile_options(
obs-moq
PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-quoted-include-in-framework-header -Wno-comma>
)
set_target_properties(
obs-moq
PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON
)
endif()
target_sources(
obs-moq
PRIVATE
src/obs-moq.cpp
src/moq-audio-encoder.cpp
src/moq-audio-encoder.h
src/moq-implementation.h
src/moq-worker.h
src/moq-output.h
src/moq-service.h
src/moq-output.cpp
src/moq-service.cpp
src/moq-settings.cpp
src/moq-settings.h
src/moq-source.cpp
src/moq-source.h
)
# Sessions advertise it in SETUP (moq-implementation.h); the dock also displays it.
target_compile_definitions(obs-moq PRIVATE PLUGIN_VERSION_STRING="${PLUGIN_VERSION}")
# The dock requires both the frontend API (to register it) and Qt (to build it).
# The advanced settings dialog is Qt-only, so it ships with the dock that opens it;
# without Qt the same settings are still reachable through the service properties.
if(ENABLE_FRONTEND_API AND ENABLE_QT)
target_sources(obs-moq PRIVATE src/moq-dock.cpp src/moq-dock.h src/moq-advanced-dialog.cpp src/moq-advanced-dialog.h)
target_compile_definitions(obs-moq PRIVATE MOQ_FRONTEND_ENABLED MOQ_VERSION_STRING="${_moq_link_version}")
endif()
if(${BUILD_PLUGIN})
set_target_properties_plugin(obs-moq PROPERTIES OUTPUT_NAME ${_name})
else()
set_target_properties_obs(obs-moq PROPERTIES FOLDER plugins PREFIX "")
endif()