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.")
20 set (ENABLE_CLI true CACHE BOOL "Enable command Line interface.")
22 set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
25 ##############################################################################
28 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
30 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
33 set (ENABLE_GUI false)
35 macro (find_host_package)
36 find_package (${ARGN})
40 find_host_package (PythonInterp REQUIRED)
41 find_package (Threads)
44 if (NOT (ENABLE_GUI STREQUAL "AUTO"))
45 set (REQUIRE_GUI REQUIRED)
47 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
48 find_package (QJSON ${REQUIRE_GUI})
52 find_package (DirectX)
53 set (ENABLE_EGL false)
55 set (ENABLE_EGL false)
60 include_directories (${X11_INCLUDE_DIR})
61 add_definitions (-DHAVE_X11)
66 ##############################################################################
67 # Set global build options
69 include (CheckCXXCompilerFlag)
72 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
73 add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
75 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
76 if (CXX_COMPILER_FLAG_VISIBILITY)
77 add_definitions ("-fvisibility=hidden")
82 # C99 includes for msvc
83 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msvc)
85 # Enable math constants defines
86 add_definitions (-D_USE_MATH_DEFINES)
89 add_definitions (-DNOMINMAX)
92 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
93 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
95 add_definitions (-wd4063) # not a valid value for switch of enum
96 add_definitions (-wd4127) # conditional expression is constant
97 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
98 add_definitions (-wd4505) # unreferenced local function has been removed
99 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
100 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
101 add_definitions (-wd4018) # signed/unsigned mismatch
104 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
106 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
107 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
109 if (${flag_var} MATCHES "/MD")
110 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
112 endforeach (flag_var)
115 add_definitions (-Wall)
116 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
117 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
121 # Avoid depending on MinGW runtime DLLs
122 check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
123 if (HAVE_STATIC_LIBGCC_FLAG)
124 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
125 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
126 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
128 check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
129 if (HAVE_STATIC_LIBSTDCXX_FLAG)
130 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
131 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
132 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
137 # Put all executables into the same top level build directory, regardless of
138 # which subdirectory they are declared
139 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
142 ##############################################################################
143 # Bundled dependencies
145 # We always use the bundled zlib, libpng, and snappy sources:
146 # - on Windows to make it easy to deploy the wrappers DLLs
147 # - on unices to prevent symbol collisions when tracing applications that link
148 # against other versions of these libraries
150 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
151 set (ZLIB_LIBRARIES z_bundled)
152 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
154 include_directories (${ZLIB_INCLUDE_DIRS})
156 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
157 set (SNAPPY_LIBRARIES snappy_bundled)
158 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
160 include_directories (${SNAPPY_INCLUDE_DIRS})
162 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
163 set (PNG_DEFINITIONS "")
164 set (PNG_LIBRARIES png_bundled)
166 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
167 include_directories (${PNG_INCLUDE_DIR})
168 add_definitions (${PNG_DEFINITIONS})
171 add_subdirectory (thirdparty/getopt EXCLUDE_FROM_ALL)
172 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
173 set (GETOPT_LIBRARIES getopt_bundled)
177 add_subdirectory (thirdparty/less)
180 # The Qt website provides binaries for Windows and MacOSX, and they are
181 # automatically found by cmake without any manual intervention. The situation
182 # for QJSON is substantially different: there are no binaries for QJSON
183 # available, and there is no standard installation directory that is detected
186 # By bundling the QJSON source, we make it much more easier to build the GUI on
187 # Windows and MacOSX. But we only use the bundled sources when ENABLE_GUI is
189 if (QT4_FOUND AND NOT QJSON_FOUND AND (ENABLE_GUI STREQUAL "AUTO"))
190 add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
191 set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
192 set (QJSON_LIBRARY_DIRS)
193 set (QJSON_LIBRARIES qjson_bundled)
194 set (QJSON_FOUND TRUE)
197 # We use bundled headers for all Khronos APIs, to guarantee support for both
198 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
199 # are so intertwined that conditional compilation extremely difficult. This
200 # also avoids missing/inconsistent declarations in system headers.
201 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
203 ##############################################################################
204 # Installation directories
207 # On Windows/MacOSX, applications are usually installed on a directory of
209 set (DOC_INSTALL_DIR doc)
210 set (LIB_INSTALL_DIR lib)
212 set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
213 set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
216 set(SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
217 set(WRAPPER_INSTALL_DIR ${LIB_INSTALL_DIR}/wrappers)
219 # Expose the binary/install directories to source
221 # TODO: Use the same directory layout, for both build and install directories,
222 # so that binaries can find each other using just relative paths.
225 -DAPITRACE_BINARY_DIR="${CMAKE_BINARY_DIR}"
226 -DAPITRACE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
227 -DAPITRACE_WRAPPER_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${WRAPPER_INSTALL_DIR}"
231 ##############################################################################
232 # Common libraries / utilities
234 include_directories (
235 ${CMAKE_CURRENT_BINARY_DIR}
236 ${CMAKE_CURRENT_SOURCE_DIR}
237 ${CMAKE_CURRENT_SOURCE_DIR}/common
241 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
242 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
243 DEPENDS glproc.py dispatch.py specs/wglapi.py specs/glxapi.py specs/cglapi.py specs/eglapi.py specs/glesapi.py specs/glapi.py specs/gltypes.py specs/stdapi.py
246 # Wrap glproc.hpp as a target to prevent the command from being executed
247 # multiple times simulatenously, when the targets that depend on it are built
249 add_custom_target (glproc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
252 set (os os_win32.cpp)
253 set (glws_os glws_wgl.cpp)
255 set (os os_posix.cpp)
257 set (glws_os glws_cocoa.mm)
259 set (glws_os glws_glx.cpp)
263 add_library (common STATIC
264 common/trace_callset.cpp
265 common/trace_dump.cpp
266 common/trace_file.cpp
267 common/trace_file_read.cpp
268 common/trace_file_write.cpp
269 common/trace_file_zlib.cpp
270 common/trace_file_snappy.cpp
271 common/trace_model.cpp
272 common/trace_parser.cpp
273 common/trace_parser_flags.cpp
274 common/trace_writer.cpp
275 common/trace_writer_local.cpp
276 common/trace_writer_model.cpp
277 common/trace_loader.cpp
278 common/trace_resource.cpp
279 common/trace_tools_trace.cpp
287 set_target_properties (common PROPERTIES
288 COMPILE_DEFINITIONS APITRACE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
289 # Ensure it can be statically linked in shared libraries
290 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
294 target_link_libraries (common log)
298 ##############################################################################
301 add_subdirectory (wrappers)
304 ##############################################################################
308 OUTPUT glretrace_gl.cpp
309 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
310 DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
314 OUTPUT glstate_params.cpp
315 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate_params.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
316 DEPENDS glstate_params.py specs/glparams.py specs/gltypes.py specs/stdapi.py
319 add_library (retrace_common
335 add_dependencies (retrace_common glproc)
338 TARGET retrace_common
340 PROPERTY COMPILE_DEFINITIONS "RETRACE"
343 if (WIN32 OR APPLE OR X11_FOUND)
344 add_executable (glretrace
349 add_dependencies (glretrace glproc)
354 PROPERTY COMPILE_DEFINITIONS "RETRACE"
357 target_link_libraries (glretrace
368 target_link_libraries (glretrace
370 "-framework ApplicationServices" # CGS*
371 #"-framework OpenGL" # CGL*
374 target_link_libraries (glretrace ${X11_X11_LIB})
377 target_link_libraries (glretrace
378 # gdb doesn't like when pthreads is loaded through dlopen (which happens
379 # when dlopen'ing libGL), so link pthreads to avoid this issue. See also
380 # http://stackoverflow.com/questions/2702628/gdb-cannot-find-new-threads-generic-error
381 ${CMAKE_THREAD_LIBS_INIT}
385 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
386 target_link_libraries (glretrace rt)
391 install (TARGETS glretrace RUNTIME DESTINATION bin)
394 if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE)
395 add_executable (eglretrace
400 add_dependencies (eglretrace glproc)
405 PROPERTY COMPILE_DEFINITIONS "RETRACE"
408 target_link_libraries (eglretrace
415 ${CMAKE_THREAD_LIBS_INIT}
419 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
420 target_link_libraries (eglretrace rt)
423 install (TARGETS eglretrace RUNTIME DESTINATION bin)
426 if (WIN32 AND DirectX_D3DX9_FOUND)
428 OUTPUT d3dretrace_d3d9.cpp
429 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp
430 DEPENDS d3dretrace.py retrace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
433 include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
434 add_executable (d3dretrace
440 target_link_libraries (d3dretrace
444 ${DirectX_D3D9_LIBRARY}
448 ##############################################################################
452 add_subdirectory(cli)
455 ##############################################################################
456 # Scripts (to support the CLI)
460 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.py
461 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jsondiff.py
462 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/snapdiff.py
463 DESTINATION ${SCRIPTS_INSTALL_DIR}
466 ##############################################################################
469 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
470 add_subdirectory(gui)
474 ##############################################################################
483 DESTINATION ${DOC_INSTALL_DIR}
486 set (CPACK_PACKAGE_VERSION_MAJOR "3")
487 set (CPACK_PACKAGE_VERSION_MINOR "0")
489 # Use current date in YYYYMMDD format as patch number
491 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
492 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
495 # cpack mistakenly detects Mingw-w64 as win32
497 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
498 set (CPACK_SYSTEM_NAME win64)
502 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
504 set (CPACK_GENERATOR "ZIP")
506 set (CPACK_GENERATOR "DragNDrop")
508 set (CPACK_GENERATOR "TBZ2")