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