]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2
3
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.
6 if (APPLE)
7     set (CMAKE_C_COMPILER "clang")
8     set (CMAKE_CXX_COMPILER "clang++")
9 endif ()
10
11
12 project (apitrace)
13
14
15 ##############################################################################
16 # Options
17
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)
21 endif ()
22
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.")
28
29 set (ENABLE_CLI true CACHE BOOL "Enable command Line interface.")
30
31 set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
32
33
34 ##############################################################################
35 # Find dependencies
36
37 # Ensure __thread is support
38 if (NOT MSVC)
39     include (CheckCXXSourceCompiles)
40     check_cxx_source_compiles("__thread int i; int main() { return 0; }" HAVE_COMPILER_TLS)
41     if (NOT HAVE_COMPILER_TLS)
42         if (APPLE)
43             message (FATAL_ERROR "C++ compiler does not support __thread keyword. Please install XCode 4.5 or higher.")
44         else (MINGW32)
45             message (FATAL_ERROR "C++ compiler does not support __thread keyword. Please use MinGW g++ version 4.4 or higher")
46         else ()
47             message (FATAL_ERROR "C++ compiler does not support __thread keyword.")
48         endif ()
49     endif ()
50 endif ()
51
52 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
53
54 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
55
56 if (ANDROID)
57     set (ENABLE_GUI false)
58 else ()
59     macro (find_host_package)
60         find_package (${ARGN})
61     endmacro()
62 endif ()
63
64 find_host_package (PythonInterp REQUIRED)
65 find_package (Threads)
66
67 if (ENABLE_GUI)
68     if (NOT (ENABLE_GUI STREQUAL "AUTO"))
69         set (REQUIRE_GUI REQUIRED)
70     endif ()
71     find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
72 endif ()
73
74 if (WIN32)
75     find_package (DirectX)
76     set (ENABLE_EGL false)
77 elseif (APPLE)
78     set (ENABLE_EGL false)
79 else ()
80     find_package (X11)
81
82     if (X11_FOUND)
83         include_directories (${X11_INCLUDE_DIR})
84         add_definitions (-DHAVE_X11)
85     else ()
86         # Print a clear message when X11 is not found
87         include (FindPackageMessage)
88         find_package_message (X11 "Could not find X11" "")
89     endif ()
90 endif ()
91
92
93 ##############################################################################
94 # Set global build options
95
96 include (CheckCXXCompilerFlag)
97
98 if (WIN32)
99     # http://msdn.microsoft.com/en-us/library/aa383745.aspx
100     add_definitions (-D_WIN32_WINNT=0x0601 -DWINVER=0x0601)
101 else (WIN32)
102     CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
103     if (CXX_COMPILER_FLAG_VISIBILITY)
104         add_definitions ("-fvisibility=hidden")
105     endif ()
106 endif ()
107
108 if (MSVC)
109     # C99 includes for MSVC
110     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msinttypes)
111
112     # Enable math constants defines
113     add_definitions (-D_USE_MATH_DEFINES)
114
115     # No min/max macros
116     add_definitions (-DNOMINMAX)
117
118     # Adjust warnings
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)
131     
132     # Use static runtime
133     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
134     foreach (flag_var
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
137     )
138         if (${flag_var} MATCHES "/MD")
139             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
140         endif ()
141     endforeach (flag_var)
142 else ()
143     # Adjust warnings
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
147
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")
152     endif ()
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")
156     endif ()
157
158     # Be nice to Eclipse
159     add_definitions (-fmessage-length=0)
160 endif ()
161
162 if (MINGW)
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")
169     endif ()
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++")
175     endif ()
176 endif ()
177
178
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})
182
183
184 ##############################################################################
185 # Installation directories
186
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
191         ERROR_QUIET
192         OUTPUT_STRIP_TRAILING_WHITESPACE
193     )
194     CHECK_INCLUDE_FILES(proc/readproc.h READPROC_H_FOUND)
195     if (READPROC_H_FOUND)
196         add_definitions (-DHAVE_READPROC_H)
197         find_library (proc_LIBRARY NAMES proc procps)
198     endif ()
199 endif()
200
201 if (WIN32 OR APPLE)
202     # On Windows/MacOSX, applications are usually installed on a directory of
203     # their own
204     set (DOC_INSTALL_DIR doc)
205     set (LIB_INSTALL_DIR lib)
206     set (LIB_ARCH_INSTALL_DIR lib)
207 else ()
208     set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
209     set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
210     if (ARCH_SUBDIR)
211         set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
212     else ()
213         set (LIB_ARCH_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
214     endif ()
215 endif ()
216
217 set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
218 set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
219
220
221 ##############################################################################
222 # Bundled dependencies
223 #
224 # We always use the bundled zlib, libpng, and snappy sources:
225 # - on Windows to make it easy to deploy the wrappers DLLs
226 # - on unices to prevent symbol collisions when tracing applications that link
227 # against other versions of these libraries
228
229 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
230 set (ZLIB_LIBRARIES z_bundled)
231 add_subdirectory (thirdparty/zlib)
232
233 include_directories (${ZLIB_INCLUDE_DIRS})
234
235 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
236 set (SNAPPY_LIBRARIES snappy_bundled)
237 add_subdirectory (thirdparty/snappy)
238
239 include_directories (${SNAPPY_INCLUDE_DIRS})
240
241 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
242 set (PNG_DEFINITIONS "")
243 set (PNG_LIBRARIES png_bundled)
244
245 add_subdirectory (thirdparty/libpng)
246
247 if (MSVC)
248     add_subdirectory (thirdparty/getopt)
249     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
250     set (GETOPT_LIBRARIES getopt_bundled)
251 endif ()
252
253 if (WIN32)
254     add_subdirectory (thirdparty/less)
255     add_subdirectory (thirdparty/directxtex)
256 endif ()
257
258 # Always use bundled QJSon.
259 # - The packaged versions QJson are very old, and do not support NaN/Infinity.
260 # - To make it easier to build the GUI on Windows and MacOSX, as there are no
261 # binaries at all.
262 if (QT4_FOUND)
263     add_definitions (-DQJSON_EXPORT=)
264     add_subdirectory (thirdparty/qjson)
265     set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
266     set (QJSON_LIBRARY_DIRS)
267     set (QJSON_LIBRARIES qjson_bundled)
268     set (QJSON_FOUND TRUE)
269 endif ()
270
271 # We use bundled headers for all Khronos APIs, to guarantee support for both
272 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
273 # are so intertwined that conditional compilation extremely difficult. This
274 # also avoids missing/inconsistent declarations in system headers.
275 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
276
277
278 ##############################################################################
279 # Common libraries / utilities
280
281 include_directories (
282     ${CMAKE_CURRENT_BINARY_DIR}
283     ${CMAKE_CURRENT_SOURCE_DIR}
284     ${CMAKE_CURRENT_SOURCE_DIR}/common
285 )
286
287 if (WIN32)
288     set (os os_win32.cpp)
289     set (glws_os glws_wgl.cpp)
290 else ()
291     set (os os_posix.cpp)
292     if (APPLE)
293         set (glws_os glws_cocoa.mm)
294     else ()
295         set (glws_os glws_glx.cpp)
296     endif ()
297 endif ()
298
299 add_library (common STATIC
300     common/trace_callset.cpp
301     common/trace_dump.cpp
302     common/trace_fast_callset.cpp
303     common/trace_file.cpp
304     common/trace_file_read.cpp
305     common/trace_file_write.cpp
306     common/trace_file_zlib.cpp
307     common/trace_file_snappy.cpp
308     common/trace_model.cpp
309     common/trace_parser.cpp
310     common/trace_parser_flags.cpp
311     common/trace_writer.cpp
312     common/trace_writer_local.cpp
313     common/trace_writer_model.cpp
314     common/trace_loader.cpp
315     common/trace_profiler.cpp
316     common/trace_option.cpp
317     common/${os}
318 )
319
320 set_target_properties (common PROPERTIES
321     # Ensure it can be statically linked in shared libraries
322     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
323 )
324
325 if (ANDROID)
326     target_link_libraries (common
327         log
328     )
329 endif ()
330
331
332 ##############################################################################
333 # Sub-directories
334
335 add_subdirectory (dispatch)
336 add_subdirectory (helpers)
337 add_subdirectory (wrappers)
338 add_subdirectory (image)
339 add_subdirectory (retrace)
340
341
342 ##############################################################################
343 # CLI
344
345 if (ENABLE_CLI)
346     if (WIN32)
347         add_subdirectory (inject)
348     endif ()
349     add_subdirectory (cli)
350 endif ()
351
352 ##############################################################################
353 # Scripts (to support the CLI)
354
355 install (
356     PROGRAMS
357         scripts/highlight.py
358         scripts/jsondiff.py
359         scripts/profileshader.py
360         scripts/retracediff.py
361         scripts/snapdiff.py
362         scripts/tracecheck.py
363         scripts/tracediff.py
364         scripts/unpickle.py
365     DESTINATION ${SCRIPTS_INSTALL_DIR}
366 )
367 if (WIN32)
368     install (
369         PROGRAMS scripts/convert.py
370         DESTINATION ${SCRIPTS_INSTALL_DIR}
371     )
372 endif ()
373
374 ##############################################################################
375 # GUI
376
377 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
378     add_subdirectory(gui)
379 endif ()
380
381
382 ##############################################################################
383 # Packaging
384
385 install (
386     FILES
387         BUGS.markdown
388         NEWS.markdown
389         README.markdown
390     DESTINATION ${DOC_INSTALL_DIR}
391 )
392 install (
393     FILES LICENSE
394     DESTINATION ${DOC_INSTALL_DIR}
395     RENAME LICENSE.txt
396 )
397 if (MSVC)
398     install (
399         FILES thirdparty/msinttypes/LICENSE
400         DESTINATION ${DOC_INSTALL_DIR}
401         RENAME LICENSE-msinttypes.txt
402     )
403 endif ()
404
405 set (CPACK_PACKAGE_VERSION_MAJOR "3")
406 set (CPACK_PACKAGE_VERSION_MINOR "0")
407
408 # Use current date in YYYYMMDD format as patch number 
409 execute_process (
410     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
411     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
412 )
413
414 # cpack mistakenly detects Mingw-w64 as win32
415 if (MINGW)
416     if (CMAKE_SIZEOF_VOID_P EQUAL 8)
417         set (CPACK_SYSTEM_NAME win64)
418     endif ()
419 endif ()
420
421 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
422 if (WIN32)
423     set (CPACK_GENERATOR "ZIP")
424 elseif (APPLE)
425     set (CPACK_GENERATOR "DragNDrop")
426 else ()
427     set (CPACK_GENERATOR "TBZ2")
428 endif ()
429
430 include(CPack)