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