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