]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Minimal D3D11 support.
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2
3 project (apitrace)
4
5
6 ##############################################################################
7 # Options
8
9 # On Mac OS X build fat binaries with i386 and x86_64 architectures by default.
10 if (APPLE AND NOT CMAKE_OSX_ARCHITECTURES)
11     set (CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
12 endif ()
13
14 # We use a cached string variable instead of the standard (boolean) OPTION
15 # command so that we can default to auto-detecting optional depencies, while
16 # still providing a mechanism to force/disable these optional dependencies, as
17 # prescribed in http://www.gentoo.org/proj/en/qa/automagic.xml
18 set (ENABLE_GUI "AUTO" CACHE STRING "Enable Qt GUI.")
19
20 set (ENABLE_CLI true CACHE BOOL "Enable command Line interface.")
21
22 set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
23
24
25 ##############################################################################
26 # Find dependencies
27
28 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
29
30 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
31
32 if (ANDROID)
33     set (ENABLE_GUI false)
34 else ()
35     macro (find_host_package)
36         find_package (${ARGN})
37     endmacro()
38 endif ()
39
40 find_host_package (PythonInterp REQUIRED)
41 find_package (Threads)
42
43 if (ENABLE_GUI)
44     if (NOT (ENABLE_GUI STREQUAL "AUTO"))
45         set (REQUIRE_GUI REQUIRED)
46     endif ()
47     find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
48     find_package (QJSON ${REQUIRE_GUI})
49 endif ()
50
51 if (WIN32)
52     find_package (DirectX)
53     set (ENABLE_EGL false)
54 elseif (APPLE)
55     set (ENABLE_EGL false)
56 else ()
57     find_package (X11)
58
59     if (X11_FOUND)
60         include_directories (${X11_INCLUDE_DIR})
61         add_definitions (-DHAVE_X11)
62     endif ()
63 endif ()
64
65
66 ##############################################################################
67 # Set global build options
68
69 include (CheckCXXCompilerFlag)
70
71 if (WIN32)
72     # http://msdn.microsoft.com/en-us/library/aa383745.aspx
73     add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
74 else (WIN32)
75     CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
76     if (CXX_COMPILER_FLAG_VISIBILITY)
77         add_definitions ("-fvisibility=hidden")
78     endif ()
79 endif ()
80
81 if (MSVC)
82     # C99 includes for msvc
83     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msvc)
84
85     # Enable math constants defines
86     add_definitions (-D_USE_MATH_DEFINES)
87
88     # No min/max macros
89     add_definitions (-DNOMINMAX)
90
91     # Adjust warnings
92     add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
93     add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
94     add_definitions (-W4)
95     add_definitions (-wd4063) # not a valid value for switch of enum
96     add_definitions (-wd4127) # conditional expression is constant
97     add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
98     add_definitions (-wd4505) # unreferenced local function has been removed
99     add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
100     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
101     add_definitions (-wd4018) # signed/unsigned mismatch
102     
103     # Use static runtime
104     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
105     foreach (flag_var
106         CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
107         CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
108     )
109         if (${flag_var} MATCHES "/MD")
110             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
111         endif ()
112     endforeach (flag_var)
113 else ()
114     # Adjust warnings
115     add_definitions (-Wall)
116     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
117     add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
118 endif ()
119
120 if (MINGW)
121     # Avoid depending on MinGW runtime DLLs
122     check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
123     if (HAVE_STATIC_LIBGCC_FLAG)
124         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
125         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
126         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
127     endif ()
128     check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
129     if (HAVE_STATIC_LIBSTDCXX_FLAG)
130         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
131         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
132         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
133     endif ()
134 endif ()
135
136
137 # Put all executables into the same top level build directory, regardless of
138 # which subdirectory they are declared
139 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
140
141
142 ##############################################################################
143 # Bundled dependencies
144 #
145 # We always use the bundled zlib, libpng, and snappy sources:
146 # - on Windows to make it easy to deploy the wrappers DLLs
147 # - on unices to prevent symbol collisions when tracing applications that link
148 # against other versions of these libraries
149
150 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
151 set (ZLIB_LIBRARIES z_bundled)
152 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
153
154 include_directories (${ZLIB_INCLUDE_DIRS})
155
156 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
157 set (SNAPPY_LIBRARIES snappy_bundled)
158 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
159
160 include_directories (${SNAPPY_INCLUDE_DIRS})
161
162 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
163 set (PNG_DEFINITIONS "")
164 set (PNG_LIBRARIES png_bundled)
165
166 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
167 include_directories (${PNG_INCLUDE_DIR})
168 add_definitions (${PNG_DEFINITIONS})
169
170 if (MSVC)
171     add_subdirectory (thirdparty/getopt EXCLUDE_FROM_ALL)
172     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
173     set (GETOPT_LIBRARIES getopt_bundled)
174 endif ()
175
176 if (WIN32)
177     add_subdirectory (thirdparty/less)
178 endif ()
179
180 # The Qt website provides binaries for Windows and MacOSX, and they are
181 # automatically found by cmake without any manual intervention.  The situation
182 # for QJSON is substantially different: there are no binaries for QJSON
183 # available, and there is no standard installation directory that is detected
184 # by cmake.
185 #
186 # By bundling the QJSON source, we make it much more easier to build the GUI on
187 # Windows and MacOSX.  But we only use the bundled sources when ENABLE_GUI is
188 # AUTO.
189 if (QT4_FOUND AND NOT QJSON_FOUND AND (ENABLE_GUI STREQUAL "AUTO"))
190     add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
191     set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
192     set (QJSON_LIBRARY_DIRS)
193     set (QJSON_LIBRARIES qjson_bundled)
194     set (QJSON_FOUND TRUE)
195 endif ()
196
197 # We use bundled headers for all Khronos APIs, to guarantee support for both
198 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
199 # are so intertwined that conditional compilation extremely difficult. This
200 # also avoids missing/inconsistent declarations in system headers.
201 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
202
203 ##############################################################################
204 # Installation directories
205
206 if (WIN32 OR APPLE)
207     # On Windows/MacOSX, applications are usually installed on a directory of
208     # their own
209     set (DOC_INSTALL_DIR doc)
210     set (LIB_INSTALL_DIR lib)
211 else ()
212     set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
213     set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
214 endif ()
215
216 set(SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
217 set(WRAPPER_INSTALL_DIR ${LIB_INSTALL_DIR}/wrappers)
218
219 # Expose the binary/install directories to source
220 #
221 # TODO: Use the same directory layout, for both build and install directories,
222 # so that binaries can find each other using just relative paths.
223 #
224 add_definitions(
225     -DAPITRACE_BINARY_DIR="${CMAKE_BINARY_DIR}"
226     -DAPITRACE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
227     -DAPITRACE_WRAPPER_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${WRAPPER_INSTALL_DIR}"
228 )
229
230
231 ##############################################################################
232 # Common libraries / utilities
233
234 include_directories (
235     ${CMAKE_CURRENT_BINARY_DIR}
236     ${CMAKE_CURRENT_SOURCE_DIR}
237     ${CMAKE_CURRENT_SOURCE_DIR}/common
238 )
239
240 add_custom_command (
241     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
242     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
243     DEPENDS glproc.py dispatch.py specs/wglapi.py specs/glxapi.py specs/cglapi.py specs/eglapi.py specs/glesapi.py specs/glapi.py specs/gltypes.py specs/stdapi.py
244 )
245
246 # Wrap glproc.hpp as a target to prevent the command from being executed
247 # multiple times simulatenously, when the targets that depend on it are built
248 # in parallel.
249 add_custom_target (glproc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
250
251 if (WIN32)
252     set (os os_win32.cpp)
253     set (glws_os glws_wgl.cpp)
254 else ()
255     set (os os_posix.cpp)
256     if (APPLE)
257         set (glws_os glws_cocoa.mm)
258     else ()
259         set (glws_os glws_glx.cpp)
260     endif ()
261 endif ()
262
263 add_library (common STATIC
264     common/trace_callset.cpp
265     common/trace_dump.cpp
266     common/trace_file.cpp
267     common/trace_file_read.cpp
268     common/trace_file_write.cpp
269     common/trace_file_zlib.cpp
270     common/trace_file_snappy.cpp
271     common/trace_model.cpp
272     common/trace_parser.cpp
273     common/trace_parser_flags.cpp
274     common/trace_writer.cpp
275     common/trace_writer_local.cpp
276     common/trace_writer_model.cpp
277     common/trace_loader.cpp
278     common/trace_resource.cpp
279     common/trace_tools_trace.cpp
280     common/image.cpp
281     common/image_bmp.cpp
282     common/image_pnm.cpp
283     common/image_png.cpp
284     common/${os}
285 )
286
287 set_target_properties (common PROPERTIES
288     COMPILE_DEFINITIONS APITRACE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
289     # Ensure it can be statically linked in shared libraries
290     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
291 )
292
293 if (ANDROID)
294     target_link_libraries (common log)
295 endif ()
296
297
298 ##############################################################################
299 # API tracers
300
301 if (WIN32)
302     if (MINGW)
303         # Silence warnings about @nn suffix mismatch
304         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
305     endif ()
306
307     # ddraw.dll
308     if (DirectX_D3D_INCLUDE_DIR)
309         include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
310         add_custom_command (
311             OUTPUT ddrawtrace.cpp
312             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
313             DEPENDS ddrawtrace.py trace.py specs/d3d.py specs/d3dtypes.py specs/d3dcaps.py specs/ddraw.py specs/winapi.py specs/stdapi.py
314         )
315         add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
316         target_link_libraries (ddraw
317             common
318             ${ZLIB_LIBRARIES}
319             ${SNAPPY_LIBRARIES}
320         )
321         set_target_properties (ddraw
322             PROPERTIES PREFIX ""
323             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
324             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
325         )
326         install (TARGETS ddraw LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
327     endif ()
328
329     # d3d8.dll
330     if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
331         include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
332         add_custom_command (
333             OUTPUT d3d8trace.cpp
334             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
335             DEPENDS d3d8trace.py trace.py specs/d3d8.py specs/d3d8types.py specs/d3d8caps.py specs/winapi.py specs/stdapi.py
336         )
337         add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
338         target_link_libraries (d3d8
339             common
340             ${ZLIB_LIBRARIES}
341             ${SNAPPY_LIBRARIES}
342         )
343         set_target_properties (d3d8
344             PROPERTIES PREFIX ""
345             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
346             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
347         )
348         install (TARGETS d3d8 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
349     endif ()
350
351     # d3d9.dll
352     if (DirectX_D3DX9_INCLUDE_DIR)
353         include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
354         add_custom_command (
355             OUTPUT d3d9trace.cpp
356             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
357             DEPENDS d3d9trace.py trace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
358         )
359         add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
360         target_link_libraries (d3d9
361             common
362             ${ZLIB_LIBRARIES}
363             ${SNAPPY_LIBRARIES}
364         )
365         set_target_properties (d3d9
366             PROPERTIES PREFIX ""
367             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
368             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
369         )
370         install (TARGETS d3d9 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
371     endif ()
372
373     # d3d10.dll
374     if (DirectX_D3DX10_INCLUDE_DIR)
375         include_directories (SYSTEM ${DirectX_D3DX10_INCLUDE_DIR})
376         add_custom_command (
377             OUTPUT d3d10trace.cpp
378             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
379             DEPENDS d3d10trace.py trace.py specs/d3d10misc.py specs/d3d10.py specs/d3d10sdklayers.py specs/d3dcommon.py specs/dxgi.py specs/dxgitype.py specs/dxgiformat.py specs/winapi.py specs/stdapi.py
380         )
381         add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
382         target_link_libraries (d3d10
383             common
384             ${ZLIB_LIBRARIES}
385             ${SNAPPY_LIBRARIES}
386         )
387         set_target_properties (d3d10
388             PROPERTIES PREFIX ""
389             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
390             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
391         )
392         install (TARGETS d3d10 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
393     endif ()
394
395     # d3d10_1.dll
396     if (DirectX_D3DX10_INCLUDE_DIR AND DirectX_D3D10_1_INCLUDE_DIR)
397         include_directories (SYSTEM ${DirectX_D3D10_1_INCLUDE_DIR})
398         add_custom_command (
399             OUTPUT d3d10_1trace.cpp
400             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10_1trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10_1trace.cpp
401             DEPENDS d3d10_1trace.py trace.py specs/d3d10_1.py specs/d3d10.py specs/d3d10sdklayers.py specs/d3dcommon.py specs/dxgi.py specs/dxgitype.py specs/dxgiformat.py specs/winapi.py specs/stdapi.py
402         )
403         add_library (d3d10_1 MODULE specs/d3d10_1.def d3d10_1trace.cpp)
404         target_link_libraries (d3d10_1
405             common
406             ${ZLIB_LIBRARIES}
407             ${SNAPPY_LIBRARIES}
408         )
409         set_target_properties (d3d10_1
410             PROPERTIES PREFIX ""
411             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
412             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
413         )
414         install (TARGETS d3d10_1 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
415     endif ()
416
417     # d3d11.dll
418     if (DirectX_D3DX11_INCLUDE_DIR)
419         include_directories (SYSTEM ${DirectX_D3DX11_INCLUDE_DIR})
420         add_custom_command (
421             OUTPUT d3d11trace.cpp
422             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d11trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d11trace.cpp
423             DEPENDS d3d11trace.py trace.py specs/d3d11.py specs/d3d11sdklayers.py specs/d3dcommon.py specs/dxgi.py specs/dxgitype.py specs/dxgiformat.py specs/winapi.py specs/stdapi.py
424         )
425         add_library (d3d11 MODULE specs/d3d11.def d3d11trace.cpp)
426         target_link_libraries (d3d11
427             common
428             ${ZLIB_LIBRARIES}
429             ${SNAPPY_LIBRARIES}
430         )
431         set_target_properties (d3d11
432             PROPERTIES PREFIX ""
433             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
434             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
435         )
436         install (TARGETS d3d11 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
437     endif ()
438
439     # opengl32.dll
440     add_custom_command (
441         OUTPUT wgltrace.cpp
442         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
443         DEPENDS wgltrace.py gltrace.py trace.py specs/wglapi.py specs/wglenum.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/winapi.py specs/stdapi.py
444     )
445     add_library (wgltrace MODULE specs/opengl32.def
446         wgltrace.cpp
447         glcaps.cpp
448         glproc_gl.cpp
449     )
450     add_dependencies (wgltrace glproc)
451     target_link_libraries (wgltrace
452         common
453         ${ZLIB_LIBRARIES}
454         ${SNAPPY_LIBRARIES}
455     )
456     set_target_properties (wgltrace PROPERTIES
457         PREFIX ""
458         OUTPUT_NAME opengl32
459         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
460         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
461     )
462     install (TARGETS wgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
463
464 elseif (APPLE)
465     # OpenGL framework
466     add_custom_command (
467         OUTPUT cgltrace.cpp
468         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
469         DEPENDS cgltrace.py gltrace.py trace.py specs/cglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
470     )
471
472     add_library (cgltrace SHARED
473         cgltrace.cpp
474         glcaps.cpp
475         glproc_gl.cpp
476     )
477
478     add_dependencies (cgltrace glproc)
479
480     set_target_properties (cgltrace PROPERTIES
481         # OpenGL framework name
482         PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
483         # Specificy the version and reexport GLU symbols
484         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
485         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
486         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
487     )
488
489     target_link_libraries (cgltrace
490         common
491         ${ZLIB_LIBRARIES}
492         ${SNAPPY_LIBRARIES}
493         ${CMAKE_THREAD_LIBS_INIT}
494         dl
495     )
496
497     install (TARGETS cgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
498 elseif (X11_FOUND)
499     # libGL.so
500     add_custom_command (
501         OUTPUT glxtrace.cpp
502         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
503         DEPENDS glxtrace.py gltrace.py trace.py specs/glxapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
504     )
505
506     add_library (glxtrace SHARED
507         glxtrace.cpp
508         glcaps.cpp
509         glproc_gl.cpp
510     )
511
512     add_dependencies (glxtrace glproc)
513
514     set_target_properties (glxtrace PROPERTIES
515         # avoid the default "lib" prefix
516         PREFIX ""
517         # Prevent symbol relocations internal to our wrapper library to be
518         # overwritten by the application.
519         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
520         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
521         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
522     )
523
524     target_link_libraries (glxtrace
525         common
526         ${ZLIB_LIBRARIES}
527         ${SNAPPY_LIBRARIES}
528         ${X11_X11_LIB}
529         ${CMAKE_THREAD_LIBS_INIT}
530         dl
531     )
532
533     install (TARGETS glxtrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
534 endif ()
535
536
537 if (ENABLE_EGL AND NOT WIN32 AND NOT APPLE)
538     # libEGL.so/libGL.so
539     add_custom_command (
540         OUTPUT egltrace.cpp
541         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/egltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/egltrace.cpp
542         DEPENDS egltrace.py gltrace.py trace.py specs/eglapi.py specs/glesapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
543     )
544
545     add_library (egltrace SHARED
546         egltrace.cpp
547         glcaps.cpp
548         glproc_egl.cpp
549     )
550
551     add_dependencies (egltrace glproc)
552
553     set_target_properties (egltrace PROPERTIES
554         # avoid the default "lib" prefix
555         PREFIX ""
556         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
557         # Prevent symbol relocations internal to our wrapper library to be
558         # overwritten by the application.
559         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
560         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
561     )
562
563     target_link_libraries (egltrace
564         common
565         ${ZLIB_LIBRARIES}
566         ${SNAPPY_LIBRARIES}
567         ${CMAKE_THREAD_LIBS_INIT}
568         dl
569     )
570
571     install (TARGETS egltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
572 endif ()
573
574 ##############################################################################
575 # API retracers
576
577 add_custom_command (
578     OUTPUT glretrace_gl.cpp
579     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
580     DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
581 )
582
583 add_custom_command (
584     OUTPUT glstate_params.cpp
585     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate_params.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
586     DEPENDS glstate_params.py specs/glparams.py specs/gltypes.py specs/stdapi.py
587 )
588
589 add_library (retrace_common
590     glretrace_gl.cpp
591     glretrace_cgl.cpp
592     glretrace_glx.cpp
593     glretrace_wgl.cpp
594     glretrace_egl.cpp
595     glretrace_main.cpp
596     glstate.cpp
597     glstate_images.cpp
598     glstate_params.cpp
599     glstate_shaders.cpp
600     retrace.cpp
601     retrace_stdc.cpp
602     glws.cpp
603 )
604
605 add_dependencies (retrace_common glproc)
606
607 set_property (
608     TARGET retrace_common
609     APPEND
610     PROPERTY COMPILE_DEFINITIONS "RETRACE"
611 )
612
613 if (WIN32 OR APPLE OR X11_FOUND)
614     add_executable (glretrace
615         ${glws_os}
616         glproc_gl.cpp
617     )
618
619     add_dependencies (glretrace glproc)
620
621     set_property (
622         TARGET glretrace
623         APPEND
624         PROPERTY COMPILE_DEFINITIONS "RETRACE"
625     )
626
627     target_link_libraries (glretrace
628         retrace_common
629         common
630         ${PNG_LIBRARIES}
631         ${ZLIB_LIBRARIES}
632         ${SNAPPY_LIBRARIES}
633     )
634
635     if (WIN32)
636     else ()
637         if (APPLE)
638             target_link_libraries (glretrace
639                 "-framework Cocoa"
640                 "-framework ApplicationServices" # CGS*
641                 #"-framework OpenGL" # CGL*
642             )
643         else ()
644             target_link_libraries (glretrace ${X11_X11_LIB})
645         endif ()
646
647         target_link_libraries (glretrace
648             # gdb doesn't like when pthreads is loaded through dlopen (which happens
649             # when dlopen'ing libGL), so link pthreads to avoid this issue.  See also
650             # http://stackoverflow.com/questions/2702628/gdb-cannot-find-new-threads-generic-error
651             ${CMAKE_THREAD_LIBS_INIT}
652             dl
653         )
654
655         if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
656             target_link_libraries (glretrace rt)
657         endif ()
658
659     endif ()
660
661     install (TARGETS glretrace RUNTIME DESTINATION bin) 
662 endif ()
663
664 if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE)
665     add_executable (eglretrace
666         glws_egl_xlib.cpp
667         glproc_egl.cpp
668     )
669
670     add_dependencies (eglretrace glproc)
671
672     set_property (
673         TARGET eglretrace
674         APPEND
675         PROPERTY COMPILE_DEFINITIONS "RETRACE"
676     )
677
678     target_link_libraries (eglretrace
679         retrace_common
680         common
681         ${PNG_LIBRARIES}
682         ${ZLIB_LIBRARIES}
683         ${SNAPPY_LIBRARIES}
684         ${X11_X11_LIB}
685         ${CMAKE_THREAD_LIBS_INIT}
686         dl
687     )
688
689     if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
690         target_link_libraries (eglretrace rt)
691     endif ()
692
693     install (TARGETS eglretrace RUNTIME DESTINATION bin) 
694 endif ()
695
696 if (WIN32 AND DirectX_D3DX9_FOUND)
697     add_custom_command (
698         OUTPUT d3dretrace_d3d9.cpp
699         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp
700         DEPENDS d3dretrace.py retrace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
701     )
702
703     include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
704     add_executable (d3dretrace
705         retrace.cpp
706         retrace_stdc.cpp
707         d3dretrace_main.cpp
708         d3dretrace_d3d9.cpp
709     )
710     target_link_libraries (d3dretrace
711         common
712         ${ZLIB_LIBRARIES}
713         ${SNAPPY_LIBRARIES}
714         ${DirectX_D3D9_LIBRARY}
715     )
716 endif ()
717
718 ##############################################################################
719 # CLI
720
721 if (ENABLE_CLI)
722     add_subdirectory(cli)
723 endif ()
724
725 ##############################################################################
726 # Scripts (to support the CLI)
727
728 install (
729     PROGRAMS
730         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.py
731         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jsondiff.py
732         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/snapdiff.py
733     DESTINATION ${SCRIPTS_INSTALL_DIR}
734 )
735
736 ##############################################################################
737 # GUI
738
739 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
740     add_subdirectory(gui)
741 endif ()
742
743
744 ##############################################################################
745 # Packaging
746
747 install (
748     FILES
749         BUGS.markdown
750         LICENSE
751         NEWS.markdown
752         README.markdown
753     DESTINATION ${DOC_INSTALL_DIR}
754 )
755
756 set (CPACK_PACKAGE_VERSION_MAJOR "3")
757 set (CPACK_PACKAGE_VERSION_MINOR "0")
758
759 # Use current date in YYYYMMDD format as patch number 
760 execute_process (
761     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
762     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
763 )
764
765 # cpack mistakenly detects Mingw-w64 as win32
766 if (MINGW)
767     if (CMAKE_SIZEOF_VOID_P EQUAL 8)
768         set (CPACK_SYSTEM_NAME win64)
769     endif ()
770 endif ()
771
772 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
773 if (WIN32)
774     set (CPACK_GENERATOR "ZIP")
775 elseif (APPLE)
776     set (CPACK_GENERATOR "DragNDrop")
777 else ()
778     set (CPACK_GENERATOR "TBZ2")
779 endif ()
780
781 include(CPack)