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 (DirectX)
43 find_package (X11 REQUIRED)
45 set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
46 set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
48 include_directories (${X11_INCLUDE_DIR})
52 ##############################################################################
53 # Set global build options
55 include (CheckCXXCompilerFlag)
58 # MSVC & MinGW only define & use APIENTRY
59 add_definitions (-DGLAPIENTRY=__stdcall)
61 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
62 add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
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)
71 # C99 includes for msvc
72 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msvc)
74 # Enable math constants defines
75 add_definitions (-D_USE_MATH_DEFINES)
78 add_definitions (-DNOMINMAX)
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)
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
93 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
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
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)
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
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})
115 ##############################################################################
116 # Bundled dependencies
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
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)
127 include_directories (${ZLIB_INCLUDE_DIRS})
128 link_libraries (${ZLIB_LIBRARIES})
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)
134 include_directories (${SNAPPY_INCLUDE_DIRS})
135 link_libraries (${SNAPPY_LIBRARIES})
137 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
138 set (PNG_DEFINITIONS "")
139 set (PNG_LIBRARIES png_bundled)
141 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
142 include_directories (${PNG_INCLUDE_DIR})
143 add_definitions (${PNG_DEFINITIONS})
144 link_libraries (${PNG_LIBRARIES})
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
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
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)
164 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
167 ##############################################################################
168 # Common libraries / utilities
170 include_directories (
171 ${CMAKE_CURRENT_SOURCE_DIR}
172 ${CMAKE_CURRENT_SOURCE_DIR}/common
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
182 set (os os_win32.cpp)
183 set (glws_os glws_wgl.cpp)
185 set (os os_posix.cpp)
187 set (glws_os glws_cocoa.mm)
189 set (glws_os glws_glx.cpp)
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
209 set_target_properties (common PROPERTIES
210 # Ensure it can be statically linked in shared libraries
211 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
214 link_libraries (common)
216 add_executable (tracedump tracedump.cpp)
217 install (TARGETS tracedump RUNTIME DESTINATION bin)
220 ##############################################################################
225 # Silence warnings about @nn suffix mismatch
226 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
230 if (DirectX_D3D_INCLUDE_DIR)
231 include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
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
237 add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
238 set_target_properties (ddraw
240 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
241 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
243 install (TARGETS ddraw LIBRARY DESTINATION wrappers)
244 endif (DirectX_D3D_INCLUDE_DIR)
247 if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
248 include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
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
254 add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
255 set_target_properties (d3d8
257 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
258 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
260 install (TARGETS d3d8 LIBRARY DESTINATION wrappers)
261 endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
264 if (DirectX_D3DX9_INCLUDE_DIR)
265 include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
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
271 add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
272 set_target_properties (d3d9
274 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
275 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
277 install (TARGETS d3d9 LIBRARY DESTINATION wrappers)
278 endif (DirectX_D3DX9_INCLUDE_DIR)
281 if (DirectX_D3D10_INCLUDE_DIR)
282 include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
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
288 add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
289 set_target_properties (d3d10
291 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
292 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
294 install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
295 endif (DirectX_D3D10_INCLUDE_DIR)
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
303 add_library (wgltrace MODULE specs/opengl32.def
306 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
308 set_target_properties (wgltrace PROPERTIES
311 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
312 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
314 install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
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
324 add_library (cgltrace SHARED
327 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
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
339 target_link_libraries (cgltrace dl)
341 install (TARGETS cgltrace LIBRARY DESTINATION wrappers)
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
350 add_library (glxtrace SHARED
351 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
357 set_target_properties (glxtrace PROPERTIES
358 # avoid the default "lib" prefix
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"
368 target_link_libraries (glxtrace dl ${X11_X11_LIB})
370 install (TARGETS glxtrace LIBRARY DESTINATION lib)
374 ##############################################################################
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
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
389 include_directories (
390 ${CMAKE_CURRENT_BINARY_DIR}
391 ${OPENGL_INCLUDE_PATH}
394 add_executable (glretrace
405 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
411 PROPERTY COMPILE_DEFINITIONS "RETRACE"
414 target_link_libraries (glretrace
419 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
421 target_link_libraries (glretrace
423 "-framework ApplicationServices" # CGS*
424 ${OPENGL_gl_LIBRARY} # CGL*
427 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
430 install (TARGETS glretrace RUNTIME DESTINATION bin)
433 ##############################################################################
436 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
437 add_subdirectory(gui)
441 ##############################################################################
453 set (CPACK_PACKAGE_VERSION_MAJOR "2")
454 set (CPACK_PACKAGE_VERSION_MINOR "0")
456 # Use current date in YYYYMMDD format as patch number
458 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
459 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
462 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
464 set (CPACK_GENERATOR "ZIP")
466 set (CPACK_GENERATOR "DragNDrop")
468 set (CPACK_GENERATOR "TBZ2")