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