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
|
##############################################################################
# API tracers
if (ENABLE_STATIC_LIBGCC)
add_linker_flags (-static-libgcc)
endif ()
if (ENABLE_STATIC_LIBSTDCXX)
# Unfortunately for a long time static libstdcxx didn't built with -fPIC
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28811
include (CheckCXXSourceCompiles)
set (CMAKE_REQUIRED_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
set (CMAKE_REQUIRED_LIBRARIES -shared -static-libgcc -static-libstdc++)
check_cxx_source_compiles (
"
#include <string>
std::string s;
"
STATIC_LIBSTDCXX_PIC
)
unset (CMAKE_REQUIRED_LIBRARIES)
unset (CMAKE_REQUIRED_FLAGS)
if (STATIC_LIBSTDCXX_PIC)
add_linker_flags (-static-libstdc++)
endif ()
endif ()
macro (target_linker_version_script target version_script)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT ANDROID)
# https://sourceware.org/binutils/docs/ld/VERSION.html
set_property (
TARGET ${target}
APPEND_STRING
PROPERTY LINK_FLAGS " -Wl,--version-script=${version_script}"
)
# XXX: Unfortunately LINK_DEPENDS is ignored in non-Makefile generators
# See also http://www.cmake.org/pipermail/cmake/2010-May/037206.html
add_custom_target (${target}_version_script
DEPENDS ${version_script}
VERBATIM
)
#set_property (
# TARGET ${target}
# PROPERTY LINK_DEPENDS ${version_script}
#)
add_dependencies (${target} ${target}_version_script)
endif ()
endmacro ()
set (CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories (
${CMAKE_SOURCE_DIR}/helpers
${CMAKE_BINARY_DIR}/dispatch
${CMAKE_SOURCE_DIR}/dispatch
${CMAKE_SOURCE_DIR}/lib/guids
${CMAKE_SOURCE_DIR}/thirdparty/crc32c
)
if (NOT WIN32 AND NOT APPLE)
# Prevent symbol relocations internal to our wrapper library to be
# overwritten by the application. And fail if there are missing
# symbols.
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic -Wl,-Bsymbolic-functions")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-Bsymbolic -Wl,-Bsymbolic-functions")
# Fail if there are missing symbols, except when using Address Sanitizer
# since libasan symbols are supposed to be preloaded.
if (NOT ENABLE_ASAN)
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,defs")
endif ()
endif ()
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# Code shared across all APIs
add_convenience_library (trace
assert.cpp
memtrace.hpp
memtrace.cpp
)
target_link_libraries (trace
common
guids
crc32c
${SNAPPY_LIBRARIES}
)
# Code shared across all OpenGL variants
add_convenience_library (gltrace_common
glcaps.cpp
config.cpp
gltrace_arrays.cpp
gltrace_state.cpp
)
add_dependencies (gltrace_common glproc)
target_link_libraries (gltrace_common
glhelpers
trace
)
if (WIN32)
if (MINGW)
# Silence warnings about @nn suffix mismatch
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
endif ()
# ddraw.dll
if (DirectX_D3D_INCLUDE_FOUND)
include_directories (BEFORE SYSTEM ${DirectX_D3D_INCLUDE_DIR})
add_custom_command (
OUTPUT ddrawtrace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
DEPENDS
ddrawtrace.py
dlltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/d3d.py
${CMAKE_SOURCE_DIR}/specs/d3dtypes.py
${CMAKE_SOURCE_DIR}/specs/d3dcaps.py
${CMAKE_SOURCE_DIR}/specs/ddraw.py
${CMAKE_SOURCE_DIR}/specs/winapi.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (ddrawtrace MODULE ddraw.def ddrawtrace.cpp)
target_link_libraries (ddrawtrace
trace
)
set_target_properties (ddrawtrace PROPERTIES
PREFIX ""
OUTPUT_NAME ddraw
)
install (TARGETS ddrawtrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
install_pdb (ddrawtrace DESTINATION ${WRAPPER_INSTALL_DIR})
endif ()
# d3d8.dll
if (DirectX_D3D8_INCLUDE_FOUND AND DirectX_D3D9_INCLUDE_FOUND)
include_directories (BEFORE SYSTEM ${DirectX_D3D9_INCLUDE_DIR} ${DirectX_D3D8_INCLUDE_DIR})
add_custom_command (
OUTPUT d3d8trace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
DEPENDS
d3d8trace.py
dlltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/d3d8.py
${CMAKE_SOURCE_DIR}/specs/d3d8types.py
${CMAKE_SOURCE_DIR}/specs/d3d8caps.py
${CMAKE_SOURCE_DIR}/specs/winapi.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (d3d8trace MODULE
d3d8.def
d3d8trace.cpp
d3d9shader.cpp
)
target_link_libraries (d3d8trace
d3dhelpers
trace
)
set_target_properties (d3d8trace PROPERTIES
PREFIX ""
OUTPUT_NAME d3d8
)
install (TARGETS d3d8trace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
install_pdb (d3d8trace DESTINATION ${WRAPPER_INSTALL_DIR})
endif ()
# d3d9.dll
if (DirectX_D3D9_INCLUDE_FOUND)
include_directories (BEFORE SYSTEM ${DirectX_D3D9_INCLUDE_DIR})
add_custom_command (
OUTPUT d3d9trace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
DEPENDS
d3d9trace.py
dlltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/d3d9.py
${CMAKE_SOURCE_DIR}/specs/d3d9types.py
${CMAKE_SOURCE_DIR}/specs/d3d9caps.py
${CMAKE_SOURCE_DIR}/specs/dxva2.py
${CMAKE_SOURCE_DIR}/specs/winapi.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (d3d9trace MODULE
d3d9.def
d3d9trace.cpp
d3d9shader.cpp
)
target_link_libraries (d3d9trace
d3dhelpers
trace
)
set_target_properties (d3d9trace PROPERTIES
PREFIX ""
OUTPUT_NAME d3d9
)
install (TARGETS d3d9trace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
install_pdb (d3d9trace DESTINATION ${WRAPPER_INSTALL_DIR})
endif ()
# dxgi.dll, d3d10.dll, d3d10_1.dll, d3d11.dll
if (DirectX_D3D11_3_INCLUDE_FOUND)
include_directories (BEFORE SYSTEM ${DirectX_D3D11_3_INCLUDE_DIR})
add_custom_command (
OUTPUT dxgitrace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/dxgitrace.py > ${CMAKE_CURRENT_BINARY_DIR}/dxgitrace.cpp
DEPENDS
dxgitrace.py
dlltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/d3d11.py
${CMAKE_SOURCE_DIR}/specs/dcomp.py
${CMAKE_SOURCE_DIR}/specs/d3d11sdklayers.py
${CMAKE_SOURCE_DIR}/specs/d3d10.py
${CMAKE_SOURCE_DIR}/specs/d3d10sdklayers.py
${CMAKE_SOURCE_DIR}/specs/dxgi.py
${CMAKE_SOURCE_DIR}/specs/d3d9.py
${CMAKE_SOURCE_DIR}/specs/winapi.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (dxgitrace MODULE
dxgitrace.def
dxgitrace.cpp
d3dcommonshader.cpp
)
target_link_libraries (dxgitrace
d3dhelpers
trace
)
set_target_properties (dxgitrace
PROPERTIES PREFIX ""
)
install (TARGETS dxgitrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
install_pdb (dxgitrace DESTINATION ${WRAPPER_INSTALL_DIR})
endif ()
# d2d1.dll, dwrite.dll
if (DirectX_D2D1_1_INCLUDE_FOUND)
include_directories (BEFORE SYSTEM ${DirectX_D2D1_1_INCLUDE_DIR})
add_custom_command (
OUTPUT d2d1trace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d2d1trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d2d1trace.cpp
DEPENDS
d2d1trace.py
dlltrace.py
trace.py
${CMAKE_SOURCE_DIR}/specs/d2d1.py
${CMAKE_SOURCE_DIR}/specs/dwrite.py
${CMAKE_SOURCE_DIR}/specs/dcommon.py
${CMAKE_SOURCE_DIR}/specs/dxgi.py
${CMAKE_SOURCE_DIR}/specs/winapi.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (d2d1trace MODULE d2d1trace.def d2d1trace.cpp)
target_link_libraries (d2d1trace
trace
)
set_target_properties (d2d1trace
PROPERTIES PREFIX ""
)
install (TARGETS d2d1trace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
install_pdb (d2d1trace DESTINATION ${WRAPPER_INSTALL_DIR})
endif ()
# opengl32.dll
add_custom_command (
OUTPUT wgltrace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
DEPENDS
wgltrace.py
gltrace.py
dlltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/wglapi.py
${CMAKE_SOURCE_DIR}/specs/wglenum.py
${CMAKE_SOURCE_DIR}/specs/glapi.py
${CMAKE_SOURCE_DIR}/specs/glparams.py
${CMAKE_SOURCE_DIR}/specs/gltypes.py
${CMAKE_SOURCE_DIR}/specs/winapi.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (wgltrace MODULE opengl32.def
wgltrace.cpp
)
add_dependencies (wgltrace glproc)
target_link_libraries (wgltrace
gltrace_common
glproc
glproc_gl
)
set_target_properties (wgltrace PROPERTIES
PREFIX ""
OUTPUT_NAME opengl32
)
install (TARGETS wgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
install_pdb (wgltrace DESTINATION ${WRAPPER_INSTALL_DIR})
elseif (APPLE)
# OpenGL framework
add_custom_command (
OUTPUT cgltrace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
DEPENDS
cgltrace.py
gltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/cglapi.py
${CMAKE_SOURCE_DIR}/specs/glapi.py
${CMAKE_SOURCE_DIR}/specs/glparams.py
${CMAKE_SOURCE_DIR}/specs/gltypes.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (cgltrace SHARED
cgltrace.cpp
)
add_dependencies (cgltrace glproc)
set_target_properties (cgltrace PROPERTIES
# OpenGL framework name
OUTPUT_NAME "OpenGL"
# Mac framework
FRAMEWORK true
# Specificy the version and reexport GLU symbols
LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
)
target_link_libraries (cgltrace
gltrace_common
glproc_gl
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
)
install (TARGETS cgltrace FRAMEWORK DESTINATION ${WRAPPER_INSTALL_DIR})
elseif (X11_FOUND)
# libGL.so
add_custom_command (
OUTPUT glxtrace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
DEPENDS
glxtrace.py
gltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/glxapi.py
${CMAKE_SOURCE_DIR}/specs/glapi.py
${CMAKE_SOURCE_DIR}/specs/glparams.py
${CMAKE_SOURCE_DIR}/specs/gltypes.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (glxtrace SHARED
glxtrace.cpp
dlsym.cpp
)
add_dependencies (glxtrace glproc)
set_target_properties (glxtrace PROPERTIES
# avoid the default "lib" prefix
PREFIX ""
)
target_link_libraries (glxtrace
gltrace_common
glproc_gl
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
)
target_linker_version_script (glxtrace ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.version)
install (TARGETS glxtrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
endif ()
if (ENABLE_EGL AND NOT WIN32 AND NOT APPLE)
# libEGL.so/libGL.so
add_custom_command (
OUTPUT egltrace.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/egltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/egltrace.cpp
DEPENDS
egltrace.py
gltrace.py
trace.py
${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
${CMAKE_SOURCE_DIR}/specs/eglapi.py
${CMAKE_SOURCE_DIR}/specs/eglenum.py
${CMAKE_SOURCE_DIR}/specs/glapi.py
${CMAKE_SOURCE_DIR}/specs/glparams.py
${CMAKE_SOURCE_DIR}/specs/gltypes.py
${CMAKE_SOURCE_DIR}/specs/stdapi.py
)
add_library (egltrace SHARED
egltrace.cpp
dlsym.cpp
)
add_dependencies (egltrace glproc)
set_target_properties (egltrace PROPERTIES
# avoid the default "lib" prefix
PREFIX ""
)
target_compile_definitions (egltrace PRIVATE -DEGLTRACE=1)
target_link_libraries (egltrace
gltrace_common
glproc_egl
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
)
target_linker_version_script (egltrace ${CMAKE_CURRENT_SOURCE_DIR}/egltrace.version)
install (TARGETS egltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
endif ()
|