]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Link need libraries explicitly.
[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 # The Qt website provides binaries for Windows and MacOSX, and they are
173 # automatically found by cmake without any manual intervention.  The situation
174 # for QJSON is substantially different: there are no binaries for QJSON
175 # available, and there is no standard installation directory that is detected
176 # by cmake.
177 #
178 # By bundling the QJSON source, we make it much more easier to build the GUI on
179 # Windows and MacOSX.  But we only use the bundled sources when ENABLE_GUI is
180 # AUTO.
181 if (QT4_FOUND AND NOT QJSON_FOUND AND (ENABLE_GUI STREQUAL "AUTO"))
182     add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
183     set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
184     set (QJSON_LIBRARY_DIRS)
185     set (QJSON_LIBRARIES qjson_bundled)
186     set (QJSON_FOUND TRUE)
187 endif ()
188
189 # We use bundled headers for all Khronos APIs, to guarantee support for both
190 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
191 # are so intertwined that conditional compilation extremely difficult. This
192 # also avoids missing/inconsistent declarations in system headers.
193 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
194
195 ##############################################################################
196 # Installation directories
197
198 if (WIN32 OR APPLE)
199     # On Windows/MacOSX, applications are usually installed on a directory of
200     # their own
201     set (DOC_INSTALL_DIR doc)
202     set (LIB_INSTALL_DIR lib)
203 else ()
204     set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
205     set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
206 endif ()
207
208 set(SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
209 set(WRAPPER_INSTALL_DIR ${LIB_INSTALL_DIR}/wrappers)
210
211 # Expose the binary/install directories to source
212 #
213 # TODO: Use the same directory layout, for both build and install directories,
214 # so that binaries can find each other using just relative paths.
215 #
216 add_definitions(
217     -DAPITRACE_BINARY_DIR="${CMAKE_BINARY_DIR}"
218     -DAPITRACE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
219     -DAPITRACE_WRAPPER_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${WRAPPER_INSTALL_DIR}"
220 )
221
222
223 ##############################################################################
224 # Common libraries / utilities
225
226 include_directories (
227     ${CMAKE_CURRENT_BINARY_DIR}
228     ${CMAKE_CURRENT_SOURCE_DIR}
229     ${CMAKE_CURRENT_SOURCE_DIR}/common
230 )
231
232 add_custom_command (
233     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
234     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
235     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
236 )
237
238 # Wrap glproc.hpp as a target to prevent the command from being executed
239 # multiple times simulatenously, when the targets that depend on it are built
240 # in parallel.
241 add_custom_target (glproc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
242
243 if (WIN32)
244     set (os os_win32.cpp)
245     set (glws_os glws_wgl.cpp)
246 else ()
247     set (os os_posix.cpp)
248     if (APPLE)
249         set (glws_os glws_cocoa.mm)
250     else ()
251         set (glws_os glws_glx.cpp)
252     endif ()
253 endif ()
254
255 add_library (common STATIC
256     common/trace_callset.cpp
257     common/trace_dump.cpp
258     common/trace_file.cpp
259     common/trace_file_read.cpp
260     common/trace_file_write.cpp
261     common/trace_file_zlib.cpp
262     common/trace_file_snappy.cpp
263     common/trace_model.cpp
264     common/trace_parser.cpp
265     common/trace_parser_flags.cpp
266     common/trace_writer.cpp
267     common/trace_writer_local.cpp
268     common/trace_writer_model.cpp
269     common/trace_loader.cpp
270     common/trace_resource.cpp
271     common/trace_tools_trace.cpp
272     common/image.cpp
273     common/image_bmp.cpp
274     common/image_pnm.cpp
275     common/image_png.cpp
276     common/${os}
277 )
278
279 set_target_properties (common PROPERTIES
280     COMPILE_DEFINITIONS APITRACE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
281     # Ensure it can be statically linked in shared libraries
282     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
283 )
284
285
286 ##############################################################################
287 # API tracers
288
289 if (WIN32)
290     if (MINGW)
291         # Silence warnings about @nn suffix mismatch
292         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
293     endif (MINGW)
294
295     # ddraw.dll
296     if (DirectX_D3D_INCLUDE_DIR)
297         include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
298         add_custom_command (
299             OUTPUT ddrawtrace.cpp
300             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
301             DEPENDS ddrawtrace.py trace.py specs/d3d.py specs/d3dtypes.py specs/d3dcaps.py specs/ddraw.py specs/winapi.py specs/stdapi.py
302         )
303         add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
304         target_link_libraries (ddraw
305             common
306             ${ZLIB_LIBRARIES}
307             ${SNAPPY_LIBRARIES}
308         )
309         set_target_properties (ddraw
310             PROPERTIES PREFIX ""
311             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
312             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
313         )
314         install (TARGETS ddraw LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
315     endif (DirectX_D3D_INCLUDE_DIR)
316
317     # d3d8.dll
318     if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
319         include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
320         add_custom_command (
321             OUTPUT d3d8trace.cpp
322             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
323             DEPENDS d3d8trace.py trace.py specs/d3d8.py specs/d3d8types.py specs/d3d8caps.py specs/winapi.py specs/stdapi.py
324         )
325         add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
326         target_link_libraries (d3d8
327             common
328             ${ZLIB_LIBRARIES}
329             ${SNAPPY_LIBRARIES}
330         )
331         set_target_properties (d3d8
332             PROPERTIES PREFIX ""
333             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
334             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
335         )
336         install (TARGETS d3d8 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
337     endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
338
339     # d3d9.dll
340     if (DirectX_D3DX9_INCLUDE_DIR)
341         include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
342         add_custom_command (
343             OUTPUT d3d9trace.cpp
344             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
345             DEPENDS d3d9trace.py trace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
346         )
347         add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
348         target_link_libraries (d3d9
349             common
350             ${ZLIB_LIBRARIES}
351             ${SNAPPY_LIBRARIES}
352         )
353         set_target_properties (d3d9
354             PROPERTIES PREFIX ""
355             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
356             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
357         )
358         install (TARGETS d3d9 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
359     endif (DirectX_D3DX9_INCLUDE_DIR)
360
361     # d3d10.dll
362     if (DirectX_D3D10_INCLUDE_DIR)
363         include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
364         add_custom_command (
365             OUTPUT d3d10trace.cpp
366             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
367             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
368         )
369         add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
370         target_link_libraries (d3d10
371             common
372             ${ZLIB_LIBRARIES}
373             ${SNAPPY_LIBRARIES}
374         )
375         set_target_properties (d3d10
376             PROPERTIES PREFIX ""
377             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
378             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
379         )
380         install (TARGETS d3d10 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
381     endif (DirectX_D3D10_INCLUDE_DIR)
382
383     # opengl32.dll
384     add_custom_command (
385         OUTPUT wgltrace.cpp
386         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
387         DEPENDS wgltrace.py gltrace.py trace.py specs/wglapi.py specs/wglenum.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/winapi.py specs/stdapi.py
388     )
389     add_library (wgltrace MODULE specs/opengl32.def
390         wgltrace.cpp
391         glcaps.cpp
392         glproc_gl.cpp
393     )
394     add_dependencies (wgltrace glproc)
395     target_link_libraries (wgltrace
396         common
397         ${ZLIB_LIBRARIES}
398         ${SNAPPY_LIBRARIES}
399     )
400     set_target_properties (wgltrace PROPERTIES
401         PREFIX ""
402         OUTPUT_NAME opengl32
403         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
404         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
405     )
406     install (TARGETS wgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
407
408 elseif (APPLE)
409     # OpenGL framework
410     add_custom_command (
411         OUTPUT cgltrace.cpp
412         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
413         DEPENDS cgltrace.py gltrace.py trace.py specs/cglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
414     )
415
416     add_library (cgltrace SHARED
417         cgltrace.cpp
418         glcaps.cpp
419         glproc_gl.cpp
420     )
421
422     add_dependencies (cgltrace glproc)
423
424     set_target_properties (cgltrace PROPERTIES
425         # OpenGL framework name
426         PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
427         # Specificy the version and reexport GLU symbols
428         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
429         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
430         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
431     )
432
433     target_link_libraries (cgltrace
434         common
435         ${ZLIB_LIBRARIES}
436         ${SNAPPY_LIBRARIES}
437         ${CMAKE_THREAD_LIBS_INIT}
438         dl
439     )
440
441     install (TARGETS cgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
442 elseif (X11_FOUND)
443     # libGL.so
444     add_custom_command (
445         OUTPUT glxtrace.cpp
446         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
447         DEPENDS glxtrace.py gltrace.py trace.py specs/glxapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
448     )
449
450     add_library (glxtrace SHARED
451         glxtrace.cpp
452         glcaps.cpp
453         glproc_gl.cpp
454     )
455
456     add_dependencies (glxtrace glproc)
457
458     set_target_properties (glxtrace PROPERTIES
459         # avoid the default "lib" prefix
460         PREFIX ""
461         # Prevent symbol relocations internal to our wrapper library to be
462         # overwritten by the application.
463         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
464         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
465         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
466     )
467
468     target_link_libraries (glxtrace
469         common
470         ${ZLIB_LIBRARIES}
471         ${SNAPPY_LIBRARIES}
472         ${X11_X11_LIB}
473         ${CMAKE_THREAD_LIBS_INIT}
474         dl
475     )
476
477     install (TARGETS glxtrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
478 endif ()
479
480
481 if (ENABLE_EGL AND NOT WIN32 AND NOT APPLE)
482     # libEGL.so/libGL.so
483     add_custom_command (
484         OUTPUT egltrace.cpp
485         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/egltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/egltrace.cpp
486         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
487     )
488
489     add_library (egltrace SHARED
490         egltrace.cpp
491         glcaps.cpp
492         glproc_egl.cpp
493     )
494
495     add_dependencies (egltrace glproc)
496
497     set_property (
498         TARGET egltrace
499         APPEND
500         PROPERTY COMPILE_DEFINITIONS "TRACE_EGL"
501     )
502
503     set_target_properties (egltrace PROPERTIES
504         # avoid the default "lib" prefix
505         PREFIX ""
506         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
507         # Prevent symbol relocations internal to our wrapper library to be
508         # overwritten by the application.
509         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
510         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
511     )
512
513     target_link_libraries (egltrace
514         common
515         ${ZLIB_LIBRARIES}
516         ${SNAPPY_LIBRARIES}
517         ${CMAKE_THREAD_LIBS_INIT}
518         dl
519     )
520
521     install (TARGETS egltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
522 endif ()
523
524 ##############################################################################
525 # API retracers
526
527 add_custom_command (
528     OUTPUT glretrace_gl.cpp
529     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
530     DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
531 )
532
533 add_custom_command (
534     OUTPUT glstate_params.cpp
535     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
536     DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py
537 )
538
539 set (retrace_sources
540     glretrace_gl.cpp
541     glretrace_cgl.cpp
542     glretrace_glx.cpp
543     glretrace_wgl.cpp
544     glretrace_egl.cpp
545     glretrace_main.cpp
546     glstate.cpp
547     glstate_params.cpp
548     retrace.cpp
549     retrace_stdc.cpp
550     glws.cpp
551 )
552
553 if (WIN32 OR APPLE OR X11_FOUND)
554     add_executable (glretrace
555         ${retrace_sources}
556         ${glws_os}
557         glproc_gl.cpp
558     )
559
560     add_dependencies (glretrace glproc)
561
562     set_property (
563         TARGET glretrace
564         APPEND
565         PROPERTY COMPILE_DEFINITIONS "RETRACE"
566     )
567
568     target_link_libraries (glretrace
569         common
570         ${PNG_LIBRARIES}
571         ${ZLIB_LIBRARIES}
572         ${SNAPPY_LIBRARIES}
573     )
574
575     if (WIN32)
576     else ()
577         if (APPLE)
578             target_link_libraries (glretrace
579                 "-framework Cocoa"
580                 "-framework ApplicationServices" # CGS*
581                 #"-framework OpenGL" # CGL*
582             )
583         else ()
584             target_link_libraries (glretrace ${X11_X11_LIB})
585         endif ()
586
587         target_link_libraries (glretrace
588             # gdb doesn't like when pthreads is loaded through dlopen (which happens
589             # when dlopen'ing libGL), so link pthreads to avoid this issue.  See also
590             # http://stackoverflow.com/questions/2702628/gdb-cannot-find-new-threads-generic-error
591             ${CMAKE_THREAD_LIBS_INIT}
592             dl
593         )
594
595         if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
596             target_link_libraries (glretrace rt)
597         endif ()
598
599     endif ()
600
601     install (TARGETS glretrace RUNTIME DESTINATION bin) 
602 endif ()
603
604 if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE)
605     add_executable (eglretrace
606         ${retrace_sources}
607         glws_egl_xlib.cpp
608         glproc_egl.cpp
609     )
610
611     add_dependencies (eglretrace glproc)
612
613     set_property (
614         TARGET eglretrace
615         APPEND
616         PROPERTY COMPILE_DEFINITIONS "RETRACE"
617         PROPERTY COMPILE_DEFINITIONS "TRACE_EGL"
618     )
619
620     target_link_libraries (eglretrace
621         common
622         ${PNG_LIBRARIES}
623         ${ZLIB_LIBRARIES}
624         ${SNAPPY_LIBRARIES}
625         ${X11_X11_LIB}
626         ${CMAKE_THREAD_LIBS_INIT}
627         dl
628     )
629
630     if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
631         target_link_libraries (eglretrace rt)
632     endif ()
633
634     install (TARGETS eglretrace RUNTIME DESTINATION bin) 
635 endif ()
636
637 ##############################################################################
638 # CLI
639
640 if (ENABLE_CLI)
641     add_subdirectory(cli)
642 endif ()
643
644 ##############################################################################
645 # Scripts (to support the CLI)
646
647 install (
648     PROGRAMS
649         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.py
650         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jsondiff.py
651         ${CMAKE_CURRENT_SOURCE_DIR}/scripts/snapdiff.py
652     DESTINATION ${SCRIPTS_INSTALL_DIR}
653 )
654
655 ##############################################################################
656 # GUI
657
658 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
659     add_subdirectory(gui)
660 endif ()
661
662
663 ##############################################################################
664 # Packaging
665
666 install (
667     FILES
668         BUGS.markdown
669         LICENSE
670         NEWS.markdown
671         README.markdown
672     DESTINATION ${DOC_INSTALL_DIR}
673 )
674
675 set (CPACK_PACKAGE_VERSION_MAJOR "3")
676 set (CPACK_PACKAGE_VERSION_MINOR "0")
677
678 # Use current date in YYYYMMDD format as patch number 
679 execute_process (
680     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
681     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
682 )
683
684 # cpack mistakenly detects Mingw-w64 as win32
685 if (MINGW)
686     if (CMAKE_SIZEOF_VOID_P EQUAL 8)
687         set (CPACK_SYSTEM_NAME win64)
688     endif ()
689 endif ()
690
691 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
692 if (WIN32)
693     set (CPACK_GENERATOR "ZIP")
694 elseif (APPLE)
695     set (CPACK_GENERATOR "DragNDrop")
696 else ()
697     set (CPACK_GENERATOR "TBZ2")
698 endif ()
699
700 include(CPack)