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 # Ensure __thread is support
39 include (CheckCXXSourceCompiles)
40 check_cxx_source_compiles("__thread int i; int main() { return 0; }" HAVE_COMPILER_TLS)
41 if (NOT HAVE_COMPILER_TLS)
43 message (FATAL_ERROR "C++ compiler does not support __thread keyword. Please install XCode 4.5 or higher.")
45 message (FATAL_ERROR "C++ compiler does not support __thread keyword. Please use MinGW g++ version 4.4 or higher")
47 message (FATAL_ERROR "C++ compiler does not support __thread keyword.")
52 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
54 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
57 set (ENABLE_GUI false)
59 macro (find_host_package)
60 find_package (${ARGN})
64 find_host_package (PythonInterp REQUIRED)
65 find_package (Threads)
68 if (NOT (ENABLE_GUI STREQUAL "AUTO"))
69 set (REQUIRE_GUI REQUIRED)
71 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
75 find_package (DirectX)
76 set (ENABLE_EGL false)
78 set (ENABLE_EGL false)
83 include_directories (${X11_INCLUDE_DIR})
84 add_definitions (-DHAVE_X11)
86 # Print a clear message when X11 is not found
87 include (FindPackageMessage)
88 find_package_message (X11 "Could not find X11" "")
93 ##############################################################################
94 # Set global build options
96 include (CheckCXXCompilerFlag)
99 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
100 add_definitions (-D_WIN32_WINNT=0x0601 -DWINVER=0x0601)
102 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
103 if (CXX_COMPILER_FLAG_VISIBILITY)
104 add_definitions ("-fvisibility=hidden")
109 # C99 includes for MSVC
110 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msinttypes)
112 # Enable math constants defines
113 add_definitions (-D_USE_MATH_DEFINES)
116 add_definitions (-DNOMINMAX)
119 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
120 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
121 add_definitions (-W4)
122 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
123 add_definitions (-wd4018) # signed/unsigned mismatch
124 add_definitions (-wd4063) # not a valid value for switch of enum
125 add_definitions (-wd4100) # unreferenced formal parameter
126 add_definitions (-wd4127) # conditional expression is constant
127 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
128 add_definitions (-wd4505) # unreferenced local function has been removed
129 add_definitions (-wd4512) # assignment operator could not be generated
130 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
133 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
135 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
136 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
138 if (${flag_var} MATCHES "/MD")
139 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
141 endforeach (flag_var)
144 add_definitions (-Wall)
145 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
146 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
148 # Use GDB extensions if available
149 if (CMAKE_COMPILER_IS_GNUC)
150 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -O0")
151 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb")
153 if (CMAKE_COMPILER_IS_GNUCXX)
154 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0")
155 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb")
159 add_definitions (-fmessage-length=0)
163 # Avoid depending on MinGW runtime DLLs
164 check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
165 if (HAVE_STATIC_LIBGCC_FLAG)
166 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
167 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
168 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
170 check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
171 if (HAVE_STATIC_LIBSTDCXX_FLAG)
172 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
173 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
174 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
179 # Put all executables into the same top level build directory, regardless of
180 # which subdirectory they are declared
181 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
184 ##############################################################################
185 # Installation directories
187 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
188 # Debian multiarch support
189 execute_process(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
190 OUTPUT_VARIABLE ARCH_SUBDIR
192 OUTPUT_STRIP_TRAILING_WHITESPACE
194 CHECK_INCLUDE_FILES(proc/readproc.h READPROC_H_FOUND)
195 if (READPROC_H_FOUND)
196 add_definitions (-DHAVE_READPROC_H)
201 # On Windows/MacOSX, applications are usually installed on a directory of
203 set (DOC_INSTALL_DIR doc)
204 set (LIB_INSTALL_DIR lib)
205 set (LIB_ARCH_INSTALL_DIR lib)
207 set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
208 set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
210 set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
212 set (LIB_ARCH_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
216 set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
217 set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
220 ##############################################################################
221 # Bundled dependencies
223 # We always use the bundled zlib, libpng, and snappy sources:
224 # - on Windows to make it easy to deploy the wrappers DLLs
225 # - on unices to prevent symbol collisions when tracing applications that link
226 # against other versions of these libraries
228 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
229 set (ZLIB_LIBRARIES z_bundled)
230 add_subdirectory (thirdparty/zlib)
232 include_directories (${ZLIB_INCLUDE_DIRS})
234 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
235 set (SNAPPY_LIBRARIES snappy_bundled)
236 add_subdirectory (thirdparty/snappy)
238 include_directories (${SNAPPY_INCLUDE_DIRS})
240 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
241 set (PNG_DEFINITIONS "")
242 set (PNG_LIBRARIES png_bundled)
244 add_subdirectory (thirdparty/libpng)
247 add_subdirectory (thirdparty/getopt)
248 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
249 set (GETOPT_LIBRARIES getopt_bundled)
253 add_subdirectory (thirdparty/less)
254 add_subdirectory (thirdparty/directxtex)
257 # Always use bundled QJSon.
258 # - The packaged versions QJson are very old, and do not support NaN/Infinity.
259 # - To make it easier to build the GUI on Windows and MacOSX, as there are no
262 add_definitions (-DQJSON_EXPORT=)
263 add_subdirectory (thirdparty/qjson)
264 set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
265 set (QJSON_LIBRARY_DIRS)
266 set (QJSON_LIBRARIES qjson_bundled)
267 set (QJSON_FOUND TRUE)
270 # We use bundled headers for all Khronos APIs, to guarantee support for both
271 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
272 # are so intertwined that conditional compilation extremely difficult. This
273 # also avoids missing/inconsistent declarations in system headers.
274 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
277 ##############################################################################
278 # Common libraries / utilities
280 include_directories (
281 ${CMAKE_CURRENT_BINARY_DIR}
282 ${CMAKE_CURRENT_SOURCE_DIR}
283 ${CMAKE_CURRENT_SOURCE_DIR}/common
287 set (os os_win32.cpp)
288 set (glws_os glws_wgl.cpp)
290 set (os os_posix.cpp)
292 set (glws_os glws_cocoa.mm)
294 set (glws_os glws_glx.cpp)
298 add_library (common STATIC
299 common/trace_callset.cpp
300 common/trace_dump.cpp
301 common/trace_file.cpp
302 common/trace_file_read.cpp
303 common/trace_file_write.cpp
304 common/trace_file_zlib.cpp
305 common/trace_file_snappy.cpp
306 common/trace_model.cpp
307 common/trace_parser.cpp
308 common/trace_parser_flags.cpp
309 common/trace_writer.cpp
310 common/trace_writer_local.cpp
311 common/trace_writer_model.cpp
312 common/trace_loader.cpp
313 common/trace_profiler.cpp
314 common/trace_option.cpp
318 set_target_properties (common PROPERTIES
319 COMPILE_DEFINITIONS APITRACE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
320 # Ensure it can be statically linked in shared libraries
321 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
325 target_link_libraries (common
331 ##############################################################################
334 add_subdirectory (dispatch)
335 add_subdirectory (helpers)
336 add_subdirectory (wrappers)
337 add_subdirectory (image)
338 add_subdirectory (retrace)
341 ##############################################################################
346 add_subdirectory (inject)
348 add_subdirectory (cli)
351 ##############################################################################
352 # Scripts (to support the CLI)
358 scripts/profileshader.py
359 scripts/retracediff.py
361 scripts/tracecheck.py
364 DESTINATION ${SCRIPTS_INSTALL_DIR}
368 PROGRAMS scripts/convert.py
369 DESTINATION ${SCRIPTS_INSTALL_DIR}
373 ##############################################################################
376 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
377 add_subdirectory(gui)
381 ##############################################################################
389 DESTINATION ${DOC_INSTALL_DIR}
393 DESTINATION ${DOC_INSTALL_DIR}
398 FILES thirdparty/msinttypes/LICENSE
399 DESTINATION ${DOC_INSTALL_DIR}
400 RENAME LICENSE-msinttypes.txt
404 set (CPACK_PACKAGE_VERSION_MAJOR "3")
405 set (CPACK_PACKAGE_VERSION_MINOR "0")
407 # Use current date in YYYYMMDD format as patch number
409 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
410 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
413 # cpack mistakenly detects Mingw-w64 as win32
415 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
416 set (CPACK_SYSTEM_NAME win64)
420 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
422 set (CPACK_GENERATOR "ZIP")
424 set (CPACK_GENERATOR "DragNDrop")
426 set (CPACK_GENERATOR "TBZ2")