-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
907 lines (396 loc) · 15.2 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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0054 NEW)
#Support for visual studio build
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
#Build shared libraries opposed to single exe
set(NV_SHARED_REPLAY_LIB 0)
#Choose an available Windows SDK in order to meet the Direct3D feature level
set(REQUIRED_WIN_SDK_VERSION 10.0.16299.0)
if(WIN32 AND REQUIRED_WIN_SDK_VERSION AND NOT CMAKE_SYSTEM_VERSION)
#Detect all the Windows SDKs that exist on the machine.
set(WIN_SDK_VERSIONS "")
#We have to check "Windows.h" to verify if the SDK is really installed because there's no reliable registry value since v10.
macro(AddWinSDKIfInstalled SDK_INCLUDE_PATH SDK_VERSION)
if(EXISTS "${SDK_INCLUDE_PATH}/um/Windows.h")
list(APPEND WIN_SDK_VERSIONS "${SDK_VERSION}")
endif()
endmacro()
#Helper to identify all sub - sdks within a windows SDK directory
macro(AddWin10SDKIfInstalled SDK_DIR)
if(IS_DIRECTORY ${SDK_DIR})
file(GLOB SUB_FOLDERS RELATIVE ${SDK_DIR}/Include ${SDK_DIR}/Include/*)
foreach(SUB_FOLDER ${SUB_FOLDERS})
AddWinSDKIfInstalled(${SDK_DIR}/Include/${SUB_FOLDER} ${SUB_FOLDER})
endforeach()
endif()
endmacro()
# Start at v8.1 because the minimum Visual Studio supported version is 2015.
get_filename_component(WIN_SDK_V81_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot81]" ABSOLUTE CACHE)
if(NOT WIN_SDK_V81_ROOT)
set(WIN_SDK_V81_ROOT "%ProgramFiles%/Windows Kits/8.1")
endif()
if(IS_DIRECTORY ${WIN_SDK_V81_ROOT})
AddWinSDKIfInstalled(${WIN_SDK_V81_ROOT}/Include 8.1)
endif()
# Add system-identified windows 10 SDKs
get_filename_component(WIN_SDK_V10_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE CACHE)
if(NOT WIN_SDK_V10_ROOT)
set(WIN_SDK_V10_ROOT "%ProgramFiles%/Windows Kits/10")
endif()
AddWin10SDKIfInstalled(${WIN_SDK_V10_ROOT})
# Add a user-specified WINDOWS_SDK_DIR if one is defined
if(DEFINED ENV{WINDOWS_SDK_DIR})
AddWin10SDKIfInstalled($ENV{WINDOWS_SDK_DIR})
endif()
message(STATUS "Finding Windows SDK to satisfy required SDK of: ${REQUIRED_WIN_SDK_VERSION}")
if (WIN_SDK_VERSIONS)
message(STATUS "Windows SDK candidates: ${WIN_SDK_VERSIONS}")
else()
message(STATUS "Windows SDK candidates: none found")
endif()
# Select a version that satisfies the requirement
list(REVERSE WIN_SDK_VERSIONS)
foreach(WIN_SDK_VERSION ${WIN_SDK_VERSIONS})
if (WIN_SDK_VERSION VERSION_GREATER_EQUAL REQUIRED_WIN_SDK_VERSION)
message(STATUS "Windows SDK selected: ${WIN_SDK_VERSION}")
set(CMAKE_SYSTEM_VERSION ${WIN_SDK_VERSION})
break()
endif()
endforeach()
if(NOT CMAKE_SYSTEM_VERSION)
message(FATAL_ERROR "Failed to find a Windows SDK that available to use. The minimum version required is ${REQUIRED_WIN_SDK_VERSION}")
endif()
endif()
# Set project name
set(CPP_PROJECT_NAME "wrench__2021_05_06__11_13_11")
set(CPP_PROJECT_NAME_NOTIMESTAMP "wrench")
# Set output name
option(NV_USE_TIMESTAMP_IN_APPLICATION_NAME "Rename output file to be timestamped" OFF)
if (NV_USE_TIMESTAMP_IN_APPLICATION_NAME)
set(CPP_OUTPUT_NAME ${CPP_PROJECT_NAME})
else()
set(CPP_OUTPUT_NAME ${CPP_PROJECT_NAME_NOTIMESTAMP})
endif()
project(${CPP_PROJECT_NAME})
# The target name is trim so that cmake path lengths are short; the actual
# executable will be renamed via a property below
set(EXECUTABLE_TARGET cppcap)
# As there's no default LINUX variable, add one.
if(UNIX AND NOT APPLE)
set(LINUX 1)
endif()
# Information of original capture
set(NV_ORIGINAL_OS WIN32)
set(NV_ORIGINAL_WINSYS win32)
set(NV_ORIGINAL_ARCH 64)
# Value of NV_ORIGINAL_OS is WIN32 or LINUX
# ${${NV_ORIGINAL_OS}} is 1 only if this project is built on the same platform than original capture.
set(NV_BUILD_ON_ORIGINAL_PLATFORM ${${NV_ORIGINAL_OS}})
# Determine default window system if not specified by "-DNV_WINSYS"
if(NOT NV_WINSYS)
if(NV_BUILD_ON_ORIGINAL_PLATFORM)
set(NV_WINSYS ${NV_ORIGINAL_WINSYS})
else()
if(LINUX)
set(NV_WINSYS xcb)
elseif(WIN32)
set(NV_WINSYS win32)
endif()
endif()
endif()
# Make NV_WINSYS to be an option selectable in cmake-GUI
set(NV_WINSYS "${NV_WINSYS}" CACHE STRING "Select window system type to interact with graphics API")
if(LINUX)
set_property(CACHE NV_WINSYS PROPERTY STRINGS xcb x11 vulkan-d2d)
elseif(WIN32)
set_property(CACHE NV_WINSYS PROPERTY STRINGS win32)
endif()
if(NV_WINSYS STREQUAL xcb)
set(NV_USE_XCB 1)
elseif(NV_WINSYS STREQUAL x11)
set(NV_USE_X11 1)
elseif(NV_WINSYS STREQUAL vulkan-d2d)
set(NV_USE_D2D 1)
elseif(NV_WINSYS STREQUAL win32)
set(NV_USE_WIN32 1)
else()
message(FATAL_ERROR "Specified wrong 'NV_WINSYS' argument. Must be one of 'xcb'/'x11'/'vulkan-d2d' on Linux or 'win32' on Windows.")
endif()
# Determine bitness
if(CMAKE_SIZEOF_VOID_P STREQUAL "8")
set(NV_USE_64BIT 1)
elseif(CMAKE_SIZEOF_VOID_P STREQUAL "4")
set(NV_USE_32BIT 1)
else()
message(FATAL_ERROR "Unrecognized bitness.")
endif()
if(NV_USE_64BIT)
link_directories(
)
endif()
if(NV_USE_32BIT)
link_directories(
)
endif()
# Checking arch mismatch
if((NV_USE_64BIT AND NV_ORIGINAL_ARCH STREQUAL 64) OR (NV_USE_32BIT AND NV_ORIGINAL_ARCH STREQUAL 32))
message(STATUS "Building ${NV_ORIGINAL_ARCH}-bit app.")
elseif(NV_USE_64BIT AND NV_ORIGINAL_ARCH STREQUAL 32)
message(WARNING "Application originally targeted 32-bit; compiling now as 64-bit.")
elseif(NV_USE_32BIT AND NV_ORIGINAL_ARCH STREQUAL 64)
message(FATAL_ERROR "Application originally targeted 64-bit; compiling now as 32-bit.")
else()
message(FATAL_ERROR "Unrecognized original bitwise.")
endif()
if(CMAKE_BUILD_TYPE)
message(STATUS "Building with a ${CMAKE_BUILD_TYPE} configuration.")
endif()
# Control library linkage mode
if (NV_SHARED_REPLAY_LIB)
set(ReplayExecutorLibraryType "SHARED")
set(NV_REPLAY_LIB_TYPE "NV_REPLAY_LIB_SHARED")
else()
set(ReplayExecutorLibraryType "STATIC")
set(NV_REPLAY_LIB_TYPE "NV_REPLAY_LIB_STATIC")
endif()
################################################################################
# Replay Executor (library)
################################################################################
add_library(ReplayExecutor ${ReplayExecutorLibraryType}
Application.cpp
CommonReplay.cpp
D3D11Replay.cpp
DXGIReplay.cpp
DataScope.cpp
Helpers.cpp
ReadOnlyDatabase.cpp
ReplayHelpers.cpp
ThreadPool.cpp
Threading.cpp
)
target_include_directories(ReplayExecutor PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
include)
target_compile_definitions(ReplayExecutor
PUBLIC
NV_HAS_FUNCTION_OVERRIDES
PRIVATE
${NV_REPLAY_LIB_TYPE}
ReplayExecutor_EXPORTS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(ReplayExecutor PUBLIC
-std=c++14
-fvisibility=hidden
-Os
-g
-O2
-Werror=return-type)
endif()
option(NV_USE_MANAGED_WINSYS "Use replayer managed windowing system" OFF)
if(NV_USE_MANAGED_WINSYS OR NOT NV_BUILD_ON_ORIGINAL_PLATFORM OR NOT NV_WINSYS STREQUAL NV_ORIGINAL_WINSYS)
target_compile_definitions(ReplayExecutor PUBLIC NV_USE_MANAGED_WINSYS)
endif()
target_include_directories(ReplayExecutor PUBLIC
)
if(NV_USE_64BIT)
target_link_libraries(ReplayExecutor
PRIVATE
)
endif()
if(NV_USE_32BIT)
target_link_libraries(ReplayExecutor
PRIVATE
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# -W3 - Warning level 3 (see https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=vs-2019)
# -MP - Build with multiple processes to speed up the build
# -Ob2 - Inline expansion level, allows compiler to expand any function not explicitly marked for no inlining
# -wdXXXX - disable a specific Warning (see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-c4800-through-c4999?view=vs-2019)
# -bigobj - Increase number of sections in .obj file to a capacity of 4Gb, we have some very large files
# -GS- - Disable buffer security check, this is local .exe that is primarily built from generated code and requires full performance
target_compile_options(ReplayExecutor PUBLIC -W3 -MP -Ob2 -wd4351 -wd4819 -bigobj -GS-)
# -MDd - Defines _DEBUG, _MT, and _DLL for multithreaded debug builds, uses shared run-time library
target_compile_options(ReplayExecutor PUBLIC $<$<CONFIG:DEBUG>:-MDd>)
# -MD - Defines _MT and _DLL for multithreaded builds, uses shared run-time library
# -Oi - Generate instrinsic functions to replace some function calls with instrinsic functions for better performance
target_compile_options(ReplayExecutor PUBLIC $<$<CONFIG:RELEASE>:-Oi -MD>)
# /OPT:NOICF - Disable COMDAT folding
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO /OPT:NOICF")
endif()
# Set platform specific properties.
if(NV_USE_WIN32)
# Windows application & Win32 windowing system
target_sources(ReplayExecutor
PRIVATE
Win32Application.cpp
WindowSystem_Win32.cpp)
target_compile_definitions(ReplayExecutor
PUBLIC
_CRT_SECURE_NO_DEPRECATE
NOMINMAX
NV_USE_WIN32=1
VK_USE_PLATFORM_WIN32_KHR
UNICODE
PRIVATE
ReplayExecutor_EXPORTS)
endif()
if(LINUX)
# Linux application
target_sources(ReplayExecutor
PRIVATE
LinuxApplication.cpp)
# XCB Windowing System
if(NV_USE_XCB)
target_sources(ReplayExecutor
PRIVATE
WindowSystem_Xcb.cpp)
target_compile_definitions(ReplayExecutor
PUBLIC
NV_USE_XCB=1
VK_USE_PLATFORM_XCB_KHR)
target_link_libraries(ReplayExecutor
PRIVATE
dl
xcb
xcb-icccm
pthread)
endif()
# X11 Windowing System
if(NV_USE_X11)
target_sources(ReplayExecutor
PRIVATE
WindowSystem_X11.cpp)
target_compile_definitions(ReplayExecutor
PUBLIC
NV_USE_X11=1
VK_USE_PLATFORM_XLIB_KHR)
target_link_libraries(ReplayExecutor
PRIVATE
dl
X11
Xau
pthread)
endif()
# D2D Windowing System
if(NV_USE_D2D)
target_sources(ReplayExecutor
PRIVATE
WindowSystem_D2d.cpp)
target_compile_definitions(ReplayExecutor
PUBLIC
NV_USE_D2D=1)
target_link_libraries(ReplayExecutor
PRIVATE
dl
pthread)
endif()
endif()
################################################################################
# Generated Replay (library)
################################################################################
add_library(GeneratedReplay ${ReplayExecutorLibraryType}
Frame0Part00.cpp
FrameReset00.cpp
FrameSetup00.cpp
PerfMarkersReset.cpp
PerfMarkersSetup.cpp
ReplayProcedures.cpp
Resources00.cpp
WinResourcesReset.cpp
WinResourcesSetup.cpp
function_overrides.cpp
)
target_include_directories(GeneratedReplay
PRIVATE
include)
target_link_libraries(GeneratedReplay
PRIVATE
ReplayExecutor
d3d11.lib
d3d9.lib
d3d9.lib
dxgi.lib
)
target_compile_definitions(GeneratedReplay
PUBLIC
${NV_REPLAY_LIB_TYPE})
if(NV_USE_WIN32)
target_compile_definitions(GeneratedReplay
PUBLIC
_CRT_SECURE_NO_DEPRECATE
NV_USE_WIN32=1
VK_USE_PLATFORM_WIN32_KHR)
endif()
################################################################################
# Main (executable)
################################################################################
add_executable(Main
Main.cpp
)
set_target_properties(Main PROPERTIES OUTPUT_NAME ${CPP_OUTPUT_NAME})
set_directory_properties(PROPERTY VS_STARTUP_PROJECT Main)
if(WIN32)
target_compile_definitions(Main
PRIVATE
NOMINMAX)
endif()
if(LINUX)
target_link_libraries(Main
PRIVATE
pthread)
endif()
# Dynamic DLL dependency
add_dependencies(Main GeneratedReplay)
# Link libraries
target_link_libraries(Main
PRIVATE
ReplayExecutor)
# Static link the generate replay for the non-shared (e.g. static build)
if (NOT NV_SHARED_REPLAY_LIB)
target_link_libraries(Main PRIVATE
GeneratedReplay)
endif()
################################################################################
# Install
################################################################################
# Install targets
if(NOT NV_INSTALL_FOLDER)
set(NV_INSTALL_FOLDER bin)
endif()
install(TARGETS Main RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/${NV_INSTALL_FOLDER}/)
if(NV_SHARED_REPLAY_LIB)
if(WIN32)
install(TARGETS GeneratedReplay RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/${NV_INSTALL_FOLDER}/)
install(TARGETS ReplayExecutor RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/${NV_INSTALL_FOLDER}/)
else()
install(TARGETS GeneratedReplay LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/${NV_INSTALL_FOLDER}/)
install(TARGETS ReplayExecutor LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/${NV_INSTALL_FOLDER}/)
endif()
endif()
set(RESOURCE_FILES_OR_FOLDERS)
if(NV_USE_64BIT)
list(APPEND RESOURCE_FILES_OR_FOLDERS
)
endif()
if(NV_USE_32BIT)
list(APPEND RESOURCE_FILES_OR_FOLDERS
)
endif()
if(LINUX)
install(PROGRAMS "Linux/run_replay.sh" DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/${NV_INSTALL_FOLDER}/ RENAME "${CPP_OUTPUT_NAME}.sh")
endif()
if(RESOURCE_FILES_OR_FOLDERS)
set(RESOURCES)
foreach(FILE_OR_FOLDER ${RESOURCE_FILES_OR_FOLDERS})
# The behavior of "IS_DIRECTORY" is well-defined only for full paths.
get_filename_component(ABSOLUTE_FILE_OR_FOLDER "${FILE_OR_FOLDER}" ABSOLUTE)
if(IS_DIRECTORY ${ABSOLUTE_FILE_OR_FOLDER})
file(GLOB SUB_FILES ${ABSOLUTE_FILE_OR_FOLDER}/*.*)
list(APPEND RESOURCES ${SUB_FILES})
else()
list(APPEND RESOURCES ${FILE_OR_FOLDER})
endif()
endforeach()
install(FILES ${RESOURCES} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/${NV_INSTALL_FOLDER}/)
endif()