]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Fix dumb typo.
[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
21 ##############################################################################
22 # Find dependencies
23
24 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
25
26 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
27
28 find_package (PythonInterp REQUIRED)
29 find_package (OpenGL REQUIRED)
30
31 if (ENABLE_GUI)
32     if (NOT (ENABLE_GUI STREQUAL "AUTO"))
33         set (REQUIRE_GUI REQUIRED)
34     endif ()
35     find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
36     find_package (QJSON ${REQUIRE_GUI})
37 endif ()
38
39 if (WIN32)
40     find_package (DirectX)
41 elseif (APPLE)
42 else ()
43     find_package (X11 REQUIRED)
44
45     set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
46     set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
47
48     include_directories (${X11_INCLUDE_DIR})
49 endif ()
50
51
52 ##############################################################################
53 # Set global build options
54
55 include (CheckCXXCompilerFlag)
56
57 if (WIN32)
58     # MSVC & MinGW only define & use APIENTRY
59     add_definitions (-DGLAPIENTRY=__stdcall)
60
61     # http://msdn.microsoft.com/en-us/library/aa383745.aspx
62     add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
63 else (WIN32)
64     CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
65     if (CXX_COMPILER_FLAG_VISIBILITY)
66         add_definitions ("-fvisibility=hidden")
67     endif (CXX_COMPILER_FLAG_VISIBILITY)
68 endif (WIN32)
69
70 if (MSVC)
71     # C99 includes for msvc
72     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msvc)
73
74     # Enable math constants defines
75     add_definitions (-D_USE_MATH_DEFINES)
76
77     # No min/max macros
78     add_definitions (-DNOMINMAX)
79
80     # Adjust warnings
81     add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
82     add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
83     add_definitions (-W4)
84     add_definitions (-wd4063) # not a valid value for switch of enum
85     add_definitions (-wd4127) # conditional expression is constant
86     add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
87     add_definitions (-wd4505) # unreferenced local function has been removed
88     add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
89     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
90     add_definitions (-wd4018) # signed/unsigned mismatch
91     
92     # Use static runtime
93     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
94     foreach (flag_var
95         CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
96         CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
97     )
98         if (${flag_var} MATCHES "/MD")
99             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
100         endif (${flag_var} MATCHES "/MD")
101     endforeach (flag_var)
102 else ()
103     # Adjust warnings
104     add_definitions (-Wall)
105     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
106     add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
107 endif ()
108
109
110 # Put all executables into the same top level build directory, regardless of
111 # which subdirectory they are declared
112 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
113
114
115 ##############################################################################
116 # Bundled dependencies
117 #
118 # We always use the bundled zlib, libpng, and snappy sources:
119 # - on Windows to make it easy to deploy the wrappers DLLs
120 # - on unices to prevent symbol collisions when tracing applications that link
121 # against other versions of these libraries
122
123 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
124 set (ZLIB_LIBRARIES z_bundled)
125 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
126
127 include_directories (${ZLIB_INCLUDE_DIRS})
128 link_libraries (${ZLIB_LIBRARIES})
129
130 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
131 set (SNAPPY_LIBRARIES snappy_bundled)
132 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
133
134 include_directories (${SNAPPY_INCLUDE_DIRS})
135 link_libraries (${SNAPPY_LIBRARIES})
136
137 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
138 set (PNG_DEFINITIONS "")
139 set (PNG_LIBRARIES png_bundled)
140
141 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
142 include_directories (${PNG_INCLUDE_DIR})
143 add_definitions (${PNG_DEFINITIONS})
144 link_libraries (${PNG_LIBRARIES})
145
146 # The Qt website provides binaries for Windows and MacOSX, and they are
147 # automatically found by cmake without any manual intervention.  The situation
148 # for QJSON is substantially different: there are no binaries for QJSON
149 # available, and there is no standard installation directory that is detected
150 # by cmake.
151 #
152 # By bundling the QJSON source, we make it much more easier to build the GUI on
153 # Windows and MacOSX.  But we only use the bundled sources when ENABLE_GUI is
154 # AUTO.
155 if (QT4_FOUND AND NOT QJSON_FOUND AND (ENABLE_GUI STREQUAL "AUTO"))
156     add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
157     set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/qjson)
158     set (QJSON_LIBRARY_DIRS)
159     set (QJSON_LIBRARIES qjson_bundled)
160     set (QJSON_FOUND TRUE)
161 endif ()
162
163 # For glext headers
164 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
165
166
167 ##############################################################################
168 # Common libraries / utilities
169
170 include_directories (
171     ${CMAKE_CURRENT_SOURCE_DIR}
172     ${CMAKE_CURRENT_SOURCE_DIR}/common
173 )
174
175 add_custom_command (
176     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
177     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
178     DEPENDS glproc.py dispatch.py specs/wglapi.py specs/glxapi.py specs/cglapi.py specs/glapi.py specs/gltypes.py specs/stdapi.py
179 )
180
181 if (WIN32)
182     set (os os_win32.cpp)
183     set (glws_os glws_wgl.cpp)
184 else ()
185     set (os os_posix.cpp)
186     if (APPLE)
187         set (glws_os glws_cocoa.mm)
188     else ()
189         set (glws_os glws_glx.cpp)
190     endif ()
191 endif ()
192
193 add_library (common STATIC
194     common/trace_file.cpp
195     common/trace_snappyfile.cpp
196     common/trace_model.cpp
197     common/trace_parser.cpp
198     common/trace_writer.cpp
199     common/trace_local_writer.cpp
200     common/trace_model_writer.cpp
201     common/trace_loader.cpp
202     common/image.cpp
203     common/image_bmp.cpp
204     common/image_pnm.cpp
205     common/image_png.cpp
206     common/${os}
207 )
208
209 set_target_properties (common PROPERTIES
210     # Ensure it can be statically linked in shared libraries
211     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
212 )
213
214 link_libraries (common)
215
216 add_executable (tracedump tracedump.cpp)
217 install (TARGETS tracedump RUNTIME DESTINATION bin) 
218
219
220 ##############################################################################
221 # API tracers
222
223 if (WIN32)
224     if (MINGW)
225         # Silence warnings about @nn suffix mismatch
226         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
227     endif (MINGW)
228
229     # ddraw.dll
230     if (DirectX_D3D_INCLUDE_DIR)
231         include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
232         add_custom_command (
233             OUTPUT ddrawtrace.cpp
234             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
235             DEPENDS ddrawtrace.py trace.py specs/d3d.py specs/d3dtypes.py specs/d3dcaps.py specs/ddraw.py specs/winapi.py specs/stdapi.py
236         )
237         add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
238         set_target_properties (ddraw
239             PROPERTIES PREFIX ""
240             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
241             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
242         )
243         install (TARGETS ddraw LIBRARY DESTINATION wrappers)
244     endif (DirectX_D3D_INCLUDE_DIR)
245
246     # d3d8.dll
247     if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
248         include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
249         add_custom_command (
250             OUTPUT d3d8trace.cpp
251             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
252             DEPENDS d3d8trace.py trace.py specs/d3d8.py specs/d3d8types.py specs/d3d8caps.py specs/winapi.py specs/stdapi.py
253         )
254         add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
255         set_target_properties (d3d8
256             PROPERTIES PREFIX ""
257             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
258             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
259         )
260         install (TARGETS d3d8 LIBRARY DESTINATION wrappers)
261     endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
262
263     # d3d9.dll
264     if (DirectX_D3DX9_INCLUDE_DIR)
265         include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
266         add_custom_command (
267             OUTPUT d3d9trace.cpp
268             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
269             DEPENDS d3d9trace.py trace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
270         )
271         add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
272         set_target_properties (d3d9
273             PROPERTIES PREFIX ""
274             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
275             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
276         )
277         install (TARGETS d3d9 LIBRARY DESTINATION wrappers)
278     endif (DirectX_D3DX9_INCLUDE_DIR)
279
280     # d3d10.dll
281     if (DirectX_D3D10_INCLUDE_DIR)
282         include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
283         add_custom_command (
284             OUTPUT d3d10trace.cpp
285             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
286             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
287         )
288         add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
289         set_target_properties (d3d10
290             PROPERTIES PREFIX ""
291             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
292             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
293         )
294         install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
295     endif (DirectX_D3D10_INCLUDE_DIR)
296
297     # opengl32.dll
298     add_custom_command (
299         OUTPUT wgltrace.cpp
300         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
301         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
302     )
303     add_library (wgltrace MODULE specs/opengl32.def
304         wgltrace.cpp
305         glcaps.cpp
306         ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
307     )
308     set_target_properties (wgltrace PROPERTIES
309         PREFIX ""
310         OUTPUT_NAME opengl32
311         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
312         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
313     )
314     install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
315
316 elseif (APPLE)
317     # OpenGL framework
318     add_custom_command (
319         OUTPUT cgltrace.cpp
320         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
321         DEPENDS cgltrace.py gltrace.py trace.py specs/cglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
322     )
323
324     add_library (cgltrace SHARED
325         cgltrace.cpp
326         glcaps.cpp
327         ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
328     )
329
330     set_target_properties (cgltrace PROPERTIES
331         # OpenGL framework name
332         PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
333         # Specificy the version and reexport GLU symbols
334         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
335         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
336         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
337     )
338
339     target_link_libraries (cgltrace dl)
340
341     install (TARGETS cgltrace LIBRARY DESTINATION wrappers)
342 else ()
343     # libGL.so
344     add_custom_command (
345         OUTPUT glxtrace.cpp
346         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
347         DEPENDS glxtrace.py gltrace.py trace.py specs/glxapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
348     )
349
350     add_library (glxtrace SHARED
351         ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
352         glxtrace.cpp
353         glcaps.cpp
354         glsnapshot.cpp
355     )
356
357     set_target_properties (glxtrace PROPERTIES
358         # avoid the default "lib" prefix
359         PREFIX ""
360     )
361
362     # Prevent symbol relocations internal to our wrapper library to be
363     # overwritten by the application.
364     set_target_properties (glxtrace PROPERTIES
365         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
366     )
367
368     target_link_libraries (glxtrace dl ${X11_X11_LIB})
369
370     install (TARGETS glxtrace LIBRARY DESTINATION lib)
371 endif ()
372
373
374 ##############################################################################
375 # API retracers
376
377 add_custom_command (
378     OUTPUT glretrace_gl.cpp
379     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
380     DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
381 )
382
383 add_custom_command (
384     OUTPUT glstate_params.cpp
385     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
386     DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py
387 )
388
389 include_directories (
390     ${CMAKE_CURRENT_BINARY_DIR}
391     ${OPENGL_INCLUDE_PATH}
392 )
393
394 add_executable (glretrace
395     glretrace_gl.cpp
396     glretrace_cgl.cpp
397     glretrace_glx.cpp
398     glretrace_wgl.cpp
399     glretrace_main.cpp
400     glstate.cpp
401     glstate_params.cpp
402     retrace.cpp
403     glws.cpp
404     ${glws_os}
405     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
406 )
407
408 set_property (
409     TARGET glretrace
410     APPEND
411     PROPERTY COMPILE_DEFINITIONS "RETRACE"
412 )
413
414 target_link_libraries (glretrace
415     common
416 )
417
418 if (WIN32)
419     target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
420 elseif (APPLE)
421     target_link_libraries (glretrace
422         "-framework Cocoa"
423         "-framework ApplicationServices" # CGS*
424         ${OPENGL_gl_LIBRARY} # CGL*
425     )
426 else ()
427     target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
428 endif ()
429
430 install (TARGETS glretrace RUNTIME DESTINATION bin) 
431
432
433 ##############################################################################
434 # GUI
435
436 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
437     add_subdirectory(gui)
438 endif ()
439
440
441 ##############################################################################
442 # Packaging
443
444 install (
445     FILES
446         BUGS.markdown
447         LICENSE
448         NEWS.markdown
449         README.markdown
450         TODO.markdown
451     DESTINATION doc)
452
453 set (CPACK_PACKAGE_VERSION_MAJOR "2")
454 set (CPACK_PACKAGE_VERSION_MINOR "0")
455
456 # Use current date in YYYYMMDD format as patch number 
457 execute_process (
458     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
459     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
460 )
461
462 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
463 if (WIN32)
464     set (CPACK_GENERATOR "ZIP")
465 elseif (APPLE)
466     set (CPACK_GENERATOR "DragNDrop")
467 else ()
468     set (CPACK_GENERATOR "TBZ2")
469 endif ()
470
471 include(CPack)