]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
retrace: Implement glxCopySubBufferMESA
[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 # But DONT force clang if we are cross-compiling to Android.
7 if (APPLE AND NOT ANDROID_NDK)
8     set (CMAKE_C_COMPILER "clang")
9     set (CMAKE_CXX_COMPILER "clang++")
10 endif ()
11
12
13 project (apitrace)
14
15
16 ##############################################################################
17 # Options
18
19 # On Mac OS X build fat binaries with i386 and x86_64 architectures by default.
20 if (APPLE AND NOT CMAKE_OSX_ARCHITECTURES)
21     set (CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
22 endif ()
23
24 # We use a cached string variable instead of the standard (boolean) OPTION
25 # command so that we can default to auto-detecting optional depencies, while
26 # still providing a mechanism to force/disable these optional dependencies, as
27 # prescribed in http://www.gentoo.org/proj/en/qa/automagic.xml
28 set (ENABLE_GUI "AUTO" CACHE STRING "Enable Qt GUI.")
29
30 set (ENABLE_CLI true CACHE BOOL "Enable command Line interface.")
31
32 set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
33
34
35 ##############################################################################
36 # Find dependencies
37
38 # Check for compiler TLS support.  We don't use compiler TLS support on Windows
39 # because, even if the compiler supports it, Windows XP does not support TLS on
40 # DLLs.
41 if (NOT WIN32)
42     include (CheckCXXSourceCompiles)
43     check_cxx_source_compiles("__thread int i; int main() { return 0; }" HAVE_COMPILER_TLS)
44     if (HAVE_COMPILER_TLS)
45         add_definitions (-DHAVE_COMPILER_TLS=__thread)
46     else ()
47         message (WARNING "C++ compiler does not support __thread keyword.")
48     endif ()
49 endif ()
50
51 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
52
53 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
54
55 if (ANDROID)
56     set (ENABLE_GUI false)
57 else ()
58     macro (find_host_package)
59         find_package (${ARGN})
60     endmacro()
61 endif ()
62
63 find_host_package (PythonInterp REQUIRED)
64 find_package (Threads)
65
66 if (ENABLE_GUI)
67     if (NOT (ENABLE_GUI STREQUAL "AUTO"))
68         set (REQUIRE_GUI REQUIRED)
69     endif ()
70     find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
71 endif ()
72
73 if (WIN32)
74     find_package (DirectX)
75     set (ENABLE_EGL false)
76 elseif (APPLE)
77     set (ENABLE_EGL false)
78 else ()
79     find_package (X11)
80
81     if (X11_FOUND)
82         include_directories (${X11_INCLUDE_DIR})
83         add_definitions (-DHAVE_X11)
84     else ()
85         # Print a clear message when X11 is not found
86         include (FindPackageMessage)
87         find_package_message (X11 "Could not find X11" "")
88     endif ()
89 endif ()
90
91
92 ##############################################################################
93 # Set global build options
94
95 include (CheckCXXCompilerFlag)
96
97 if (WIN32)
98     # http://msdn.microsoft.com/en-us/library/aa383745.aspx
99     add_definitions (-D_WIN32_WINNT=0x0601 -DWINVER=0x0601)
100 else (WIN32)
101     CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
102     if (CXX_COMPILER_FLAG_VISIBILITY)
103         add_definitions ("-fvisibility=hidden")
104     endif ()
105 endif ()
106
107 if (MSVC)
108     # C99 includes for MSVC
109     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msinttypes)
110
111     # No RTTI required
112     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
113
114     # Enable math constants defines
115     add_definitions (-D_USE_MATH_DEFINES)
116
117     # No min/max macros
118     add_definitions (-DNOMINMAX)
119
120     # Adjust warnings
121     add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
122     add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
123     add_definitions (-W4)
124     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
125     add_definitions (-wd4018) # signed/unsigned mismatch
126     add_definitions (-wd4063) # not a valid value for switch of enum
127     add_definitions (-wd4100) # unreferenced formal parameter
128     add_definitions (-wd4127) # conditional expression is constant
129     add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
130     add_definitions (-wd4505) # unreferenced local function has been removed
131     add_definitions (-wd4512) # assignment operator could not be generated
132     add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
133     
134     # Use static runtime
135     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
136     foreach (flag_var
137         CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
138         CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
139     )
140         if (${flag_var} MATCHES "/MD")
141             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
142         endif ()
143     endforeach (flag_var)
144 else ()
145     # Adjust warnings
146     add_definitions (-Wall)
147     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
148     add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
149
150     # No RTTI required
151     #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
152
153     # Use GDB extensions if available
154     if (CMAKE_COMPILER_IS_GNUC)
155         set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -O0")
156         set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb")
157     endif ()
158     if (CMAKE_COMPILER_IS_GNUCXX)
159         set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0")
160         set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb")
161     endif ()
162
163     # Be nice to Eclipse
164     add_definitions (-fmessage-length=0)
165 endif ()
166
167 if (MINGW)
168     # Avoid depending on MinGW runtime DLLs
169     check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
170     if (HAVE_STATIC_LIBGCC_FLAG)
171         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
172         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
173         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
174     endif ()
175     check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
176     if (HAVE_STATIC_LIBSTDCXX_FLAG)
177         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
178         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
179         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
180     endif ()
181 endif ()
182
183 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
184     # For RTLD_DEFAULT and RTLD_NEXT
185     add_definitions (-D_GNU_SOURCE)
186 endif ()
187
188
189 # Put all executables into the same top level build directory, regardless of
190 # which subdirectory they are declared
191 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
192
193
194 ##############################################################################
195 # Installation directories
196
197 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
198     # Debian multiarch support
199     execute_process(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
200         OUTPUT_VARIABLE ARCH_SUBDIR
201         ERROR_QUIET
202         OUTPUT_STRIP_TRAILING_WHITESPACE
203     )
204     CHECK_INCLUDE_FILES(proc/readproc.h READPROC_H_FOUND)
205     if (READPROC_H_FOUND)
206         add_definitions (-DHAVE_READPROC_H)
207         find_library (proc_LIBRARY NAMES proc procps)
208     endif ()
209 endif()
210
211 if (WIN32 OR APPLE)
212     # On Windows/MacOSX, applications are usually installed on a directory of
213     # their own
214     set (DOC_INSTALL_DIR doc)
215     set (LIB_INSTALL_DIR lib)
216     set (LIB_ARCH_INSTALL_DIR lib)
217 else ()
218     set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
219     set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
220     if (ARCH_SUBDIR)
221         set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
222     else ()
223         set (LIB_ARCH_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
224     endif ()
225 endif ()
226
227 set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
228 set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
229
230
231 ##############################################################################
232 # Bundled dependencies
233 #
234 # We always use the bundled zlib, libpng, and snappy sources:
235 # - on Windows to make it easy to deploy the wrappers DLLs
236 # - on unices to prevent symbol collisions when tracing applications that link
237 # against other versions of these libraries
238
239 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
240 set (ZLIB_LIBRARIES z_bundled)
241 add_subdirectory (thirdparty/zlib)
242
243 include_directories (${ZLIB_INCLUDE_DIRS})
244
245 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
246 set (SNAPPY_LIBRARIES snappy_bundled)
247 add_subdirectory (thirdparty/snappy)
248
249 include_directories (${SNAPPY_INCLUDE_DIRS})
250
251 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
252 set (PNG_DEFINITIONS "")
253 set (PNG_LIBRARIES png_bundled)
254
255 add_subdirectory (thirdparty/libpng)
256
257 if (MSVC)
258     add_subdirectory (thirdparty/getopt)
259     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
260     set (GETOPT_LIBRARIES getopt_bundled)
261 endif ()
262
263 if (WIN32)
264     add_subdirectory (thirdparty/less)
265     add_subdirectory (thirdparty/directxtex)
266 endif ()
267
268 if (CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
269     add_subdirectory (thirdparty/libbacktrace)
270     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libbacktrace)
271     set (LIBBACKTRACE_LIBRARIES dl backtrace)
272     add_definitions (-DHAVE_BACKTRACE=1)
273 endif ()
274
275 # Always use bundled QJSon.
276 # - The packaged versions QJson are very old, and do not support NaN/Infinity.
277 # - To make it easier to build the GUI on Windows and MacOSX, as there are no
278 # binaries at all.
279 if (QT4_FOUND)
280     add_definitions (-DQJSON_EXPORT=)
281     add_subdirectory (thirdparty/qjson)
282     set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
283     set (QJSON_LIBRARY_DIRS)
284     set (QJSON_LIBRARIES qjson_bundled)
285     set (QJSON_FOUND TRUE)
286 endif ()
287
288 # We use bundled headers for all Khronos APIs, to guarantee support for both
289 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
290 # are so intertwined that conditional compilation extremely difficult. This
291 # also avoids missing/inconsistent declarations in system headers.
292 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
293
294
295 ##############################################################################
296 # Common libraries / utilities
297
298 include_directories (
299     ${CMAKE_CURRENT_BINARY_DIR}
300     ${CMAKE_CURRENT_SOURCE_DIR}
301     ${CMAKE_CURRENT_SOURCE_DIR}/common
302 )
303
304 if (WIN32)
305     set (os os_win32.cpp)
306     set (glws_os glws_wgl.cpp)
307 else ()
308     set (os os_posix.cpp)
309     if (APPLE)
310         set (glws_os glws_cocoa.mm)
311     else ()
312         set (glws_os glws_glx.cpp)
313     endif ()
314 endif ()
315
316 add_library (common STATIC
317     common/trace_callset.cpp
318     common/trace_dump.cpp
319     common/trace_fast_callset.cpp
320     common/trace_file.cpp
321     common/trace_file_read.cpp
322     common/trace_file_write.cpp
323     common/trace_file_zlib.cpp
324     common/trace_file_snappy.cpp
325     common/trace_model.cpp
326     common/trace_parser.cpp
327     common/trace_parser_flags.cpp
328     common/trace_writer.cpp
329     common/trace_writer_local.cpp
330     common/trace_writer_model.cpp
331     common/trace_loader.cpp
332     common/trace_profiler.cpp
333     common/trace_option.cpp
334     common/${os}
335     common/os_backtrace.cpp
336 )
337
338 set_target_properties (common PROPERTIES
339     # Ensure it can be statically linked in shared libraries
340     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
341 )
342
343 target_link_libraries (common
344     ${LIBBACKTRACE_LIBRARIES}
345 )
346 if (ANDROID)
347     target_link_libraries (common
348         log
349     )
350 endif ()
351
352
353 ##############################################################################
354 # Sub-directories
355
356 add_subdirectory (dispatch)
357 add_subdirectory (helpers)
358 add_subdirectory (wrappers)
359 add_subdirectory (image)
360 add_subdirectory (retrace)
361
362
363 ##############################################################################
364 # CLI
365
366 if (ENABLE_CLI)
367     if (WIN32)
368         add_subdirectory (inject)
369     endif ()
370     add_subdirectory (cli)
371 endif ()
372
373 ##############################################################################
374 # Scripts (to support the CLI)
375
376 install (
377     PROGRAMS
378         scripts/highlight.py
379         scripts/jsondiff.py
380         scripts/profileshader.py
381         scripts/retracediff.py
382         scripts/snapdiff.py
383         scripts/tracecheck.py
384         scripts/tracediff.py
385         scripts/unpickle.py
386     DESTINATION ${SCRIPTS_INSTALL_DIR}
387 )
388 if (WIN32)
389     install (
390         PROGRAMS scripts/convert.py
391         DESTINATION ${SCRIPTS_INSTALL_DIR}
392     )
393 endif ()
394
395 ##############################################################################
396 # GUI
397
398 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
399     add_subdirectory(gui)
400 endif ()
401
402
403 ##############################################################################
404 # Packaging
405
406 install (
407     FILES
408         BUGS.markdown
409         NEWS.markdown
410         README.markdown
411     DESTINATION ${DOC_INSTALL_DIR}
412 )
413 install (
414     FILES LICENSE
415     DESTINATION ${DOC_INSTALL_DIR}
416     RENAME LICENSE.txt
417 )
418 if (MSVC)
419     install (
420         FILES thirdparty/msinttypes/LICENSE
421         DESTINATION ${DOC_INSTALL_DIR}
422         RENAME LICENSE-msinttypes.txt
423     )
424 endif ()
425
426 set (CPACK_PACKAGE_VERSION_MAJOR "4")
427 set (CPACK_PACKAGE_VERSION_MINOR "0")
428
429 # Use current date in YYYYMMDD format as patch number 
430 execute_process (
431     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
432     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
433 )
434
435 # cpack mistakenly detects Mingw-w64 as win32
436 if (MINGW)
437     if (CMAKE_SIZEOF_VOID_P EQUAL 8)
438         set (CPACK_SYSTEM_NAME win64)
439     endif ()
440 endif ()
441
442 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
443 if (WIN32)
444     set (CPACK_GENERATOR "ZIP")
445 elseif (APPLE)
446     set (CPACK_GENERATOR "DragNDrop")
447 else ()
448     set (CPACK_GENERATOR "TBZ2")
449 endif ()
450
451 include(CPack)