1 cmake_minimum_required (VERSION 2.8)
6 ##############################################################################
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)
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.")
21 ##############################################################################
24 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
26 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
28 find_package (PythonInterp REQUIRED)
29 find_package (OpenGL REQUIRED)
32 if (NOT (ENABLE_GUI STREQUAL "AUTO"))
33 set (REQUIRE_GUI REQUIRED)
35 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
36 find_package (QJSON ${REQUIRE_GUI})
40 find_package (X11 REQUIRED)
42 # On Mac OS X, GLX is provided as a separate OpenGL implementation, different
43 # from the standard OpenGL framework which provides support for native Mac OS X
46 find_path (X11_GL_INCLUDE_PATH GL/glx.h ${X11_INC_SEARCH_PATH})
47 if (NOT X11_GL_INCLUDE_PATH)
48 message (SEND_ERROR "Could not find GL/glx.h")
49 endif (NOT X11_GL_INCLUDE_PATH)
50 set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_GL_INCLUDE_PATH})
52 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
54 message (SEND_ERROR "Could not find libGL.dylib")
55 endif (NOT X11_GL_LIB)
57 set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
58 set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
61 include_directories (${X11_INCLUDE_DIR})
65 find_package (DirectX)
69 ##############################################################################
70 # Set global build options
72 include (CheckCXXCompilerFlag)
75 # MSVC & MinGW only define & use APIENTRY
76 add_definitions (-DGLAPIENTRY=__stdcall)
78 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
79 add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
81 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
82 if (CXX_COMPILER_FLAG_VISIBILITY)
83 add_definitions ("-fvisibility=hidden")
84 endif (CXX_COMPILER_FLAG_VISIBILITY)
88 # C99 includes for msvc
89 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msvc)
91 # Enable math constants defines
92 add_definitions (-D_USE_MATH_DEFINES)
95 add_definitions (-DNOMINMAX)
98 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
99 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
100 add_definitions (-W4)
101 add_definitions (-wd4063) # not a valid value for switch of enum
102 add_definitions (-wd4127) # conditional expression is constant
103 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
104 add_definitions (-wd4505) # unreferenced local function has been removed
105 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
106 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
107 add_definitions (-wd4018) # signed/unsigned mismatch
110 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
112 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
113 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
115 if (${flag_var} MATCHES "/MD")
116 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
117 endif (${flag_var} MATCHES "/MD")
118 endforeach (flag_var)
121 add_definitions (-Wall)
122 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
123 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
127 # Put all executables into the same top level build directory, regardless of
128 # which subdirectory they are declared
129 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
132 ##############################################################################
133 # Bundled dependencies
135 # We always use the bundled zlib, libpng, and snappy sources:
136 # - on Windows to make it easy to deploy the wrappers DLLs
137 # - on unices to prevent symbol collisions when tracing applications that link
138 # against other versions of these libraries
140 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
141 set (ZLIB_LIBRARIES z_bundled)
142 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
144 include_directories (${ZLIB_INCLUDE_DIRS})
145 link_libraries (${ZLIB_LIBRARIES})
147 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
148 set (SNAPPY_LIBRARIES snappy_bundled)
149 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
151 include_directories (${SNAPPY_INCLUDE_DIRS})
152 link_libraries (${SNAPPY_LIBRARIES})
154 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
155 set (PNG_DEFINITIONS "")
156 set (PNG_LIBRARIES png_bundled)
158 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
159 include_directories (${PNG_INCLUDE_DIR})
160 add_definitions (${PNG_DEFINITIONS})
161 link_libraries (${PNG_LIBRARIES})
163 # The Qt website provides binaries for Windows and MacOSX, and they are
164 # automatically found by cmake without any manual intervention. The situation
165 # for QJSON is substantially different: there are no binaries for QJSON
166 # available, and there is no standard installation directory that is detected
169 # By bundling the QJSON source, we make it much more easier to build the GUI on
170 # Windows and MacOSX. But we only use the bundled sources when ENABLE_GUI is
172 if (QT4_FOUND AND NOT QJSON_FOUND AND (ENABLE_GUI STREQUAL "AUTO"))
173 add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
174 set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/qjson)
175 set (QJSON_LIBRARY_DIRS)
176 set (QJSON_LIBRARIES qjson_bundled)
177 set (QJSON_FOUND TRUE)
181 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
184 ##############################################################################
185 # Common libraries / utilities
187 include_directories (
188 ${CMAKE_CURRENT_SOURCE_DIR}
189 ${CMAKE_CURRENT_SOURCE_DIR}/common
193 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
194 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
195 DEPENDS glproc.py dispatch.py specs/wglapi.py specs/glxapi.py specs/cglapi.py specs/glapi.py specs/gltypes.py specs/stdapi.py
199 set (os os_win32.cpp)
200 set (glws_os glws_wgl.cpp)
202 set (os os_posix.cpp)
203 set (glws_os glws_glx.cpp)
206 add_library (common STATIC
207 common/trace_file.cpp
208 common/trace_snappyfile.cpp
209 common/trace_model.cpp
210 common/trace_parser.cpp
211 common/trace_writer.cpp
212 common/trace_local_writer.cpp
213 common/trace_model_writer.cpp
214 common/trace_loader.cpp
222 set_target_properties (common PROPERTIES
223 # Ensure it can be statically linked in shared libraries
224 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
227 link_libraries (common)
229 add_executable (tracedump tracedump.cpp)
230 install (TARGETS tracedump RUNTIME DESTINATION bin)
233 ##############################################################################
238 # Silence warnings about @nn suffix mismatch
239 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
243 if (DirectX_D3D_INCLUDE_DIR)
244 include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
246 OUTPUT ddrawtrace.cpp
247 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
248 DEPENDS ddrawtrace.py trace.py specs/d3d.py specs/d3dtypes.py specs/d3dcaps.py specs/ddraw.py specs/winapi.py specs/stdapi.py
250 add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
251 set_target_properties (ddraw
253 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
254 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
256 install (TARGETS ddraw LIBRARY DESTINATION wrappers)
257 endif (DirectX_D3D_INCLUDE_DIR)
260 if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
261 include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
264 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
265 DEPENDS d3d8trace.py trace.py specs/d3d8.py specs/d3d8types.py specs/d3d8caps.py specs/winapi.py specs/stdapi.py
267 add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
268 set_target_properties (d3d8
270 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
271 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
273 install (TARGETS d3d8 LIBRARY DESTINATION wrappers)
274 endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
277 if (DirectX_D3DX9_INCLUDE_DIR)
278 include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
281 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
282 DEPENDS d3d9trace.py trace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
284 add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
285 set_target_properties (d3d9
287 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
288 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
290 install (TARGETS d3d9 LIBRARY DESTINATION wrappers)
291 endif (DirectX_D3DX9_INCLUDE_DIR)
294 if (DirectX_D3D10_INCLUDE_DIR)
295 include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
297 OUTPUT d3d10trace.cpp
298 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
299 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
301 add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
302 set_target_properties (d3d10
304 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
305 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
307 install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
308 endif (DirectX_D3D10_INCLUDE_DIR)
311 if (DirectX_D2D1_INCLUDE_DIR)
312 include_directories (SYSTEM ${DirectX_D2D1_INCLUDE_DIR})
315 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d2d1trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d2d1trace.cpp
316 DEPENDS d2d1trace.py trace.py specs/d2d1.py specs/d2d1.py specs/d2dbasetypes.py specs/d2derr.py specs/dwrite.py specs/dcommon.py specs/dxgi.py specs/dxgitype.py specs/dxgiformat.py specs/winapi.py specs/stdapi.py
318 add_library (d2d1 MODULE specs/d2d1.def d2d1trace.cpp)
319 set_target_properties (d2d1
321 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
322 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
324 install (TARGETS d2d1 LIBRARY DESTINATION wrappers)
325 endif (DirectX_D2D1_INCLUDE_DIR)
330 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
331 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
333 add_library (wgltrace MODULE specs/opengl32.def
336 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
338 set_target_properties (wgltrace PROPERTIES
341 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
342 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
344 install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
350 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
351 DEPENDS cgltrace.py gltrace.py trace.py specs/cglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
354 add_library (cgltrace SHARED
357 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
360 set_target_properties (cgltrace PROPERTIES
361 # OpenGL framework name
362 PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
363 # Specificy the version and reexport GLU symbols
364 LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
365 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
366 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
369 target_link_libraries (cgltrace dl)
371 install (TARGETS cgltrace LIBRARY DESTINATION wrappers)
376 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
377 DEPENDS glxtrace.py gltrace.py trace.py specs/glxapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
380 add_library (glxtrace SHARED
381 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
387 set_target_properties (glxtrace PROPERTIES
388 # avoid the default "lib" prefix
392 # Prevent symbol relocations internal to our wrapper library to be
393 # overwritten by the application.
394 set_target_properties (glxtrace PROPERTIES
395 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
398 target_link_libraries (glxtrace dl ${X11_X11_LIB})
400 install (TARGETS glxtrace LIBRARY DESTINATION lib)
404 ##############################################################################
408 OUTPUT glretrace_gl.cpp
409 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
410 DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
414 OUTPUT glstate_params.cpp
415 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
416 DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py
419 include_directories (
420 ${CMAKE_CURRENT_BINARY_DIR}
421 ${OPENGL_INCLUDE_PATH}
424 add_executable (glretrace
435 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
441 PROPERTY COMPILE_DEFINITIONS "RETRACE"
444 target_link_libraries (glretrace
449 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
451 # XXX: We use GLX on MacOSX, which is in a separate library.
452 target_link_libraries (glretrace
455 "-framework ApplicationServices" # CGS*
456 ${OPENGL_gl_LIBRARY} # CGL*
459 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
462 install (TARGETS glretrace RUNTIME DESTINATION bin)
465 ##############################################################################
468 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
469 add_subdirectory(gui)
473 ##############################################################################
485 set (CPACK_PACKAGE_VERSION_MAJOR "2")
486 set (CPACK_PACKAGE_VERSION_MINOR "0")
488 # Use current date in YYYYMMDD format as patch number
490 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
491 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
494 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
496 set (CPACK_GENERATOR "ZIP")
498 set (CPACK_GENERATOR "DragNDrop")
500 set (CPACK_GENERATOR "TBZ2")