Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/util/CMakeLists.txt
4212 views
1
add_library(util
2
audio_stream.cpp
3
audio_stream.h
4
cd_image.cpp
5
cd_image.h
6
cd_image_cue.cpp
7
cd_image_chd.cpp
8
cd_image_device.cpp
9
cd_image_hasher.cpp
10
cd_image_hasher.h
11
cd_image_m3u.cpp
12
cd_image_memory.cpp
13
cd_image_mds.cpp
14
cd_image_pbp.cpp
15
cd_image_ppf.cpp
16
compress_helpers.cpp
17
compress_helpers.h
18
cue_parser.cpp
19
cue_parser.h
20
elf_file.cpp
21
elf_file.h
22
gpu_device.cpp
23
gpu_device.h
24
gpu_framebuffer_manager.h
25
gpu_shader_cache.cpp
26
gpu_shader_cache.h
27
gpu_texture.cpp
28
gpu_texture.h
29
host.cpp
30
host.h
31
http_downloader.cpp
32
http_downloader.h
33
image.cpp
34
image.h
35
imgui_fullscreen.cpp
36
imgui_fullscreen.h
37
imgui_manager.cpp
38
imgui_manager.h
39
ini_settings_interface.cpp
40
ini_settings_interface.h
41
input_manager.cpp
42
input_manager.h
43
input_source.cpp
44
input_source.h
45
iso_reader.cpp
46
iso_reader.h
47
media_capture.cpp
48
media_capture.h
49
page_fault_handler.cpp
50
page_fault_handler.h
51
platform_misc.h
52
postprocessing.cpp
53
postprocessing.h
54
postprocessing_shader.cpp
55
postprocessing_shader.h
56
postprocessing_shader_fx.cpp
57
postprocessing_shader_fx.h
58
postprocessing_shader_glsl.cpp
59
postprocessing_shader_glsl.h
60
shadergen.cpp
61
shadergen.h
62
shiftjis.cpp
63
shiftjis.h
64
sockets.cpp
65
sockets.h
66
state_wrapper.cpp
67
state_wrapper.h
68
texture_decompress.cpp
69
texture_decompress.h
70
wav_reader_writer.cpp
71
wav_reader_writer.h
72
window_info.cpp
73
window_info.h
74
)
75
76
target_precompile_headers(util PRIVATE "pch.h")
77
target_include_directories(util PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
78
target_include_directories(util PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
79
target_link_libraries(util PUBLIC common simpleini imgui)
80
target_link_libraries(util PRIVATE libchdr lzma JPEG::JPEG PNG::PNG WebP::libwebp plutosvg::plutosvg ZLIB::ZLIB SoundTouch::SoundTouchDLL xxhash zstd::libzstd_shared reshadefx)
81
82
if(ENABLE_X11)
83
target_sources(util PRIVATE
84
x11_tools.cpp
85
x11_tools.h
86
)
87
target_compile_definitions(util PRIVATE "-DENABLE_X11=1")
88
target_include_directories(util PRIVATE
89
"${X11_xcb_INCLUDE_PATH}"
90
"${X11_xcb_randr_INCLUDE_PATH}"
91
"${X11_X11_xcb_INCLUDE_PATH}"
92
)
93
endif()
94
95
if(ENABLE_WAYLAND)
96
target_compile_definitions(util PRIVATE "-DENABLE_WAYLAND=1")
97
endif()
98
99
if(ENABLE_OPENGL)
100
target_sources(util PRIVATE
101
opengl_context.cpp
102
opengl_context.h
103
opengl_device.cpp
104
opengl_device.h
105
opengl_loader.h
106
opengl_pipeline.cpp
107
opengl_pipeline.h
108
opengl_stream_buffer.cpp
109
opengl_stream_buffer.h
110
opengl_texture.cpp
111
opengl_texture.h
112
)
113
target_compile_definitions(util PUBLIC "ENABLE_OPENGL=1")
114
target_link_libraries(util PRIVATE glad)
115
116
if(WIN32)
117
target_sources(util PRIVATE
118
opengl_context_wgl.cpp
119
opengl_context_wgl.h
120
)
121
endif()
122
123
if(LINUX OR BSD OR ANDROID)
124
target_sources(util PRIVATE
125
opengl_context_egl.cpp
126
opengl_context_egl.h
127
)
128
target_compile_definitions(util PRIVATE "-DENABLE_EGL=1")
129
130
if(ENABLE_X11)
131
target_sources(util PRIVATE
132
opengl_context_egl_xcb.cpp
133
opengl_context_egl_xcb.h
134
opengl_context_egl_xlib.cpp
135
opengl_context_egl_xlib.h
136
)
137
endif()
138
if(ENABLE_WAYLAND)
139
target_sources(util PRIVATE
140
opengl_context_egl_wayland.cpp
141
opengl_context_egl_wayland.h
142
)
143
target_include_directories(util PRIVATE
144
"${Wayland_INCLUDE_DIRS}" # For wayland-egl
145
)
146
endif()
147
if(ANDROID)
148
target_include_directories(util PRIVATE "${CMAKE_SOURCE_DIR}/android")
149
endif()
150
endif()
151
152
if(APPLE)
153
target_sources(util PRIVATE
154
opengl_context_agl.mm
155
opengl_context_agl.h
156
)
157
set_source_files_properties(opengl_context_agl.mm PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
158
endif()
159
endif()
160
161
if(ENABLE_VULKAN)
162
target_sources(util PRIVATE
163
vulkan_builders.cpp
164
vulkan_builders.h
165
vulkan_device.cpp
166
vulkan_device.h
167
vulkan_entry_points.h
168
vulkan_entry_points.inl
169
vulkan_loader.cpp
170
vulkan_loader.h
171
vulkan_pipeline.cpp
172
vulkan_pipeline.h
173
vulkan_stream_buffer.cpp
174
vulkan_stream_buffer.h
175
vulkan_swap_chain.cpp
176
vulkan_swap_chain.h
177
vulkan_texture.cpp
178
vulkan_texture.h
179
)
180
target_compile_definitions(util PUBLIC "ENABLE_VULKAN=1")
181
target_link_libraries(util PUBLIC vulkan-headers)
182
endif()
183
184
# shaderc/spirv-cross is loaded dynamically to reduce module loads on startup.
185
get_target_property(SHADERC_INCLUDE_DIR Shaderc::shaderc_shared INTERFACE_INCLUDE_DIRECTORIES)
186
get_target_property(SPIRV_CROSS_INCLUDE_DIR spirv-cross-c-shared INTERFACE_INCLUDE_DIRECTORIES)
187
target_include_directories(util PUBLIC ${SHADERC_INCLUDE_DIR} ${SPIRV_CROSS_INCLUDE_DIR})
188
189
if(NOT ANDROID)
190
target_sources(util PRIVATE
191
cubeb_audio_stream.cpp
192
sdl_audio_stream.cpp
193
sdl_input_source.cpp
194
sdl_input_source.h
195
)
196
if(ENABLE_OPENGL)
197
target_sources(util PRIVATE
198
opengl_context_sdl.cpp
199
opengl_context_sdl.h
200
)
201
endif()
202
target_compile_definitions(util PUBLIC
203
ENABLE_SDL
204
)
205
target_link_libraries(util PUBLIC
206
cubeb
207
SDL3::SDL3
208
)
209
# FFmpeg loaded dynamically on demand.
210
target_include_directories(util PUBLIC ${FFMPEG_INCLUDE_DIRS})
211
endif()
212
213
if(WIN32)
214
target_sources(util PRIVATE
215
d3d_common.cpp
216
d3d_common.h
217
d3d11_device.cpp
218
d3d11_device.h
219
d3d11_pipeline.cpp
220
d3d11_pipeline.h
221
d3d11_stream_buffer.cpp
222
d3d11_stream_buffer.h
223
d3d11_texture.cpp
224
d3d11_texture.h
225
d3d12_builders.cpp
226
d3d12_builders.h
227
d3d12_descriptor_heap_manager.cpp
228
d3d12_descriptor_heap_manager.h
229
d3d12_device.cpp
230
d3d12_device.h
231
d3d12_pipeline.cpp
232
d3d12_pipeline.h
233
d3d12_stream_buffer.cpp
234
d3d12_stream_buffer.h
235
d3d12_texture.cpp
236
d3d12_texture.h
237
dinput_source.cpp
238
dinput_source.h
239
http_downloader_winhttp.cpp
240
platform_misc_win32.cpp
241
win32_raw_input_source.cpp
242
win32_raw_input_source.h
243
xinput_source.cpp
244
xinput_source.h
245
)
246
target_link_libraries(util PRIVATE d3d12ma)
247
target_link_libraries(util PRIVATE winmm.lib Dwmapi.lib winhttp.lib)
248
249
if(CMAKE_BUILD_TYPE MATCHES "Debug|Devel")
250
target_link_libraries(util PRIVATE WinPixEventRuntime::WinPixEventRuntime)
251
endif()
252
elseif(APPLE)
253
include(AddMetalSources)
254
255
set(MAC_SOURCES
256
metal_device.h
257
metal_device.mm
258
metal_layer.h
259
metal_stream_buffer.h
260
metal_stream_buffer.mm
261
platform_misc_mac.mm
262
)
263
set(METAL_SOURCES
264
"${CMAKE_CURRENT_SOURCE_DIR}/metal_shaders.metal"
265
)
266
set_property(GLOBAL PROPERTY UTIL_METAL_SOURCES ${METAL_SOURCES})
267
target_sources(util PRIVATE ${MAC_SOURCES})
268
find_library(IOK_LIBRARY IOKit REQUIRED)
269
find_library(METAL_LIBRARY Metal)
270
find_library(QUARTZCORE_LIBRARY QuartzCore)
271
target_link_libraries(util PRIVATE ${METAL_LIBRARY} ${QUARTZCORE_LIBRARY} ${IOK_LIBRARY})
272
set_source_files_properties(${MAC_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
273
elseif(NOT ANDROID)
274
target_sources(util PRIVATE
275
platform_misc_unix.cpp
276
)
277
find_package(PkgConfig REQUIRED)
278
pkg_check_modules(DBUS REQUIRED dbus-1)
279
target_include_directories(util PRIVATE ${DBUS_INCLUDE_DIRS})
280
281
if(LINUX)
282
target_link_libraries(util PRIVATE UDEV::UDEV)
283
endif()
284
endif()
285
286
if(NOT WIN32 AND NOT ANDROID)
287
target_sources(util PRIVATE
288
http_downloader_curl.cpp
289
)
290
target_link_libraries(util PRIVATE
291
CURL::libcurl
292
)
293
endif()
294
295
function(add_util_resources target)
296
if(APPLE)
297
get_property(UTIL_METAL_SOURCES GLOBAL PROPERTY UTIL_METAL_SOURCES)
298
add_metal_sources(${target} ${UTIL_METAL_SOURCES})
299
300
# Copy MoltenVK into the bundle
301
unset(MOLTENVK_PATH CACHE)
302
find_file(MOLTENVK_PATH NAMES
303
libMoltenVK.dylib
304
lib/libMoltenVK.dylib
305
)
306
if (MOLTENVK_PATH)
307
target_sources(${target} PRIVATE "${MOLTENVK_PATH}")
308
set_source_files_properties("${MOLTENVK_PATH}" PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks)
309
message(STATUS "Using MoltenVK from ${MOLTENVK_PATH}")
310
else()
311
message(WARNING "MoltenVK not found in path, it will depend on the target system having it.")
312
endif()
313
314
# Copy shaderc/spirv-cross into the bundle
315
get_target_property(SPIRV_CROSS_LIBRARY spirv-cross-c-shared IMPORTED_SONAME_RELEASE)
316
get_target_property(SHADERC_LIBRARY Shaderc::shaderc_shared IMPORTED_LOCATION_RELEASE)
317
target_sources(${target} PRIVATE "${SHADERC_LIBRARY}" "${SPIRV_CROSS_LIBRARY}")
318
set_source_files_properties("${SHADERC_LIBRARY}" "${SPIRV_CROSS_LIBRARY}" PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks)
319
320
# Copy FFmpeg libraries into the bundle
321
foreach(component avcodec avformat avutil swresample swscale)
322
string(REGEX REPLACE "\([0-9]+\)\.[0-9]+\.[0-9]+" "\\1" major "${FFMPEG_${component}_VERSION}")
323
string(REPLACE "lib${component}.dylib" "lib${component}.${major}.dylib" version_lib "${FFMPEG_${component}_LIBRARIES}")
324
target_sources(${target} PRIVATE ${version_lib})
325
set_source_files_properties(${target} PRIVATE ${version_lib} PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks)
326
endforeach()
327
elseif(ALLOW_INSTALL)
328
# Ensure we look for dependency libraries in the installation directory.
329
set_target_properties(${target} PROPERTIES INSTALL_RPATH "$ORIGIN")
330
331
# Copy dependency libraries to installation directory.
332
install_imported_dep_library(SDL3::SDL3)
333
install_imported_dep_library(Shaderc::shaderc_shared)
334
install_imported_dep_library(spirv-cross-c-shared)
335
install_imported_dep_library(SoundTouch::SoundTouchDLL)
336
install_imported_dep_library(plutosvg::plutosvg)
337
endif()
338
endfunction()
339
340