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=0x0601 -DWINVER=0x0601)
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 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
96 add_definitions (-wd4018) # signed/unsigned mismatch
97 add_definitions (-wd4063) # not a valid value for switch of enum
98 add_definitions (-wd4100) # unreferenced formal parameter
99 add_definitions (-wd4127) # conditional expression is constant
100 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
101 add_definitions (-wd4505) # unreferenced local function has been removed
102 add_definitions (-wd4512) # assignment operator could not be generated
103 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
106 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
108 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
109 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
111 if (${flag_var} MATCHES "/MD")
112 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
114 endforeach (flag_var)
117 add_definitions (-Wall)
118 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
119 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
121 # Use GDB extensions if available
122 if (CMAKE_COMPILER_IS_GNUC)
123 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -O0")
124 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb")
126 if (CMAKE_COMPILER_IS_GNUCXX)
127 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0")
128 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb")
133 # Avoid depending on MinGW runtime DLLs
134 check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
135 if (HAVE_STATIC_LIBGCC_FLAG)
136 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
137 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
138 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
140 check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
141 if (HAVE_STATIC_LIBSTDCXX_FLAG)
142 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
143 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
144 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
149 # Put all executables into the same top level build directory, regardless of
150 # which subdirectory they are declared
151 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
154 ##############################################################################
155 # Bundled dependencies
157 # We always use the bundled zlib, libpng, and snappy sources:
158 # - on Windows to make it easy to deploy the wrappers DLLs
159 # - on unices to prevent symbol collisions when tracing applications that link
160 # against other versions of these libraries
162 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
163 set (ZLIB_LIBRARIES z_bundled)
164 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
166 include_directories (${ZLIB_INCLUDE_DIRS})
168 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
169 set (SNAPPY_LIBRARIES snappy_bundled)
170 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
172 include_directories (${SNAPPY_INCLUDE_DIRS})
174 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
175 set (PNG_DEFINITIONS "")
176 set (PNG_LIBRARIES png_bundled)
178 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
179 include_directories (${PNG_INCLUDE_DIR})
180 add_definitions (${PNG_DEFINITIONS})
183 add_subdirectory (thirdparty/getopt EXCLUDE_FROM_ALL)
184 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
185 set (GETOPT_LIBRARIES getopt_bundled)
189 add_subdirectory (thirdparty/less)
192 # The Qt website provides binaries for Windows and MacOSX, and they are
193 # automatically found by cmake without any manual intervention. The situation
194 # for QJSON is substantially different: there are no binaries for QJSON
195 # available, and there is no standard installation directory that is detected
198 # By bundling the QJSON source, we make it much more easier to build the GUI on
199 # Windows and MacOSX. But we only use the bundled sources when ENABLE_GUI is
201 if (QT4_FOUND AND NOT QJSON_FOUND AND (ENABLE_GUI STREQUAL "AUTO"))
202 add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
203 set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
204 set (QJSON_LIBRARY_DIRS)
205 set (QJSON_LIBRARIES qjson_bundled)
206 set (QJSON_FOUND TRUE)
209 # We use bundled headers for all Khronos APIs, to guarantee support for both
210 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
211 # are so intertwined that conditional compilation extremely difficult. This
212 # also avoids missing/inconsistent declarations in system headers.
213 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
216 ##############################################################################
217 # Installation directories
219 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
220 # Debian multiarch support
221 execute_process(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
222 OUTPUT_VARIABLE ARCH_SUBDIR
224 OUTPUT_STRIP_TRAILING_WHITESPACE
229 # On Windows/MacOSX, applications are usually installed on a directory of
231 set (DOC_INSTALL_DIR doc)
232 set (LIB_INSTALL_DIR lib)
233 set (LIB_ARCH_INSTALL_DIR lib)
235 set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
236 set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
238 set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
240 set (LIB_ARCH_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
244 set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
245 set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
247 # Expose the binary/install directories to source
249 # TODO: Use the same directory layout, for both build and install directories,
250 # so that binaries can find each other using just relative paths.
253 -DAPITRACE_BINARY_DIR="${CMAKE_BINARY_DIR}"
254 -DAPITRACE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
255 -DAPITRACE_SCRIPTS_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${SCRIPTS_INSTALL_DIR}"
256 -DAPITRACE_WRAPPERS_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${WRAPPER_INSTALL_DIR}"
260 ##############################################################################
261 # Common libraries / utilities
263 include_directories (
264 ${CMAKE_CURRENT_BINARY_DIR}
265 ${CMAKE_CURRENT_SOURCE_DIR}
266 ${CMAKE_CURRENT_SOURCE_DIR}/common
270 set (os os_win32.cpp)
271 set (glws_os glws_wgl.cpp)
273 set (os os_posix.cpp)
275 set (glws_os glws_cocoa.mm)
277 set (glws_os glws_glx.cpp)
281 add_library (common STATIC
282 common/trace_callset.cpp
283 common/trace_dump.cpp
284 common/trace_file.cpp
285 common/trace_file_read.cpp
286 common/trace_file_write.cpp
287 common/trace_file_zlib.cpp
288 common/trace_file_snappy.cpp
289 common/trace_model.cpp
290 common/trace_parser.cpp
291 common/trace_parser_flags.cpp
292 common/trace_writer.cpp
293 common/trace_writer_local.cpp
294 common/trace_writer_model.cpp
295 common/trace_loader.cpp
296 common/trace_resource.cpp
297 common/trace_tools_trace.cpp
298 common/trace_profiler.cpp
306 set_target_properties (common PROPERTIES
307 COMPILE_DEFINITIONS APITRACE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
308 # Ensure it can be statically linked in shared libraries
309 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
313 target_link_libraries (common log)
317 ##############################################################################
320 add_subdirectory (dispatch)
321 add_subdirectory (wrappers)
322 add_subdirectory (retrace)
325 ##############################################################################
329 add_subdirectory(cli)
332 ##############################################################################
333 # Scripts (to support the CLI)
337 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.py
338 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jsondiff.py
339 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/snapdiff.py
340 DESTINATION ${SCRIPTS_INSTALL_DIR}
343 ##############################################################################
346 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
347 add_subdirectory(gui)
351 ##############################################################################
360 DESTINATION ${DOC_INSTALL_DIR}
363 set (CPACK_PACKAGE_VERSION_MAJOR "3")
364 set (CPACK_PACKAGE_VERSION_MINOR "0")
366 # Use current date in YYYYMMDD format as patch number
368 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
369 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
372 # cpack mistakenly detects Mingw-w64 as win32
374 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
375 set (CPACK_SYSTEM_NAME win64)
379 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
381 set (CPACK_GENERATOR "ZIP")
383 set (CPACK_GENERATOR "DragNDrop")
385 set (CPACK_GENERATOR "TBZ2")