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