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/msvc)
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 # Bundled dependencies
187 # We always use the bundled zlib, libpng, and snappy sources:
188 # - on Windows to make it easy to deploy the wrappers DLLs
189 # - on unices to prevent symbol collisions when tracing applications that link
190 # against other versions of these libraries
192 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
193 set (ZLIB_LIBRARIES z_bundled)
194 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
196 include_directories (${ZLIB_INCLUDE_DIRS})
198 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
199 set (SNAPPY_LIBRARIES snappy_bundled)
200 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
202 include_directories (${SNAPPY_INCLUDE_DIRS})
204 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
205 set (PNG_DEFINITIONS "")
206 set (PNG_LIBRARIES png_bundled)
208 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
209 include_directories (${PNG_INCLUDE_DIR})
210 add_definitions (${PNG_DEFINITIONS})
213 add_subdirectory (thirdparty/getopt EXCLUDE_FROM_ALL)
214 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
215 set (GETOPT_LIBRARIES getopt_bundled)
219 add_subdirectory (thirdparty/less)
222 # Always use bundled QJSon.
223 # - The packaged versions QJson are very old, and do not support NaN/Infinity.
224 # - To make it easier to build the GUI on Windows and MacOSX, as there are no
227 add_definitions (-DQJSON_EXPORT=)
228 add_subdirectory (thirdparty/qjson EXCLUDE_FROM_ALL)
229 set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
230 set (QJSON_LIBRARY_DIRS)
231 set (QJSON_LIBRARIES qjson_bundled)
232 set (QJSON_FOUND TRUE)
235 # We use bundled headers for all Khronos APIs, to guarantee support for both
236 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
237 # are so intertwined that conditional compilation extremely difficult. This
238 # also avoids missing/inconsistent declarations in system headers.
239 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
242 ##############################################################################
243 # Installation directories
245 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
246 # Debian multiarch support
247 execute_process(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
248 OUTPUT_VARIABLE ARCH_SUBDIR
250 OUTPUT_STRIP_TRAILING_WHITESPACE
255 # On Windows/MacOSX, applications are usually installed on a directory of
257 set (DOC_INSTALL_DIR doc)
258 set (LIB_INSTALL_DIR lib)
259 set (LIB_ARCH_INSTALL_DIR lib)
261 set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
262 set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
264 set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
266 set (LIB_ARCH_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
270 set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
271 set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
273 # Expose the binary/install directories to source
275 # TODO: Use the same directory layout, for both build and install directories,
276 # so that binaries can find each other using just relative paths.
279 -DAPITRACE_BINARY_DIR="${CMAKE_BINARY_DIR}"
280 -DAPITRACE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
281 -DAPITRACE_PROGRAMS_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/bin"
282 -DAPITRACE_SCRIPTS_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${SCRIPTS_INSTALL_DIR}"
283 -DAPITRACE_WRAPPERS_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/${WRAPPER_INSTALL_DIR}"
287 ##############################################################################
288 # Common libraries / utilities
290 include_directories (
291 ${CMAKE_CURRENT_BINARY_DIR}
292 ${CMAKE_CURRENT_SOURCE_DIR}
293 ${CMAKE_CURRENT_SOURCE_DIR}/common
297 set (os os_win32.cpp)
298 set (glws_os glws_wgl.cpp)
300 set (os os_posix.cpp)
302 set (glws_os glws_cocoa.mm)
304 set (glws_os glws_glx.cpp)
308 add_library (common STATIC
309 common/trace_callset.cpp
310 common/trace_dump.cpp
311 common/trace_file.cpp
312 common/trace_file_read.cpp
313 common/trace_file_write.cpp
314 common/trace_file_zlib.cpp
315 common/trace_file_snappy.cpp
316 common/trace_model.cpp
317 common/trace_parser.cpp
318 common/trace_parser_flags.cpp
319 common/trace_writer.cpp
320 common/trace_writer_local.cpp
321 common/trace_writer_model.cpp
322 common/trace_loader.cpp
323 common/trace_resource.cpp
324 common/trace_tools_trace.cpp
325 common/trace_profiler.cpp
330 common/trace_option.cpp
334 set_target_properties (common PROPERTIES
335 COMPILE_DEFINITIONS APITRACE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
336 # Ensure it can be statically linked in shared libraries
337 COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
341 target_link_libraries (common
347 ##############################################################################
350 add_subdirectory (dispatch)
351 add_subdirectory (helpers)
352 add_subdirectory (wrappers)
353 add_subdirectory (retrace)
356 ##############################################################################
360 add_subdirectory (cli)
363 ##############################################################################
364 # Scripts (to support the CLI)
368 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/tracediff.py
369 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jsondiff.py
370 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/snapdiff.py
371 DESTINATION ${SCRIPTS_INSTALL_DIR}
374 ##############################################################################
377 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
378 add_subdirectory(gui)
382 ##############################################################################
391 DESTINATION ${DOC_INSTALL_DIR}
394 set (CPACK_PACKAGE_VERSION_MAJOR "3")
395 set (CPACK_PACKAGE_VERSION_MINOR "0")
397 # Use current date in YYYYMMDD format as patch number
399 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
400 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
403 # cpack mistakenly detects Mingw-w64 as win32
405 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
406 set (CPACK_SYSTEM_NAME win64)
410 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
412 set (CPACK_GENERATOR "ZIP")
414 set (CPACK_GENERATOR "DragNDrop")
416 set (CPACK_GENERATOR "TBZ2")