]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
attrib_list support for WGL function wglCreateContextAttribsARB.
[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     # Enable math constants defines
112     add_definitions (-D_USE_MATH_DEFINES)
113
114     # No min/max macros
115     add_definitions (-DNOMINMAX)
116
117     # Adjust warnings
118     add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
119     add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
120     add_definitions (-W4)
121     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
122     add_definitions (-wd4018) # signed/unsigned mismatch
123     add_definitions (-wd4063) # not a valid value for switch of enum
124     add_definitions (-wd4100) # unreferenced formal parameter
125     add_definitions (-wd4127) # conditional expression is constant
126     add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
127     add_definitions (-wd4505) # unreferenced local function has been removed
128     add_definitions (-wd4512) # assignment operator could not be generated
129     add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
130     
131     # Use static runtime
132     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
133     foreach (flag_var
134         CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
135         CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
136     )
137         if (${flag_var} MATCHES "/MD")
138             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
139         endif ()
140     endforeach (flag_var)
141 else ()
142     # Adjust warnings
143     add_definitions (-Wall)
144     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
145     add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
146
147     # Use GDB extensions if available
148     if (CMAKE_COMPILER_IS_GNUC)
149         set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -O0")
150         set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb")
151     endif ()
152     if (CMAKE_COMPILER_IS_GNUCXX)
153         set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0")
154         set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb")
155     endif ()
156
157     # Be nice to Eclipse
158     add_definitions (-fmessage-length=0)
159 endif ()
160
161 if (MINGW)
162     # Avoid depending on MinGW runtime DLLs
163     check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
164     if (HAVE_STATIC_LIBGCC_FLAG)
165         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
166         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
167         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
168     endif ()
169     check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
170     if (HAVE_STATIC_LIBSTDCXX_FLAG)
171         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
172         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
173         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
174     endif ()
175 endif ()
176
177 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
178     # For RTLD_DEFAULT and RTLD_NEXT
179     add_definitions (-D_GNU_SOURCE)
180 endif ()
181
182
183 # Put all executables into the same top level build directory, regardless of
184 # which subdirectory they are declared
185 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
186
187
188 ##############################################################################
189 # Installation directories
190
191 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
192     # Debian multiarch support
193     execute_process(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
194         OUTPUT_VARIABLE ARCH_SUBDIR
195         ERROR_QUIET
196         OUTPUT_STRIP_TRAILING_WHITESPACE
197     )
198     CHECK_INCLUDE_FILES(proc/readproc.h READPROC_H_FOUND)
199     if (READPROC_H_FOUND)
200         add_definitions (-DHAVE_READPROC_H)
201         find_library (proc_LIBRARY NAMES proc procps)
202     endif ()
203 endif()
204
205 if (WIN32 OR APPLE)
206     # On Windows/MacOSX, applications are usually installed on a directory of
207     # their own
208     set (DOC_INSTALL_DIR doc)
209     set (LIB_INSTALL_DIR lib)
210     set (LIB_ARCH_INSTALL_DIR lib)
211 else ()
212     set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
213     set (LIB_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
214     if (ARCH_SUBDIR)
215         set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
216     else ()
217         set (LIB_ARCH_INSTALL_DIR lib/${CMAKE_PROJECT_NAME})
218     endif ()
219 endif ()
220
221 set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
222 set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
223
224
225 ##############################################################################
226 # Bundled dependencies
227 #
228 # We always use the bundled zlib, libpng, and snappy sources:
229 # - on Windows to make it easy to deploy the wrappers DLLs
230 # - on unices to prevent symbol collisions when tracing applications that link
231 # against other versions of these libraries
232
233 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
234 set (ZLIB_LIBRARIES z_bundled)
235 add_subdirectory (thirdparty/zlib)
236
237 include_directories (${ZLIB_INCLUDE_DIRS})
238
239 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
240 set (SNAPPY_LIBRARIES snappy_bundled)
241 add_subdirectory (thirdparty/snappy)
242
243 include_directories (${SNAPPY_INCLUDE_DIRS})
244
245 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
246 set (PNG_DEFINITIONS "")
247 set (PNG_LIBRARIES png_bundled)
248
249 add_subdirectory (thirdparty/libpng)
250
251 if (MSVC)
252     add_subdirectory (thirdparty/getopt)
253     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
254     set (GETOPT_LIBRARIES getopt_bundled)
255 endif ()
256
257 if (WIN32)
258     add_subdirectory (thirdparty/less)
259     add_subdirectory (thirdparty/directxtex)
260 endif ()
261
262 if (CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
263     add_subdirectory (thirdparty/libbacktrace)
264     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libbacktrace)
265     set (LIBBACKTRACE_LIBRARIES backtrace)
266 endif ()
267
268 # Always use bundled QJSon.
269 # - The packaged versions QJson are very old, and do not support NaN/Infinity.
270 # - To make it easier to build the GUI on Windows and MacOSX, as there are no
271 # binaries at all.
272 if (QT4_FOUND)
273     add_definitions (-DQJSON_EXPORT=)
274     add_subdirectory (thirdparty/qjson)
275     set (QJSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
276     set (QJSON_LIBRARY_DIRS)
277     set (QJSON_LIBRARIES qjson_bundled)
278     set (QJSON_FOUND TRUE)
279 endif ()
280
281 # We use bundled headers for all Khronos APIs, to guarantee support for both
282 # OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
283 # are so intertwined that conditional compilation extremely difficult. This
284 # also avoids missing/inconsistent declarations in system headers.
285 include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
286
287
288 ##############################################################################
289 # Common libraries / utilities
290
291 include_directories (
292     ${CMAKE_CURRENT_BINARY_DIR}
293     ${CMAKE_CURRENT_SOURCE_DIR}
294     ${CMAKE_CURRENT_SOURCE_DIR}/common
295 )
296
297 if (WIN32)
298     set (os os_win32.cpp)
299     set (glws_os glws_wgl.cpp)
300 else ()
301     set (os os_posix.cpp)
302     if (APPLE)
303         set (glws_os glws_cocoa.mm)
304     else ()
305         set (glws_os glws_glx.cpp)
306     endif ()
307 endif ()
308
309 add_library (common STATIC
310     common/trace_callset.cpp
311     common/trace_dump.cpp
312     common/trace_fast_callset.cpp
313     common/trace_file.cpp
314     common/trace_file_read.cpp
315     common/trace_file_write.cpp
316     common/trace_file_zlib.cpp
317     common/trace_file_snappy.cpp
318     common/trace_model.cpp
319     common/trace_parser.cpp
320     common/trace_parser_flags.cpp
321     common/trace_writer.cpp
322     common/trace_writer_local.cpp
323     common/trace_writer_model.cpp
324     common/trace_loader.cpp
325     common/trace_profiler.cpp
326     common/trace_option.cpp
327     common/${os}
328     common/trace_backtrace.cpp
329 )
330
331 set_target_properties (common PROPERTIES
332     # Ensure it can be statically linked in shared libraries
333     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
334 )
335
336 if (ANDROID)
337     target_link_libraries (common
338         log
339     )
340 endif ()
341
342
343 ##############################################################################
344 # Sub-directories
345
346 add_subdirectory (dispatch)
347 add_subdirectory (helpers)
348 add_subdirectory (wrappers)
349 add_subdirectory (image)
350 add_subdirectory (retrace)
351
352
353 ##############################################################################
354 # CLI
355
356 if (ENABLE_CLI)
357     if (WIN32)
358         add_subdirectory (inject)
359     endif ()
360     add_subdirectory (cli)
361 endif ()
362
363 ##############################################################################
364 # Scripts (to support the CLI)
365
366 install (
367     PROGRAMS
368         scripts/highlight.py
369         scripts/jsondiff.py
370         scripts/profileshader.py
371         scripts/retracediff.py
372         scripts/snapdiff.py
373         scripts/tracecheck.py
374         scripts/tracediff.py
375         scripts/unpickle.py
376     DESTINATION ${SCRIPTS_INSTALL_DIR}
377 )
378 if (WIN32)
379     install (
380         PROGRAMS scripts/convert.py
381         DESTINATION ${SCRIPTS_INSTALL_DIR}
382     )
383 endif ()
384
385 ##############################################################################
386 # GUI
387
388 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
389     add_subdirectory(gui)
390 endif ()
391
392
393 ##############################################################################
394 # Packaging
395
396 install (
397     FILES
398         BUGS.markdown
399         NEWS.markdown
400         README.markdown
401     DESTINATION ${DOC_INSTALL_DIR}
402 )
403 install (
404     FILES LICENSE
405     DESTINATION ${DOC_INSTALL_DIR}
406     RENAME LICENSE.txt
407 )
408 if (MSVC)
409     install (
410         FILES thirdparty/msinttypes/LICENSE
411         DESTINATION ${DOC_INSTALL_DIR}
412         RENAME LICENSE-msinttypes.txt
413     )
414 endif ()
415
416 set (CPACK_PACKAGE_VERSION_MAJOR "4")
417 set (CPACK_PACKAGE_VERSION_MINOR "0")
418
419 # Use current date in YYYYMMDD format as patch number 
420 execute_process (
421     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
422     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
423 )
424
425 # cpack mistakenly detects Mingw-w64 as win32
426 if (MINGW)
427     if (CMAKE_SIZEOF_VOID_P EQUAL 8)
428         set (CPACK_SYSTEM_NAME win64)
429     endif ()
430 endif ()
431
432 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
433 if (WIN32)
434     set (CPACK_GENERATOR "ZIP")
435 elseif (APPLE)
436     set (CPACK_GENERATOR "DragNDrop")
437 else ()
438     set (CPACK_GENERATOR "TBZ2")
439 endif ()
440
441 include(CPack)