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 # Avoid depending on MinGW runtime DLLs
111 check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
112 if (HAVE_STATIC_LIBGCC_FLAG)
113 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
114 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
115 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
117 check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
118 if (HAVE_STATIC_LIBSTDCXX_FLAG)
119 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
120 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
121 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
126 # Put all executables into the same top level build directory, regardless of
127 # which subdirectory they are declared
128 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
131 ##############################################################################
132 # Bundled dependencies
134 # We always use the bundled zlib, libpng, and snappy sources:
135 # - on Windows to make it easy to deploy the wrappers DLLs
136 # - on unices to prevent symbol collisions when tracing applications that link
137 # against other versions of these libraries
139 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
140 set (ZLIB_LIBRARIES z_bundled)
141 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
143 include_directories (${ZLIB_INCLUDE_DIRS})
144 link_libraries (${ZLIB_LIBRARIES})
146 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
147 set (SNAPPY_LIBRARIES snappy_bundled)
148 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
150 include_directories (${SNAPPY_INCLUDE_DIRS})
151 link_libraries (${SNAPPY_LIBRARIES})
153 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
154 set (PNG_DEFINITIONS "")
155 set (PNG_LIBRARIES png_bundled)
157 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
158 include_directories (${PNG_INCLUDE_DIR})
159 add_definitions (${PNG_DEFINITIONS})
160 link_libraries (${PNG_LIBRARIES})
162 # The Qt website provides binaries for Windows and MacOSX, and they are
163 # automatically found by cmake without any manual intervention. The situation
164 # for QJSON is substantially different: there are no binaries for QJSON
165 # available, and there is no standard installation directory that is detected
168 # By bundling the QJSON source, we make it much more easier to build the GUI on
169 # Windows and MacOSX. But we only use the bundled sources when ENABLE_GUI is
171 if (QT4_FOUND AND NOT QJSON_FOUND AND (ENABLE_GUI STREQUAL "AUTO"))
172 add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
173 set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/qjson)
174 set (QJSON_LIBRARY_DIRS)
175 set (QJSON_LIBRARIES qjson_bundled)
176 set (QJSON_FOUND TRUE)
180 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
183 ##############################################################################
184 # Installation directories
187 # On Windows/MacOSX, applications are usually installed on a directory of
189 set (DOC_INSTALL_DIR doc)
191 set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
195 # MacOSX uses fat binaries, so no need to have per-architecture wrapper
197 set (WRAPPER_INSTALL_DIR lib/apitrace)
199 set (WRAPPER_INSTALL_DIR lib/apitrace/${CMAKE_SYSTEM_PROCESSOR})
202 # Expose the binary/install directories to source
204 # TODO: Use the same directory layout, for both build and install directories,
205 # so that binaries can find each other using just relative paths.
208 -DAPITRACE_BINARY_DIR="${CMAKE_BINARY_DIR}"
209 -DAPITRACE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
210 -DAPITRACE_WRAPPER_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${WRAPPER_INSTALL_DIR}"
214 ##############################################################################
215 # Common libraries / utilities
217 include_directories (
218 ${CMAKE_CURRENT_SOURCE_DIR}
219 ${CMAKE_CURRENT_SOURCE_DIR}/common
223 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
224 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
225 DEPENDS glproc.py dispatch.py specs/wglapi.py specs/glxapi.py specs/cglapi.py specs/glapi.py specs/gltypes.py specs/stdapi.py
229 set (os os_win32.cpp)
230 set (glws_os glws_wgl.cpp)
232 set (os os_posix.cpp)
234 set (glws_os glws_cocoa.mm)
236 set (glws_os glws_glx.cpp)
240 add_library (common STATIC
241 common/trace_file.cpp
242 common/trace_file_zlib.cpp
243 common/trace_file_snappy.cpp
244 common/trace_model.cpp
245 common/trace_parser.cpp
246 common/trace_writer.cpp
247 common/trace_writer_local.cpp
248 common/trace_writer_model.cpp
249 common/trace_loader.cpp
257 set_target_properties (common PROPERTIES
258 # Ensure it can be statically linked in shared libraries
259 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
262 link_libraries (common)
265 ##############################################################################
270 # Silence warnings about @nn suffix mismatch
271 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
275 if (DirectX_D3D_INCLUDE_DIR)
276 include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
278 OUTPUT ddrawtrace.cpp
279 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ddrawtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/ddrawtrace.cpp
280 DEPENDS ddrawtrace.py trace.py specs/d3d.py specs/d3dtypes.py specs/d3dcaps.py specs/ddraw.py specs/winapi.py specs/stdapi.py
282 add_library (ddraw MODULE specs/ddraw.def ddrawtrace.cpp)
283 set_target_properties (ddraw
285 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
286 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
288 install (TARGETS ddraw LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
289 endif (DirectX_D3D_INCLUDE_DIR)
292 if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
293 include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
296 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8trace.cpp
297 DEPENDS d3d8trace.py trace.py specs/d3d8.py specs/d3d8types.py specs/d3d8caps.py specs/winapi.py specs/stdapi.py
299 add_library (d3d8 MODULE specs/d3d8.def d3d8trace.cpp d3dshader.cpp)
300 set_target_properties (d3d8
302 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
303 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
305 install (TARGETS d3d8 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
306 endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
309 if (DirectX_D3DX9_INCLUDE_DIR)
310 include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
313 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9trace.cpp
314 DEPENDS d3d9trace.py trace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
316 add_library (d3d9 MODULE specs/d3d9.def d3d9trace.cpp d3dshader.cpp)
317 set_target_properties (d3d9
319 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
320 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
322 install (TARGETS d3d9 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
323 endif (DirectX_D3DX9_INCLUDE_DIR)
326 if (DirectX_D3D10_INCLUDE_DIR)
327 include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
329 OUTPUT d3d10trace.cpp
330 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
331 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
333 add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
334 set_target_properties (d3d10
336 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
337 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
339 install (TARGETS d3d10 LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
340 endif (DirectX_D3D10_INCLUDE_DIR)
345 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
346 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
348 add_library (wgltrace MODULE specs/opengl32.def
351 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
353 set_target_properties (wgltrace PROPERTIES
356 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
357 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
359 install (TARGETS wgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
365 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
366 DEPENDS cgltrace.py gltrace.py trace.py specs/cglapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
369 add_library (cgltrace SHARED
372 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
375 set_target_properties (cgltrace PROPERTIES
376 # OpenGL framework name
377 PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
378 # Specificy the version and reexport GLU symbols
379 LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
380 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
381 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
384 target_link_libraries (cgltrace dl)
386 install (TARGETS cgltrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
391 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
392 DEPENDS glxtrace.py gltrace.py trace.py specs/glxapi.py specs/glapi.py specs/glparams.py specs/gltypes.py specs/stdapi.py
395 add_library (glxtrace SHARED
396 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
402 set_target_properties (glxtrace PROPERTIES
403 # avoid the default "lib" prefix
407 # Prevent symbol relocations internal to our wrapper library to be
408 # overwritten by the application.
409 set_target_properties (glxtrace PROPERTIES
410 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
413 target_link_libraries (glxtrace dl ${X11_X11_LIB})
415 install (TARGETS glxtrace LIBRARY DESTINATION ${WRAPPER_INSTALL_DIR})
419 ##############################################################################
423 OUTPUT glretrace_gl.cpp
424 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
425 DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
429 OUTPUT glstate_params.cpp
430 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
431 DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py
434 include_directories (
435 ${CMAKE_CURRENT_BINARY_DIR}
436 ${OPENGL_INCLUDE_PATH}
439 add_executable (glretrace
451 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
457 PROPERTY COMPILE_DEFINITIONS "RETRACE"
460 target_link_libraries (glretrace
465 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
467 target_link_libraries (glretrace
469 "-framework ApplicationServices" # CGS*
470 ${OPENGL_gl_LIBRARY} # CGL*
473 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
476 install (TARGETS glretrace RUNTIME DESTINATION bin)
478 ##############################################################################
481 add_subdirectory(cli)
483 ##############################################################################
486 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
487 add_subdirectory(gui)
491 ##############################################################################
501 DESTINATION ${DOC_INSTALL_DIR}
504 set (CPACK_PACKAGE_VERSION_MAJOR "2")
505 set (CPACK_PACKAGE_VERSION_MINOR "0")
507 # Use current date in YYYYMMDD format as patch number
509 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
510 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
513 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
515 set (CPACK_GENERATOR "ZIP")
517 set (CPACK_GENERATOR "DragNDrop")
519 set (CPACK_GENERATOR "TBZ2")