]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Add "apitrace trim" command.
[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_copier.cpp
282     common/trace_model.cpp
283     common/trace_parser.cpp
284     common/trace_parser_flags.cpp
285     common/trace_writer.cpp
286     common/trace_writer_local.cpp
287     common/trace_writer_model.cpp
288     common/trace_loader.cpp
289     common/trace_resource.cpp
290     common/trace_tools_trace.cpp
291     common/image.cpp
292     common/image_bmp.cpp
293     common/image_pnm.cpp
294     common/image_png.cpp
295     common/${os}
296 )
297
298 set_target_properties (common PROPERTIES
299     COMPILE_DEFINITIONS APITRACE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
300     # Ensure it can be statically linked in shared libraries
301     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
302 )
303
304 link_libraries (common)
305
306
307 ##############################################################################
308 # API tracers
309
310 if (WIN32)
311     if (MINGW)
312         # Silence warnings about @nn suffix mismatch
313         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
314     endif (MINGW)
315
316     # ddraw.dll
317     if (DirectX_D3D_INCLUDE_DIR)
318         include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
319         add_custom_command (
320             OUTPUT ddrawtrace.cpp
321             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
322             DEPENDS ddrawtrace.py trace.py specs/d3d.py specs/d3dtypes.py specs/d3dcaps.py specs/ddraw.py specs/winapi.py specs/stdapi.py
323         )
324         add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
325         set_target_properties (ddraw
326             PROPERTIES PREFIX ""
327             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
328             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
329         )
330         install (TARGETS ddraw LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
331     endif (DirectX_D3D_INCLUDE_DIR)
332
333     # d3d8.dll
334     if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
335         include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
336         add_custom_command (
337             OUTPUT d3d8trace.cpp
338             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
339             DEPENDS d3d8trace.py trace.py specs/d3d8.py specs/d3d8types.py specs/d3d8caps.py specs/winapi.py specs/stdapi.py
340         )
341         add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
342         set_target_properties (d3d8
343             PROPERTIES PREFIX ""
344             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
345             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
346         )
347         install (TARGETS d3d8 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
348     endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
349
350     # d3d9.dll
351     if (DirectX_D3DX9_INCLUDE_DIR)
352         include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
353         add_custom_command (
354             OUTPUT d3d9trace.cpp
355             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
356             DEPENDS d3d9trace.py trace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
357         )
358         add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
359         set_target_properties (d3d9
360             PROPERTIES PREFIX ""
361             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
362             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
363         )
364         install (TARGETS d3d9 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
365     endif (DirectX_D3DX9_INCLUDE_DIR)
366
367     # d3d10.dll
368     if (DirectX_D3D10_INCLUDE_DIR)
369         include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
370         add_custom_command (
371             OUTPUT d3d10trace.cpp
372             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
373             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
374         )
375         add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
376         set_target_properties (d3d10
377             PROPERTIES PREFIX ""
378             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
379             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
380         )
381         install (TARGETS d3d10 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
382     endif (DirectX_D3D10_INCLUDE_DIR)
383
384     # opengl32.dll
385     add_custom_command (
386         OUTPUT wgltrace.cpp
387         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
388         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
389     )
390     add_library (wgltrace MODULE specs/opengl32.def
391         wgltrace.cpp
392         glcaps.cpp
393         glproc_gl.cpp
394     )
395     add_dependencies (wgltrace glproc)
396     set_target_properties (wgltrace PROPERTIES
397         PREFIX ""
398         OUTPUT_NAME opengl32
399         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
400         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
401     )
402     install (TARGETS wgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
403
404 elseif (APPLE)
405     # OpenGL framework
406     add_custom_command (
407         OUTPUT cgltrace.cpp
408         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
409         DEPENDS cgltrace.py gltrace.py trace.py specs/cglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
410     )
411
412     add_library (cgltrace SHARED
413         cgltrace.cpp
414         glcaps.cpp
415         glproc_gl.cpp
416     )
417
418     add_dependencies (cgltrace glproc)
419
420     set_target_properties (cgltrace PROPERTIES
421         # OpenGL framework name
422         PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
423         # Specificy the version and reexport GLU symbols
424         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
425         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
426         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
427     )
428
429     target_link_libraries (cgltrace
430         pthread
431         dl
432     )
433
434     install (TARGETS cgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
435 elseif (X11_FOUND)
436     # libGL.so
437     add_custom_command (
438         OUTPUT glxtrace.cpp
439         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
440         DEPENDS glxtrace.py gltrace.py trace.py specs/glxapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
441     )
442
443     add_library (glxtrace SHARED
444         glxtrace.cpp
445         glcaps.cpp
446         glproc_gl.cpp
447     )
448
449     add_dependencies (glxtrace glproc)
450
451     set_target_properties (glxtrace PROPERTIES
452         # avoid the default "lib" prefix
453         PREFIX ""
454         # Prevent symbol relocations internal to our wrapper library to be
455         # overwritten by the application.
456         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
457         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
458         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
459     )
460
461     target_link_libraries (glxtrace
462         ${X11_X11_LIB}
463         pthread
464         dl
465     )
466
467     install (TARGETS glxtrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
468 endif ()
469
470
471 if (EGL_FOUND)
472     # libEGL.so/libGL.so
473     add_custom_command (
474         OUTPUT egltrace.cpp
475         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/egltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/egltrace.cpp
476         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
477     )
478
479     add_library (egltrace SHARED
480         egltrace.cpp
481         glcaps.cpp
482         glproc_egl.cpp
483     )
484
485     add_dependencies (egltrace glproc)
486
487     set_property (
488         TARGET egltrace
489         APPEND
490         PROPERTY COMPILE_DEFINITIONS "TRACE_EGL"
491     )
492
493     set_target_properties (egltrace PROPERTIES
494         # avoid the default "lib" prefix
495         PREFIX ""
496         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
497         # Prevent symbol relocations internal to our wrapper library to be
498         # overwritten by the application.
499         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
500         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
501     )
502
503     target_link_libraries (egltrace
504         pthread
505         dl
506     )
507
508     install (TARGETS egltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
509 endif ()
510
511 ##############################################################################
512 # API retracers
513
514 add_custom_command (
515     OUTPUT glretrace_gl.cpp
516     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
517     DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
518 )
519
520 add_custom_command (
521     OUTPUT glstate_params.cpp
522     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
523     DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py
524 )
525
526 set (retrace_sources
527     glretrace_gl.cpp
528     glretrace_cgl.cpp
529     glretrace_glx.cpp
530     glretrace_wgl.cpp
531     glretrace_egl.cpp
532     glretrace_main.cpp
533     glstate.cpp
534     glstate_params.cpp
535     retrace.cpp
536     retrace_stdc.cpp
537     glws.cpp
538 )
539
540 if (WIN32 OR APPLE OR X11_FOUND)
541     add_executable (glretrace
542         ${retrace_sources}
543         ${glws_os}
544         glproc_gl.cpp
545     )
546
547     add_dependencies (glretrace glproc)
548
549     set_property (
550         TARGET glretrace
551         APPEND
552         PROPERTY COMPILE_DEFINITIONS "RETRACE"
553     )
554
555     target_link_libraries (glretrace
556         common
557     )
558
559     if (WIN32)
560     else ()
561         if (APPLE)
562             target_link_libraries (glretrace
563                 "-framework Cocoa"
564                 "-framework ApplicationServices" # CGS*
565                 ${OPENGL_gl_LIBRARY} # CGL*
566             )
567         else ()
568             target_link_libraries (glretrace ${X11_X11_LIB})
569         endif ()
570
571         target_link_libraries (glretrace
572             # gdb doesn't like when pthreads is loaded through dlopen (which happens
573             # when dlopen'ing libGL), so link pthreads to avoid this issue.  See also
574             # http://stackoverflow.com/questions/2702628/gdb-cannot-find-new-threads-generic-error
575             pthread
576             dl
577         )
578
579         if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
580             target_link_libraries (glretrace rt)
581         endif ()
582
583     endif ()
584
585     install (TARGETS glretrace RUNTIME DESTINATION bin) 
586 endif ()
587
588 if (EGL_FOUND AND X11_FOUND AND NOT WIN32 AND NOT APPLE)
589     add_executable (eglretrace
590         ${retrace_sources}
591         glws_egl_xlib.cpp
592         glproc_egl.cpp
593     )
594
595     add_dependencies (eglretrace glproc)
596
597     set_property (
598         TARGET eglretrace
599         APPEND
600         PROPERTY COMPILE_DEFINITIONS "RETRACE"
601         PROPERTY COMPILE_DEFINITIONS "TRACE_EGL"
602     )
603
604     target_link_libraries (eglretrace
605         common
606         ${X11_X11_LIB}
607         pthread
608         dl
609     )
610
611     if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
612         target_link_libraries (eglretrace rt)
613     endif ()
614
615     install (TARGETS eglretrace RUNTIME DESTINATION bin) 
616 endif ()
617
618 ##############################################################################
619 # CLI
620
621 add_subdirectory(cli)
622
623 ##############################################################################
624 # Scripts (to support the CLI)
625
626 install (
627     PROGRAMS
628         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.sh
629         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jsondiff.py
630         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/snapdiff.py
631     DESTINATION ${SCRIPTS_INSTALL_DIR}
632 )
633
634 ##############################################################################
635 # GUI
636
637 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
638     add_subdirectory(gui)
639 endif ()
640
641
642 ##############################################################################
643 # Packaging
644
645 install (
646     FILES
647         BUGS.markdown
648         LICENSE
649         NEWS.markdown
650         README.markdown
651         TODO.markdown
652     DESTINATION ${DOC_INSTALL_DIR}
653 )
654
655 set (CPACK_PACKAGE_VERSION_MAJOR "2")
656 set (CPACK_PACKAGE_VERSION_MINOR "0")
657
658 # Use current date in YYYYMMDD format as patch number 
659 execute_process (
660     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
661     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
662 )
663
664 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
665 if (WIN32)
666     set (CPACK_GENERATOR "ZIP")
667 elseif (APPLE)
668     set (CPACK_GENERATOR "DragNDrop")
669 else ()
670     set (CPACK_GENERATOR "TBZ2")
671 endif ()
672
673 include(CPack)