1 cmake_minimum_required (VERSION 2.8)
4 # Use clang on MacOSX. gcc doesn't support __thread key, and Apple has
5 # abandoned it for clang. This must be done before the project is defined.
7 set (CMAKE_C_COMPILER "clang")
8 set (CMAKE_CXX_COMPILER "clang++")
15 ##############################################################################
18 # On Mac OS X build fat binaries with i386 and x86_64 architectures by default.
19 if (APPLE AND NOT CMAKE_OSX_ARCHITECTURES)
20 set (CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
23 # We use a cached string variable instead of the standard (boolean) OPTION
24 # command so that we can default to auto-detecting optional depencies, while
25 # still providing a mechanism to force/disable these optional dependencies, as
26 # prescribed in http://www.gentoo.org/proj/en/qa/automagic.xml
27 set (ENABLE_GUI "AUTO" CACHE STRING "Enable Qt GUI.")
29 set (ENABLE_CLI true CACHE BOOL "Enable command Line interface.")
31 set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
34 ##############################################################################
37 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
39 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
42 set (ENABLE_GUI false)
44 macro (find_host_package)
45 find_package (${ARGN})
49 find_host_package (PythonInterp REQUIRED)
50 find_package (Threads)
53 if (NOT (ENABLE_GUI STREQUAL "AUTO"))
54 set (REQUIRE_GUI REQUIRED)
56 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
60 find_package (DirectX)
61 set (ENABLE_EGL false)
63 set (ENABLE_EGL false)
68 include_directories (${X11_INCLUDE_DIR})
69 add_definitions (-DHAVE_X11)
71 # Print a clear message when X11 is not found
72 include (FindPackageMessage)
73 find_package_message (X11 "Could not find X11" "")
78 ##############################################################################
79 # Set global build options
81 include (CheckCXXCompilerFlag)
84 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
85 add_definitions (-D_WIN32_WINNT=0x0601 -DWINVER=0x0601)
87 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
88 if (CXX_COMPILER_FLAG_VISIBILITY)
89 add_definitions ("-fvisibility=hidden")
94 # C99 includes for MSVC
95 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msinttypes)
97 # Enable math constants defines
98 add_definitions (-D_USE_MATH_DEFINES)
101 add_definitions (-DNOMINMAX)
104 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
105 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
106 add_definitions (-W4)
107 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
108 add_definitions (-wd4018) # signed/unsigned mismatch
109 add_definitions (-wd4063) # not a valid value for switch of enum
110 add_definitions (-wd4100) # unreferenced formal parameter
111 add_definitions (-wd4127) # conditional expression is constant
112 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
113 add_definitions (-wd4505) # unreferenced local function has been removed
114 add_definitions (-wd4512) # assignment operator could not be generated
115 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
118 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
120 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
121 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
123 if (${flag_var} MATCHES "/MD")
124 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
126 endforeach (flag_var)
129 add_definitions (-Wall)
130 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
131 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
133 # Use GDB extensions if available
134 if (CMAKE_COMPILER_IS_GNUC)
135 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -O0")
136 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb")
138 if (CMAKE_COMPILER_IS_GNUCXX)
139 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0")
140 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb")
144 add_definitions (-fmessage-length=0)
148 # Avoid depending on MinGW runtime DLLs
149 check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
150 if (HAVE_STATIC_LIBGCC_FLAG)
151 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
152 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
153 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
155 check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
156 if (HAVE_STATIC_LIBSTDCXX_FLAG)
157 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
158 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
159 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
164 # Put all executables into the same top level build directory, regardless of
165 # which subdirectory they are declared
166 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
169 ##############################################################################
170 # Installation directories
172 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
173 # Debian multiarch support
174 execute_process(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
175 OUTPUT_VARIABLE ARCH_SUBDIR
177 OUTPUT_STRIP_TRAILING_WHITESPACE
179 CHECK_INCLUDE_FILES(proc/readproc.h READPROC_H_FOUND)
180 if (READPROC_H_FOUND)
181 add_definitions (-DHAVE_READPROC_H)
182 find_library (proc_LIBRARY NAMES proc procps)
187 # On Windows/MacOSX, applications are usually installed on a directory of
189 set (DOC_INSTALL_DIR doc)
190 set (LIB_INSTALL_DIR lib)
191 set (LIB_ARCH_INSTALL_DIR lib)
193 set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
194 set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
196 set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
198 set (LIB_ARCH_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
202 set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
203 set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
206 ##############################################################################
207 # Bundled dependencies
209 # We always use the bundled zlib, libpng, and snappy sources:
210 # - on Windows to make it easy to deploy the wrappers DLLs
211 # - on unices to prevent symbol collisions when tracing applications that link
212 # against other versions of these libraries
214 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
215 set (ZLIB_LIBRARIES z_bundled)
216 add_subdirectory (thirdparty/zlib)
218 include_directories (${ZLIB_INCLUDE_DIRS})
220 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
221 set (SNAPPY_LIBRARIES snappy_bundled)
222 add_subdirectory (thirdparty/snappy)
224 include_directories (${SNAPPY_INCLUDE_DIRS})
226 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
227 set (PNG_DEFINITIONS "")
228 set (PNG_LIBRARIES png_bundled)
230 add_subdirectory (thirdparty/libpng)
233 add_subdirectory (thirdparty/getopt)
234 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
235 set (GETOPT_LIBRARIES getopt_bundled)
239 add_subdirectory (thirdparty/less)
240 add_subdirectory (thirdparty/directxtex)
243 # Always use bundled QJSon.
244 # - The packaged versions QJson are very old, and do not support NaN/Infinity.
245 # - To make it easier to build the GUI on Windows and MacOSX, as there are no
248 add_definitions (-DQJSON_EXPORT=)
249 add_subdirectory (thirdparty/qjson)
250 set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
251 set (QJSON_LIBRARY_DIRS)
252 set (QJSON_LIBRARIES qjson_bundled)
253 set (QJSON_FOUND TRUE)
256 # We use bundled headers for all Khronos APIs, to guarantee support for both
257 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
258 # are so intertwined that conditional compilation extremely difficult. This
259 # also avoids missing/inconsistent declarations in system headers.
260 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
263 ##############################################################################
264 # Common libraries / utilities
266 include_directories (
267 ${CMAKE_CURRENT_BINARY_DIR}
268 ${CMAKE_CURRENT_SOURCE_DIR}
269 ${CMAKE_CURRENT_SOURCE_DIR}/common
273 set (os os_win32.cpp)
274 set (glws_os glws_wgl.cpp)
276 set (os os_posix.cpp)
278 set (glws_os glws_cocoa.mm)
280 set (glws_os glws_glx.cpp)
284 add_library (common STATIC
285 common/trace_callset.cpp
286 common/trace_dump.cpp
287 common/trace_file.cpp
288 common/trace_file_read.cpp
289 common/trace_file_write.cpp
290 common/trace_file_zlib.cpp
291 common/trace_file_snappy.cpp
292 common/trace_model.cpp
293 common/trace_parser.cpp
294 common/trace_parser_flags.cpp
295 common/trace_writer.cpp
296 common/trace_writer_local.cpp
297 common/trace_writer_model.cpp
298 common/trace_loader.cpp
299 common/trace_profiler.cpp
300 common/trace_option.cpp
304 set_target_properties (common PROPERTIES
305 # Ensure it can be statically linked in shared libraries
306 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
310 target_link_libraries (common
316 ##############################################################################
319 add_subdirectory (dispatch)
320 add_subdirectory (helpers)
321 add_subdirectory (wrappers)
322 add_subdirectory (image)
323 add_subdirectory (retrace)
326 ##############################################################################
331 add_subdirectory (inject)
333 add_subdirectory (cli)
336 ##############################################################################
337 # Scripts (to support the CLI)
343 scripts/profileshader.py
344 scripts/retracediff.py
346 scripts/tracecheck.py
349 DESTINATION ${SCRIPTS_INSTALL_DIR}
353 PROGRAMS scripts/convert.py
354 DESTINATION ${SCRIPTS_INSTALL_DIR}
358 ##############################################################################
361 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
362 add_subdirectory(gui)
366 ##############################################################################
374 DESTINATION ${DOC_INSTALL_DIR}
378 DESTINATION ${DOC_INSTALL_DIR}
383 FILES thirdparty/msinttypes/LICENSE
384 DESTINATION ${DOC_INSTALL_DIR}
385 RENAME LICENSE-msinttypes.txt
389 set (CPACK_PACKAGE_VERSION_MAJOR "3")
390 set (CPACK_PACKAGE_VERSION_MINOR "0")
392 # Use current date in YYYYMMDD format as patch number
394 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
395 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
398 # cpack mistakenly detects Mingw-w64 as win32
400 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
401 set (CPACK_SYSTEM_NAME win64)
405 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
407 set (CPACK_GENERATOR "ZIP")
409 set (CPACK_GENERATOR "DragNDrop")
411 set (CPACK_GENERATOR "TBZ2")