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 glws_wgl.cpp)
202 set (os os_posix.cpp)
203 set (glws glws_glx.cpp)
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_C_FLAGS}"
227 link_libraries (common)
229 add_executable (tracedump tracedump.cpp)
230 install (TARGETS tracedump RUNTIME DESTINATION bin)
233 ##############################################################################
238 if (DirectX_D3D_INCLUDE_DIR)
239 include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
241 OUTPUT ddrawtrace.cpp
242 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
243 DEPENDS ddrawtrace.py trace.py specs/d3d.py specs/d3dtypes.py specs/d3dcaps.py specs/ddraw.py specs/winapi.py specs/stdapi.py
245 add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
246 set_target_properties (ddraw
248 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
249 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
251 install (TARGETS ddraw LIBRARY DESTINATION wrappers)
252 endif (DirectX_D3D_INCLUDE_DIR)
255 if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
256 include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
259 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
260 DEPENDS d3d8trace.py trace.py specs/d3d8.py specs/d3d8types.py specs/d3d8caps.py specs/winapi.py specs/stdapi.py
262 add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
263 set_target_properties (d3d8
265 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
266 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
268 install (TARGETS d3d8 LIBRARY DESTINATION wrappers)
269 endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
272 if (DirectX_D3DX9_INCLUDE_DIR)
273 include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
276 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
277 DEPENDS d3d9trace.py trace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
279 add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
280 set_target_properties (d3d9
282 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
283 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
285 install (TARGETS d3d9 LIBRARY DESTINATION wrappers)
286 endif (DirectX_D3DX9_INCLUDE_DIR)
289 if (DirectX_D3D10_INCLUDE_DIR)
290 include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
292 OUTPUT d3d10trace.cpp
293 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
294 DEPENDS d3d10trace.py trace.py specs/d3d10misc.py specs/d3d10.py specs/dxgi.py specs/winapi.py specs/stdapi.py
296 add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
297 set_target_properties (d3d10
299 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
300 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
302 install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
303 endif (DirectX_D3D10_INCLUDE_DIR)
308 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
309 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
311 add_library (wgltrace MODULE specs/opengl32.def
314 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
316 set_target_properties (wgltrace PROPERTIES
319 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
320 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
323 set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup")
325 install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
331 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
332 DEPENDS cgltrace.py gltrace.py trace.py specs/cglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
335 add_library (cgltrace SHARED
338 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
341 set_target_properties (cgltrace PROPERTIES
342 # OpenGL framework name
343 PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
344 # Specificy the version and reexport GLU symbols
345 LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
346 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
347 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
350 target_link_libraries (cgltrace dl)
352 install (TARGETS cgltrace LIBRARY DESTINATION wrappers)
357 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
358 DEPENDS glxtrace.py gltrace.py trace.py specs/glxapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
361 add_library (glxtrace SHARED
362 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
368 set_target_properties (glxtrace PROPERTIES
369 # avoid the default "lib" prefix
373 # Prevent symbol relocations internal to our wrapper library to be
374 # overwritten by the application.
375 set_target_properties (glxtrace PROPERTIES
376 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
379 target_link_libraries (glxtrace dl ${X11_X11_LIB})
381 install (TARGETS glxtrace LIBRARY DESTINATION lib)
385 ##############################################################################
389 OUTPUT glretrace_gl.cpp
390 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
391 DEPENDS glretrace.py retrace.py codegen.py specs/glapi.py specs/gltypes.py specs/stdapi.py
395 OUTPUT glstate_params.cpp
396 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
397 DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py
400 include_directories (
401 ${CMAKE_CURRENT_BINARY_DIR}
402 ${OPENGL_INCLUDE_PATH}
405 add_executable (glretrace
415 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
421 PROPERTY COMPILE_DEFINITIONS "RETRACE"
424 target_link_libraries (glretrace
429 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
431 # XXX: We use GLX on MacOSX, which is in a separate library.
432 target_link_libraries (glretrace
435 "-framework ApplicationServices" # CGS*
436 ${OPENGL_gl_LIBRARY} # CGL*
439 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
442 install (TARGETS glretrace RUNTIME DESTINATION bin)
445 ##############################################################################
448 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
449 add_subdirectory(gui)
453 ##############################################################################
465 set (CPACK_PACKAGE_VERSION_MAJOR "1")
466 set (CPACK_PACKAGE_VERSION_MINOR "0")
468 # Use current date in YYYYMMDD format as patch number
470 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
471 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
474 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
476 set (CPACK_GENERATOR "ZIP")
478 set (CPACK_GENERATOR "DragNDrop")
480 set (CPACK_GENERATOR "TBZ2")