-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
188 lines (166 loc) · 6.24 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
cmake_minimum_required(VERSION 3.23)
# Only interpret if() arguments as variables or keywords when unquoted.
cmake_policy(SET CMP0054 NEW)
# MSVC runtime library flags are selected by an abstraction.
cmake_policy(SET CMP0091 NEW)
project(zakuro C CXX)
list(APPEND CMAKE_PREFIX_PATH ${SORA_DIR} ${YAML_ROOT_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${SORA_DIR}/share/cmake)
set(Boost_USE_STATIC_LIBS ON)
set(WEBRTC_LIBRARY_NAME webrtc)
find_package(Boost REQUIRED COMPONENTS json filesystem)
find_package(WebRTC REQUIRED)
find_package(Sora REQUIRED)
find_package(Threads REQUIRED)
find_package(Blend2D REQUIRED)
find_package(CLI11 REQUIRED)
find_package(yaml-cpp REQUIRED)
if (ZAKURO_PLATFORM STREQUAL "ubuntu-20.04_x86_64" OR ZAKURO_PLATFORM STREQUAL "ubuntu-22.04_x86_64" OR ZAKURO_PLATFORM STREQUAL "ubuntu-24.04_x86_64")
find_package(Libva REQUIRED)
find_package(Libdrm REQUIRED)
endif()
add_executable(zakuro)
set_target_properties(zakuro PROPERTIES CXX_STANDARD 17 C_STANDARD 17)
set_target_properties(zakuro PROPERTIES POSITION_INDEPENDENT_CODE ON)
string(SUBSTRING "${ZAKURO_COMMIT}" 0 8 ZAKURO_COMMIT_SHORT)
string(SUBSTRING "${WEBRTC_COMMIT}" 0 8 WEBRTC_COMMIT_SHORT)
configure_file(src/zakuro_version.gen.h.template ${CMAKE_CURRENT_BINARY_DIR}/zakuro_version.gen.h)
target_include_directories(zakuro PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
# OpenH264
target_include_directories(zakuro PRIVATE ${OPENH264_ROOT_DIR}/include)
target_sources(zakuro
PRIVATE
src/embedded_binary.cpp
src/fake_video_capturer.cpp
src/main.cpp
src/nop_video_decoder.cpp
src/util.cpp
src/virtual_client.cpp
src/wav_reader.cpp
src/xorshift.cpp
src/y4m_reader.cpp
src/zakuro.cpp
src/zakuro_audio_device_module.cpp
src/zakuro_version.cpp
)
target_link_libraries(zakuro
PRIVATE
Sora::sora
Boost::filesystem
CLI11::CLI11
Blend2D::Blend2D
yaml-cpp::yaml-cpp
)
target_compile_definitions(zakuro
PRIVATE
# CLI11 は C++17 でのビルドにおいて std::filesystem を利用するが、これを clang で解決するには c++fs のリンクが必要になる。
# しかし、 libwebrtc の libc++ では std::filesystem が提供されていないため下記のオプションを追加して利用しないようにする。
CLI11_HAS_FILESYSTEM=0
OPENSSL_IS_BORINGSSL
# https://github.com/boostorg/container_hash/issues/22 と同じ問題が clang-15 でも起きるので、これを手動で定義して回避する
BOOST_NO_CXX98_FUNCTION_BASE
)
# リソースファイルを作る
list(APPEND RESOURCE_FILES
Kosugi-Regular.ttf
num000_01.wav
num001_01.wav
num002_01.wav
num003_01.wav
num004_01.wav
num005_01.wav
num006_01.wav
num007_01.wav
num008_01.wav
num009_01.wav
num010_01.wav
num011_01.wav
num012_01.wav
num013_01.wav
num014_01.wav
num015_01.wav
num016_01.wav
num017_01.wav
num018_01.wav
num019_01.wav
num020_01.wav
num021_01.wav
num022_01.wav
num023_01.wav
num024_01.wav
num025_01.wav
num026_01.wav
num027_01.wav
num028_01.wav
num029_01.wav
num030_01.wav
num030_02.wav
num040_01.wav
num040_02.wav
num050_01.wav
num050_02.wav
num060_01.wav
num060_02.wav
num070_01.wav
num070_02.wav
num080_01.wav
num080_02.wav
num090_01.wav
num090_02.wav
)
list(LENGTH RESOURCE_FILES RESOURCE_FILES_LENGTH)
math(EXPR RESOURCE_FILES_LENGTH_MINUS_ONE "${RESOURCE_FILES_LENGTH} - 1")
foreach(n RANGE ${RESOURCE_FILES_LENGTH_MINUS_ONE})
list(GET RESOURCE_FILES ${n} file)
# ID として使う名前
# Kosugi-Regular.ttf → RESOURCE_KOSUGI_REGULAR_TTF
# num_030_2.wav → RESOURCE_NUM_030_2_WAV
string(TOUPPER "RESOURCE_${file}" file_id)
string(REGEX REPLACE "[-.]" "_" file_id "${file_id}")
# macOS のセクション名(15文字以内)
# Kosugi-Regular.ttf → Kosugi_Regular_
# num_030_2.wav → num_030_2_wav
string(REGEX REPLACE "[-.]" "_" file_name_macos "${file}")
string(SUBSTRING "${file_name_macos}" 0 15 file_name_macos)
# Linux の外部宣言の名前のベース
# Kosugi-Regular.ttf → Kosugi_Regular_ttf
# num_030_2.wav → num_030_2_wav
string(REGEX REPLACE "[-.]" "_" file_name_linux "${file}")
# バイナリの組み込み
if (ZAKURO_PLATFORM STREQUAL "macos_arm64")
target_link_options(zakuro PRIVATE "SHELL:-sectcreate __DATA ${file_name_macos} ${CMAKE_CURRENT_SOURCE_DIR}/resource/${file}")
elseif (ZAKURO_PLATFORM STREQUAL "ubuntu-20.04_x86_64" OR ZAKURO_PLATFORM STREQUAL "ubuntu-22.04_x86_64" OR ZAKURO_PLATFORM STREQUAL "ubuntu-24.04_x86_64")
set(objfile ${file}.o)
add_custom_command(OUTPUT ${objfile}
COMMAND ld
ARGS -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/${objfile} ${file}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resource
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/resource/${file})
set_source_files_properties(${objfile}
PROPERTIES
EXTERNAL_OBJECT true
GENERATED true
)
target_sources(zakuro PRIVATE ${objfile})
endif()
string(APPEND RESOURCE_FILE_ID_DEFINES "#define ${file_id} ${n}\n")
string(APPEND RESOURCE_FILE_NAME_MACOS_DEFINES " \"${file_name_macos}\",\n")
string(APPEND RESOURCE_FILE_NAME_LINUX_EXTERNS "extern const unsigned char _binary_${file_name_linux}_start[];\n")
string(APPEND RESOURCE_FILE_NAME_LINUX_EXTERNS "extern const unsigned char _binary_${file_name_linux}_end[];\n")
string(APPEND RESOURCE_FILE_NAME_LINUX_START_DEFINES " _binary_${file_name_linux}_start,\n")
string(APPEND RESOURCE_FILE_NAME_LINUX_END_DEFINES " _binary_${file_name_linux}_end,\n")
endforeach()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/embedded_binary.generated.template.h
${CMAKE_CURRENT_BINARY_DIR}/embedded_binary.generated.h
@ONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/embedded_binary.generated.priv.template.h
${CMAKE_CURRENT_BINARY_DIR}/embedded_binary.generated.priv.h
@ONLY)
if (ZAKURO_PLATFORM STREQUAL "macos_arm64")
target_compile_options(zakuro PRIVATE -fconstant-string-class=NSConstantString)
target_link_options(zakuro PRIVATE -ObjC)
set_target_properties(zakuro PROPERTIES CXX_VISIBILITY_PRESET hidden)
elseif (ZAKURO_PLATFORM STREQUAL "ubuntu-20.04_x86_64" OR ZAKURO_PLATFORM STREQUAL "ubuntu-22.04_x86_64" OR ZAKURO_PLATFORM STREQUAL "ubuntu-24.04_x86_64")
endif()