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