blob: 5e17cafe1c6efbc368fed6d09f16956ba5c69161 [file] [log] [blame]
José Fonsecae9242602015-03-09 11:04:53 +00001cmake_minimum_required (VERSION 2.8.11)
José Fonseca83178a02010-11-14 00:35:05 +00002
José Fonseca76efdcb2012-10-24 13:43:06 +01003
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.
Ben Kelly7cd89202013-05-03 21:35:37 -07006# But DONT force clang if we are cross-compiling to Android.
7if (APPLE AND NOT ANDROID_NDK)
José Fonseca76efdcb2012-10-24 13:43:06 +01008 set (CMAKE_C_COMPILER "clang")
9 set (CMAKE_CXX_COMPILER "clang++")
10endif ()
11
José Fonsecaf2ad6182014-12-02 11:33:07 +000012if (CMAKE_GENERATOR STREQUAL "Xcode")
13 message (FATAL_ERROR "Xcode generator is not supported. Please build with \"Unix Makefiles\" or \"Ninja\" generators.")
14endif ()
15
José Fonseca9adffcf2014-12-04 22:07:48 +000016# http://www.cmake.org/cmake/help/v3.0/policy/CMP0042.html
17if (POLICY CMP0042)
18 cmake_policy (SET CMP0042 NEW)
19endif()
20
José Fonseca76efdcb2012-10-24 13:43:06 +010021
José Fonseca83178a02010-11-14 00:35:05 +000022project (apitrace)
23
José Fonseca17311e82011-05-08 11:12:08 +010024
25##############################################################################
José Fonsecae68c87f2011-07-28 00:32:54 +010026# Options
José Fonseca5971d6a2011-09-27 14:13:56 +010027
28# On Mac OS X build fat binaries with i386 and x86_64 architectures by default.
29if (APPLE AND NOT CMAKE_OSX_ARCHITECTURES)
30 set (CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
31endif ()
32
José Fonsecae68c87f2011-07-28 00:32:54 +010033# We use a cached string variable instead of the standard (boolean) OPTION
34# command so that we can default to auto-detecting optional depencies, while
35# still providing a mechanism to force/disable these optional dependencies, as
José Fonsecaab310da2011-07-28 19:07:50 +010036# prescribed in http://www.gentoo.org/proj/en/qa/automagic.xml
Zack Rusina8426522011-07-29 00:07:43 -040037set (ENABLE_GUI "AUTO" CACHE STRING "Enable Qt GUI.")
José Fonsecae68c87f2011-07-28 00:32:54 +010038
Jose Fonseca6a9a4322015-01-24 19:23:57 +000039option (ENABLE_CLI "Enable command Line interface." ON)
José Fonsecaef0c6972012-03-10 16:05:09 +000040
Jose Fonseca6a9a4322015-01-24 19:23:57 +000041option (ENABLE_EGL "Enable EGL support." ON)
José Fonseca82da2422011-11-17 15:45:10 +000042
Jose Fonseca6a9a4322015-01-24 19:23:57 +000043option (ENABLE_WAFFLE "Enable WAFFLE support." OFF)
José Fonseca7c388482013-11-29 19:32:54 +000044
Jose Fonseca6a9a4322015-01-24 19:23:57 +000045option (ENABLE_FRAME_POINTER "Disable frame pointer omission" ON)
José Fonseca42945ef2014-09-03 22:32:18 +010046
Jose Fonseca21e685f2015-03-12 23:27:56 +000047# Proprietary Linux games often ship their own libraries (zlib, libstdc++,
48# etc.) in order to ship a single set of binaries across multiple
49# distributions. Given that apitrace wrapper modules will be loaded into those
50# processes, they must not depend on any shared object that could also be
51# provided by such applications. See also
52# http://lists.freedesktop.org/archives/mesa-dev/2015-March/079121.html
Jose Fonsecab132f862015-03-12 23:53:10 +000053if (NOT ANDROID)
54 option (ENABLE_STATIC_SNAPPY "Statically link against snappy" ON)
Jose Fonsecab132f862015-03-12 23:53:10 +000055 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
Jose Fonsecabdd03ca2015-04-26 21:43:01 +010056 option (ENABLE_STATIC_LIBGCC "Statically link LD_PRELOAD wrappers against libgcc" ON)
57 option (ENABLE_STATIC_LIBSTDCXX "Statically link LD_PRELOAD wrappers against libstdc++" ON)
58 if (NOT (ENABLE_STATIC_LIBGCC AND
59 ENABLE_STATIC_LIBSTDCXX AND
60 ENABLE_STATIC_SNAPPY))
61 # XXX: Should probably throw a run-time too.
62 message (WARNING
63 "LD_PRELOAD wrappers not statically linked against all "
64 "dependencies, therefore will fail to work with many "
65 "third-party applications built on different Linux "
66 "distributions and that ship their own shared-object "
67 "dependencies."
68 )
69 endif ()
Jose Fonsecab132f862015-03-12 23:53:10 +000070 endif ()
Jose Fonseca21e685f2015-03-12 23:27:56 +000071endif ()
72
José Fonsecae68c87f2011-07-28 00:32:54 +010073
74##############################################################################
José Fonseca17311e82011-05-08 11:12:08 +010075# Find dependencies
76
José Fonseca8917aea2013-04-23 10:12:12 +010077# Check for compiler TLS support. We don't use compiler TLS support on Windows
78# because, even if the compiler supports it, Windows XP does not support TLS on
79# DLLs.
80if (NOT WIN32)
81 include (CheckCXXSourceCompiles)
José Fonseca7e41fcf2015-03-26 23:03:56 +000082 check_cxx_source_compiles ("__thread int i; int main() { return 0; }" HAVE_COMPILER_TLS)
83 if (NOT HAVE_COMPILER_TLS)
84 message (FATAL_ERROR "C++ compiler does not support __thread keyword.")
José Fonseca8917aea2013-04-23 10:12:12 +010085 endif ()
86endif ()
87
José Fonsecab460bf32010-11-19 18:57:51 +000088set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
José Fonsecac56b9ac2014-06-25 13:46:35 +010089include (ConvenienceLibrary)
José Fonseca01e5c852014-10-02 15:48:35 +010090include (InstallPDB)
José Fonsecab460bf32010-11-19 18:57:51 +000091
George Wrighta4a643e2012-02-23 14:54:49 -050092if (ANDROID)
93 set (ENABLE_GUI false)
George Wrighta4a643e2012-02-23 14:54:49 -050094else ()
95 macro (find_host_package)
96 find_package (${ARGN})
97 endmacro()
98endif ()
99
José Fonseca37341052014-12-03 16:31:31 +0000100find_host_package (PythonInterp 2.7 REQUIRED)
José Fonseca994fa9a2014-06-03 16:03:45 +0100101if (NOT PYTHON_VERSION_MAJOR EQUAL 2)
102 message (FATAL_ERROR "Python 2.x required and requested, but Python ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} found.")
103endif ()
104
José Fonsecae86846f2012-03-10 16:02:49 +0000105find_package (Threads)
106
Jose Fonseca94c0b7c2015-03-12 21:13:05 +0000107if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
José Fonseca39072d22014-11-11 22:22:57 +0000108 find_package (procps)
Jose Fonsecacc41a482015-03-13 10:35:27 +0000109 if (PROCPS_FOUND)
José Fonseca39072d22014-11-11 22:22:57 +0000110 add_definitions (-DHAVE_READPROC_H)
111 endif ()
112endif ()
113
José Fonsecae68c87f2011-07-28 00:32:54 +0100114if (ENABLE_GUI)
115 if (NOT (ENABLE_GUI STREQUAL "AUTO"))
116 set (REQUIRE_GUI REQUIRED)
117 endif ()
José Fonseca3f4cd302015-01-14 12:02:06 +0000118 if (POLICY CMP0020)
119 cmake_policy (SET CMP0020 NEW)
120 endif()
121 find_package (Qt5Widgets ${REQUIRE_GUI})
122 find_package (Qt5WebKitWidgets ${REQUIRE_GUI})
José Fonsecae68c87f2011-07-28 00:32:54 +0100123endif ()
José Fonseca83178a02010-11-14 00:35:05 +0000124
José Fonsecae8fec0f2011-06-06 21:06:29 +0100125if (WIN32)
126 find_package (DirectX)
José Fonsecae319ab42012-03-10 15:37:43 +0000127 set (ENABLE_EGL false)
José Fonsecaf4608e32011-10-10 20:17:35 +0100128elseif (APPLE)
José Fonsecae319ab42012-03-10 15:37:43 +0000129 set (ENABLE_EGL false)
José Fonsecaa62e12f2011-10-07 15:33:48 +0100130else ()
Arnaud Vrac6ac796e2011-12-19 02:44:24 +0100131 find_package (X11)
José Fonsecaa62e12f2011-10-07 15:33:48 +0100132
Arnaud Vrac6ac796e2011-12-19 02:44:24 +0100133 if (X11_FOUND)
134 include_directories (${X11_INCLUDE_DIR})
135 add_definitions (-DHAVE_X11)
José Fonseca8d1d5322012-10-28 10:48:22 +0000136 else ()
137 # Print a clear message when X11 is not found
138 include (FindPackageMessage)
139 find_package_message (X11 "Could not find X11" "")
Arnaud Vrac6ac796e2011-12-19 02:44:24 +0100140 endif ()
José Fonsecaa62e12f2011-10-07 15:33:48 +0100141endif ()
José Fonsecae8fec0f2011-06-06 21:06:29 +0100142
José Fonseca7c388482013-11-29 19:32:54 +0000143if (ENABLE_EGL AND (ANDROID OR ENABLE_WAFFLE))
144 # if waffle is found eglretrace will be built for Android.
145 find_package (Waffle)
146endif ()
147
José Fonseca17311e82011-05-08 11:12:08 +0100148
149##############################################################################
150# Set global build options
151
152include (CheckCXXCompilerFlag)
José Fonseca1c6c2bc2014-02-25 15:28:03 +0000153include (CheckIncludeFileCXX)
José Fonseca17311e82011-05-08 11:12:08 +0100154
José Fonseca7ed2ef32015-01-29 15:51:22 +0000155macro (add_compiler_flags)
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000156 string (REPLACE ";" " " _FLAGS "${ARGV}")
157 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAGS}")
158 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_FLAGS}")
José Fonseca7ed2ef32015-01-29 15:51:22 +0000159endmacro ()
160
José Fonsecacb084e12014-09-11 18:13:58 +0100161macro (add_linker_flags)
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000162 string (REPLACE ";" " " _FLAGS "${ARGV}")
163 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_FLAGS}")
164 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_FLAGS}")
165 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_FLAGS}")
José Fonsecacb084e12014-09-11 18:13:58 +0100166endmacro ()
167
Jose Fonseca4ba12ac2015-05-18 15:17:05 +0100168add_definitions (
169 -D__STDC_LIMIT_MACROS
170)
171
José Fonseca5aff9b02010-11-22 13:00:54 +0000172if (WIN32)
José Fonsecaeb508e62011-05-08 07:39:31 +0100173 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
José Fonsecaf5de61a2015-03-27 12:55:19 +0000174 if (MINGW OR CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
José Fonseca070a0632014-06-23 18:25:55 +0100175 # Windows XP
176 add_definitions (-D_WIN32_WINNT=0x0501 -DWINVER=0x0501)
177 else ()
178 # Windows 7
179 add_definitions (-D_WIN32_WINNT=0x0601 -DWINVER=0x0601)
180 endif ()
José Fonseca23691292011-04-22 10:40:25 +0100181else (WIN32)
182 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
183 if (CXX_COMPILER_FLAG_VISIBILITY)
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000184 add_compiler_flags (-fvisibility=hidden)
José Fonseca5b6fb752012-04-14 14:56:45 +0100185 endif ()
186endif ()
José Fonseca83178a02010-11-14 00:35:05 +0000187
188if (MSVC)
José Fonseca15eafa92015-03-04 21:23:31 +0000189 if (${MSVC_VERSION} LESS 1800)
190 message (FATAL_ERROR "Visual Studio 2013 or later required")
José Fonsecaf8278972014-04-29 10:29:12 +0100191 endif ()
José Fonseca5caf8702011-04-11 21:01:07 +0100192
Nigel Stewart673d32a2013-07-19 09:32:47 -0500193 # No RTTI required
José Fonsecaaec30832014-05-13 17:29:40 +0100194 string (REGEX REPLACE "/GR *" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
195 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
Nigel Stewart673d32a2013-07-19 09:32:47 -0500196
José Fonsecac354ea02015-03-20 07:01:16 +0000197 # Disable C++ exceptions
198 add_definitions (-D_HAS_EXCEPTIONS=0)
199 string (REGEX REPLACE "/EHsc *" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
200 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
201
José Fonseca03f63612010-12-04 10:59:52 +0000202 # Enable math constants defines
203 add_definitions (-D_USE_MATH_DEFINES)
José Fonseca83178a02010-11-14 00:35:05 +0000204
José Fonseca2af485a2011-04-15 20:49:21 +0100205 # No min/max macros
206 add_definitions (-DNOMINMAX)
207
José Fonseca03f63612010-12-04 10:59:52 +0000208 # Adjust warnings
209 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
210 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
José Fonseca7ed2ef32015-01-29 15:51:22 +0000211 add_compiler_flags (-W3)
José Fonsecaaf7fc5c2012-04-23 12:19:53 +0100212 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
José Fonseca7ed2ef32015-01-29 15:51:22 +0000213 add_compiler_flags (-wd4018) # signed/unsigned mismatch
214 add_compiler_flags (-wd4063) # not a valid value for switch of enum
215 add_compiler_flags (-wd4100) # unreferenced formal parameter
216 add_compiler_flags (-wd4127) # conditional expression is constant
217 add_compiler_flags (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
218 add_compiler_flags (-wd4267) # conversion from 'type1' to 'type2', possible loss of data
219 add_compiler_flags (-wd4505) # unreferenced local function has been removed
220 add_compiler_flags (-wd4512) # assignment operator could not be generated
221 add_compiler_flags (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
José Fonseca03f63612010-12-04 10:59:52 +0000222
223 # Use static runtime
224 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
225 foreach (flag_var
226 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
227 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
228 )
229 if (${flag_var} MATCHES "/MD")
230 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
José Fonseca5b6fb752012-04-14 14:56:45 +0100231 endif ()
José Fonseca03f63612010-12-04 10:59:52 +0000232 endforeach (flag_var)
José Fonseca1791f622010-11-15 16:09:40 +0000233else ()
Jose Fonseca02c5d502015-03-08 20:51:11 +0000234 # Enable and require C++11
235 #
236 # We must use `-std=gnu++11` instead `-std=c++11` as the latter defines
Jose Fonsecaeabf02d2015-03-08 21:57:30 +0000237 # __STRICT_ANSI__ which prevents _isnan from being declared with MinGW.
Jose Fonseca02c5d502015-03-08 20:51:11 +0000238 #
239 # See also:
240 # - https://gcc.gnu.org/projects/cxx0x.html
241 # - http://clang.llvm.org/cxx_status.html
242 check_cxx_compiler_flag ("-std=gnu++11" CXX_COMPILER_FLAG_STD_GNUXX11)
José Fonseca1a1e3262015-03-12 14:20:19 +0000243 if (CXX_COMPILER_FLAG_STD_GNUXX11)
Jose Fonseca02c5d502015-03-08 20:51:11 +0000244 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
José Fonseca47de2eb2015-03-12 14:15:30 +0000245 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Jose Fonseca02c5d502015-03-08 20:51:11 +0000246 check_cxx_compiler_flag ("-std=gnu++0x" CXX_COMPILER_FLAG_STD_GNUXX0X)
José Fonseca47de2eb2015-03-12 14:15:30 +0000247 if (NOT CXX_COMPILER_FLAG_STD_GNUXX0X OR
248 CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.6")
249 message (FATAL_ERROR "GCC 4.6 or later required for adequate C++11 support")
Jose Fonseca02c5d502015-03-08 20:51:11 +0000250 else ()
José Fonseca47de2eb2015-03-12 14:15:30 +0000251 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
Jose Fonseca02c5d502015-03-08 20:51:11 +0000252 endif ()
José Fonseca47de2eb2015-03-12 14:15:30 +0000253 else ()
254 message (FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} compiler does not support C++11")
Jose Fonseca02c5d502015-03-08 20:51:11 +0000255 endif ()
256
José Fonseca03f63612010-12-04 10:59:52 +0000257 # Adjust warnings
José Fonseca7ed2ef32015-01-29 15:51:22 +0000258 add_compiler_flags (-Wall)
José Fonseca03f63612010-12-04 10:59:52 +0000259 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
José Fonseca7ed2ef32015-01-29 15:51:22 +0000260 add_compiler_flags (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
Imre Deak33b9a0f2012-04-20 16:34:31 +0300261
Jose Fonseca8e5e3792015-03-15 07:49:36 +0000262 # Disable strict aliasing assumptions. We generate a lot of C++ code, and
263 # it's not always easy to guarantee or spot when strict aliasing
264 # assumptions are violated. Above all, the benefit is not worth the risk.
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000265 add_compiler_flags (-fno-strict-aliasing)
Jose Fonseca8e5e3792015-03-15 07:49:36 +0000266
Nigel Stewart673d32a2013-07-19 09:32:47 -0500267 # No RTTI required
José Fonseca5cebfd82015-03-20 07:00:53 +0000268 # XXX: there's a dynamic_cast in Android
269 if (NOT ANDROID)
270 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
271 endif ()
Nigel Stewart673d32a2013-07-19 09:32:47 -0500272
José Fonsecac354ea02015-03-20 07:01:16 +0000273 # Disable C++ exceptions
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000274 #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
José Fonsecac354ea02015-03-20 07:01:16 +0000275
José Fonseca4c3da7c2014-09-12 08:36:06 +0100276 # Enable stack protection
277 if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
José Fonseca4c3da7c2014-09-12 08:36:06 +0100278 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fstack-protector-all")
279 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector-all")
280 if (MINGW)
281 # MinGW doesn't link against libssp automatically, and furthermore
282 # we want static linking.
283 set (SSP_LIBRARY "-Wl,-Bstatic -lssp -Wl,-Bdynamic")
284 set (CMAKE_C_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_C_STANDARD_LIBRARIES}")
285 set (CMAKE_CXX_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_CXX_STANDARD_LIBRARIES}")
286 endif ()
287 endif ()
288
José Fonseca7ddb0702014-08-29 18:24:19 +0100289 # Enable SSE2 intrinsics on x86
290 if (CMAKE_SIZEOF_VOID_P EQUAL 4)
José Fonsecad591f962015-01-29 16:01:53 +0000291 check_cxx_compiler_flag ("-msse2" CXX_COMPILER_FLAG_MSSE2)
292 if (CXX_COMPILER_FLAG_MSSE2)
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000293 add_compiler_flags (-msse2 -mfpmath=sse)
José Fonsecad591f962015-01-29 16:01:53 +0000294
295 # And tell GCC to assume 4 bytes alignment, many Linux/Windows
296 # applications only guarantee that, but not on systems where ABI
297 # clearly states otherwise.
298 #
299 # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38496
300 if (NOT ANDROID)
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000301 check_cxx_compiler_flag (-mincoming-stack-boundary=2 CXX_COMPILER_FLAG_MINCOMING_STACK_BOUNDARY)
José Fonsecad591f962015-01-29 16:01:53 +0000302 if (CXX_COMPILER_FLAG_MINCOMING_STACK_BOUNDARY)
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000303 add_compiler_flags (-mincoming-stack-boundary=2)
José Fonsecad591f962015-01-29 16:01:53 +0000304 endif ()
305 endif ()
José Fonseca7ddb0702014-08-29 18:24:19 +0100306 endif ()
307 endif ()
308
José Fonseca43894cb2012-10-19 18:43:46 +0100309 # Be nice to Eclipse
José Fonseca7ed2ef32015-01-29 15:51:22 +0000310 add_compiler_flags (-fmessage-length=0)
José Fonseca1791f622010-11-15 16:09:40 +0000311endif ()
José Fonseca83178a02010-11-14 00:35:05 +0000312
José Fonsecaaa5681e2011-10-11 19:32:30 +0100313if (MINGW)
314 # Avoid depending on MinGW runtime DLLs
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000315 add_linker_flags (-static-libgcc -static-libstdc++)
José Fonsecaaa5681e2011-10-11 19:32:30 +0100316endif ()
317
José Fonseca42945ef2014-09-03 22:32:18 +0100318if (ENABLE_FRAME_POINTER)
319 # disable frame pointer omission
320 if (MSVC)
José Fonseca7ed2ef32015-01-29 15:51:22 +0000321 add_compiler_flags (/Oy-)
José Fonseca42945ef2014-09-03 22:32:18 +0100322 else ()
José Fonseca7ed2ef32015-01-29 15:51:22 +0000323 add_compiler_flags (-fno-omit-frame-pointer)
José Fonseca42945ef2014-09-03 22:32:18 +0100324 endif ()
325endif ()
326
José Fonsecae632a702014-09-11 18:14:32 +0100327# Enable Data Execution Prevention and Address Space Layout Randomization
328if (WIN32)
329 if (MSVC)
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000330 add_linker_flags (/NXCOMPAT /DYNAMICBASE)
José Fonsecae632a702014-09-11 18:14:32 +0100331 else ()
Jose Fonseca6d437fb2015-03-27 10:53:06 +0000332 add_linker_flags (-Wl,--nxcompat -Wl,--dynamicbase)
José Fonsecae632a702014-09-11 18:14:32 +0100333 endif ()
334endif ()
335
Jose Fonseca94c0b7c2015-03-12 21:13:05 +0000336if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
José Fonseca6c383112013-05-04 09:33:41 +0100337 # For RTLD_DEFAULT and RTLD_NEXT
338 add_definitions (-D_GNU_SOURCE)
339endif ()
340
Jose Fonsecaf67e3c12015-05-01 17:42:03 +0100341include (TestBigEndian)
342test_big_endian (HAVE_BIGENDIAN)
343if (HAVE_BIGENDIAN)
344 add_definitions (-DHAVE_BIGENDIAN)
345endif ()
346
José Fonseca44721292011-04-21 08:24:57 +0100347# Put all executables into the same top level build directory, regardless of
348# which subdirectory they are declared
José Fonseca5d4e2a12011-07-01 11:58:16 +0100349set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
José Fonseca44721292011-04-21 08:24:57 +0100350
José Fonseca17311e82011-05-08 11:12:08 +0100351
352##############################################################################
José Fonseca27440922011-11-01 08:27:12 +0000353# Installation directories
354
Jose Fonseca94c0b7c2015-03-12 21:13:05 +0000355if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
Michal Suchanek96851e02012-05-07 16:07:16 +0200356 # Debian multiarch support
357 execute_process(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
358 OUTPUT_VARIABLE ARCH_SUBDIR
359 ERROR_QUIET
360 OUTPUT_STRIP_TRAILING_WHITESPACE
361 )
362endif()
363
José Fonseca27440922011-11-01 08:27:12 +0000364if (WIN32 OR APPLE)
365 # On Windows/MacOSX, applications are usually installed on a directory of
366 # their own
367 set (DOC_INSTALL_DIR doc)
José Fonsecaab6ded72012-03-02 10:31:19 +0000368 set (LIB_INSTALL_DIR lib)
Michal Suchanek96851e02012-05-07 16:07:16 +0200369 set (LIB_ARCH_INSTALL_DIR lib)
José Fonseca27440922011-11-01 08:27:12 +0000370else ()
371 set (DOC_INSTALL_DIR share/doc/${CMAKE_PROJECT_NAME})
Sandro Mani41245852013-11-20 21:27:29 +0100372 set (LIB_INSTALL_DIR lib${LIB_SUFFIX}/${CMAKE_PROJECT_NAME})
Michal Suchanek96851e02012-05-07 16:07:16 +0200373 if (ARCH_SUBDIR)
374 set (LIB_ARCH_INSTALL_DIR lib/${ARCH_SUBDIR}/${CMAKE_PROJECT_NAME})
375 else ()
Sandro Mani41245852013-11-20 21:27:29 +0100376 set (LIB_ARCH_INSTALL_DIR lib${LIB_SUFFIX}/${CMAKE_PROJECT_NAME})
Michal Suchanek96851e02012-05-07 16:07:16 +0200377 endif ()
José Fonseca27440922011-11-01 08:27:12 +0000378endif ()
379
José Fonseca7c3ea252012-05-08 15:02:51 +0100380set (SCRIPTS_INSTALL_DIR ${LIB_INSTALL_DIR}/scripts)
Michal Suchanek96851e02012-05-07 16:07:16 +0200381set (WRAPPER_INSTALL_DIR ${LIB_ARCH_INSTALL_DIR}/wrappers)
Carl Worth26cca9b2011-11-04 15:42:02 -0700382
José Fonseca27440922011-11-01 08:27:12 +0000383
384##############################################################################
José Fonseca8fae49d2012-12-11 07:22:16 +0000385# Bundled dependencies
386#
Jose Fonsecab132f862015-03-12 23:53:10 +0000387# We prefer to bundle and statically link against many dependencies:
José Fonseca8fae49d2012-12-11 07:22:16 +0000388# - on Windows to make it easy to deploy the wrappers DLLs
389# - on unices to prevent symbol collisions when tracing applications that link
390# against other versions of these libraries
391
Jose Fonsecab132f862015-03-12 23:53:10 +0000392if (NOT ENABLE_STATIC_SNAPPY)
393 find_package (SNAPPY)
394endif ()
395if (ENABLE_STATIC_SNAPPY OR NOT SNAPPY_FOUND)
396 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
397 set (SNAPPY_LIBRARIES snappy_bundled)
398 add_subdirectory (thirdparty/snappy)
399endif ()
José Fonseca8fae49d2012-12-11 07:22:16 +0000400include_directories (${SNAPPY_INCLUDE_DIRS})
401
Jose Fonseca63e5f392015-03-15 10:33:32 +0000402if (NOT WIN32)
Jose Fonseca33d5be12015-03-15 19:09:13 +0000403 # zlib 1.2.4-1.2.5 made it impossible to read the last block of incomplete
404 # gzip traces (e.g., apitrace-tests/traces/zlib-no-eof.trace).
405 find_package (ZLIB 1.2.6)
Jose Fonsecab132f862015-03-12 23:53:10 +0000406endif ()
Jose Fonseca63e5f392015-03-15 10:33:32 +0000407if (NOT ZLIB_FOUND)
Jose Fonsecab132f862015-03-12 23:53:10 +0000408 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
409 set (ZLIB_LIBRARIES z_bundled)
410 add_subdirectory (thirdparty/zlib)
411endif ()
412include_directories (${ZLIB_INCLUDE_DIRS})
José Fonseca8fae49d2012-12-11 07:22:16 +0000413
Jose Fonseca40f5ce12015-03-15 22:35:22 +0000414# FindPNG.cmake will search ZLIB internally (without requiring any particular
415# version), adding its include dirs and libraries, and overwriting ZLIB_FOUND.
416# So if the system's ZLIB was did not meet the our requirements, then there's
417# no safe way to use the system's PNG library.
418if (NOT WIN32 AND ZLIB_FOUND)
Jose Fonsecab132f862015-03-12 23:53:10 +0000419 find_package (PNG)
420endif ()
Jose Fonseca63e5f392015-03-15 10:33:32 +0000421if (NOT PNG_FOUND)
Jose Fonsecab132f862015-03-12 23:53:10 +0000422 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
423 set (PNG_DEFINITIONS "")
424 set (PNG_LIBRARIES png_bundled)
425 add_subdirectory (thirdparty/libpng)
426endif ()
José Fonseca8fae49d2012-12-11 07:22:16 +0000427
428if (MSVC)
429 add_subdirectory (thirdparty/getopt)
430 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/getopt)
431 set (GETOPT_LIBRARIES getopt_bundled)
432endif ()
433
434if (WIN32)
José Fonseca3b74a952015-02-09 11:52:29 +0000435 add_subdirectory (thirdparty/dxerr)
José Fonsecad7c738e2013-03-06 11:46:41 +0000436 add_subdirectory (thirdparty/directxtex)
José Fonsecae5b9a912014-09-25 21:28:59 +0100437 add_subdirectory (thirdparty/devcon)
José Fonseca8fae49d2012-12-11 07:22:16 +0000438endif ()
439
Alexander Monakov9c8be7c2013-05-19 00:23:58 +0400440if (CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
441 add_subdirectory (thirdparty/libbacktrace)
442 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libbacktrace)
Alexander Monakov2a5696b2013-07-13 00:37:17 +0400443 set (LIBBACKTRACE_LIBRARIES dl backtrace)
José Fonsecad6c02fd2013-09-20 10:50:45 +0100444 add_definitions (-DHAVE_BACKTRACE=1)
Alexander Monakov9c8be7c2013-05-19 00:23:58 +0400445endif ()
446
Meng Mengmeng093cf112014-01-22 12:49:20 +0000447add_subdirectory (thirdparty/md5)
448set (MD5_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/md5)
449set (MD5_LIBRARIES md5_bundled)
450
José Fonseca8fae49d2012-12-11 07:22:16 +0000451# We use bundled headers for all Khronos APIs, to guarantee support for both
452# OpenGL and OpenGL ES at build time, because the OpenGL and OpenGL ES 1 APIs
453# are so intertwined that conditional compilation extremely difficult. This
454# also avoids missing/inconsistent declarations in system headers.
455include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/khronos)
456
457
458##############################################################################
José Fonseca17311e82011-05-08 11:12:08 +0100459# Common libraries / utilities
José Fonseca83178a02010-11-14 00:35:05 +0000460
José Fonsecaa8c164c2011-09-21 07:46:50 +0100461include_directories (
José Fonsecaa8c164c2011-09-21 07:46:50 +0100462 ${CMAKE_CURRENT_SOURCE_DIR}/common
463)
José Fonseca5d4e2a12011-07-01 11:58:16 +0100464
José Fonseca5aff9b02010-11-22 13:00:54 +0000465if (WIN32)
José Fonseca17311e82011-05-08 11:12:08 +0100466 set (os os_win32.cpp)
José Fonsecaa62e12f2011-10-07 15:33:48 +0100467else ()
José Fonseca17311e82011-05-08 11:12:08 +0100468 set (os os_posix.cpp)
José Fonsecaa62e12f2011-10-07 15:33:48 +0100469endif ()
José Fonseca17311e82011-05-08 11:12:08 +0100470
José Fonsecac56b9ac2014-06-25 13:46:35 +0100471add_convenience_library (common
José Fonseca225193d2012-01-26 19:08:32 +0000472 common/trace_callset.cpp
José Fonseca946da142011-12-11 14:32:50 +0000473 common/trace_dump.cpp
Carl Worth12b41a82013-03-11 13:05:52 -0700474 common/trace_fast_callset.cpp
José Fonsecaa8c164c2011-09-21 07:46:50 +0100475 common/trace_file.cpp
José Fonsecaa3285532011-11-27 12:32:00 +0000476 common/trace_file_read.cpp
477 common/trace_file_write.cpp
José Fonseca4159a612011-10-26 23:37:01 +0100478 common/trace_file_zlib.cpp
479 common/trace_file_snappy.cpp
José Fonsecaa8c164c2011-09-21 07:46:50 +0100480 common/trace_model.cpp
481 common/trace_parser.cpp
José Fonseca340f5692011-11-30 07:04:44 +0000482 common/trace_parser_flags.cpp
José Fonsecaa8c164c2011-09-21 07:46:50 +0100483 common/trace_writer.cpp
José Fonseca91392da2011-10-26 23:39:16 +0100484 common/trace_writer_local.cpp
485 common/trace_writer_model.cpp
José Fonsecaa8c164c2011-09-21 07:46:50 +0100486 common/trace_loader.cpp
James Bentonaddf7f92012-07-20 18:56:19 +0100487 common/trace_profiler.cpp
Carl Wortha7e7b272012-08-12 16:48:10 -0700488 common/trace_option.cpp
José Fonsecaa8c164c2011-09-21 07:46:50 +0100489 common/${os}
Alexander Monakovcad5d612013-07-12 21:26:25 +0400490 common/os_backtrace.cpp
José Fonseca3f9ed152014-05-28 00:05:15 +0100491 common/highlight.cpp
José Fonseca49ff44d2011-07-02 14:16:37 +0100492)
José Fonseca17311e82011-05-08 11:12:08 +0100493
José Fonsecabd9811f2013-09-20 15:37:17 +0100494target_link_libraries (common
495 ${LIBBACKTRACE_LIBRARIES}
496)
José Fonseca2f00d762015-02-05 11:43:33 +0000497if (WIN32)
498 target_link_libraries (common
499 shell32
500 )
501endif ()
George Wright2a4e4b62012-02-27 15:54:36 -0500502if (ANDROID)
José Fonseca17a45412012-11-28 09:44:01 +0000503 target_link_libraries (common
504 log
505 )
George Wright2a4e4b62012-02-27 15:54:36 -0500506endif ()
507
José Fonseca27440922011-11-01 08:27:12 +0000508
José Fonseca17311e82011-05-08 11:12:08 +0100509##############################################################################
José Fonseca4f242f42012-04-14 18:13:25 +0100510# Sub-directories
José Fonseca17311e82011-05-08 11:12:08 +0100511
José Fonseca4f242f42012-04-14 18:13:25 +0100512add_subdirectory (dispatch)
José Fonseca3b186822012-11-27 15:25:21 +0000513add_subdirectory (helpers)
José Fonseca452d3252012-04-14 15:55:40 +0100514add_subdirectory (wrappers)
José Fonsecae7102bf2012-12-07 07:33:05 +0000515add_subdirectory (image)
José Fonseca9d27a542012-04-14 17:22:57 +0100516add_subdirectory (retrace)
José Fonseca7e329022010-11-19 17:05:18 +0000517
José Fonseca8e3c2c02012-01-23 00:30:35 +0000518
Carl Worth6d543af2011-10-19 18:02:33 -0700519##############################################################################
520# CLI
521
José Fonsecaef0c6972012-03-10 16:05:09 +0000522if (ENABLE_CLI)
José Fonsecabd4937e2012-12-04 13:23:03 +0000523 if (WIN32)
524 add_subdirectory (inject)
525 endif ()
José Fonseca17a45412012-11-28 09:44:01 +0000526 add_subdirectory (cli)
José Fonsecaef0c6972012-03-10 16:05:09 +0000527endif ()
José Fonseca17311e82011-05-08 11:12:08 +0100528
529##############################################################################
Carl Worth32420d22011-11-04 15:45:09 -0700530# Scripts (to support the CLI)
531
José Fonseca97a199d2011-11-29 00:22:41 +0000532install (
533 PROGRAMS
José Fonseca330135d2012-12-11 07:34:45 +0000534 scripts/highlight.py
535 scripts/jsondiff.py
536 scripts/profileshader.py
537 scripts/retracediff.py
José Fonseca330135d2012-12-11 07:34:45 +0000538 scripts/snapdiff.py
539 scripts/tracecheck.py
540 scripts/tracediff.py
541 scripts/unpickle.py
José Fonseca97a199d2011-11-29 00:22:41 +0000542 DESTINATION ${SCRIPTS_INSTALL_DIR}
543)
José Fonseca2cce1922012-12-11 19:51:26 +0000544if (WIN32)
545 install (
546 PROGRAMS scripts/convert.py
547 DESTINATION ${SCRIPTS_INSTALL_DIR}
548 )
José Fonseca393bf3f2014-07-22 14:59:03 +0100549 install (
550 FILES scripts/apitrace.PIXExp
551 DESTINATION ${SCRIPTS_INSTALL_DIR}
552 )
José Fonseca2cce1922012-12-11 19:51:26 +0000553endif ()
Carl Worth32420d22011-11-04 15:45:09 -0700554
555##############################################################################
José Fonseca17311e82011-05-08 11:12:08 +0100556# GUI
557
José Fonseca3f4cd302015-01-14 12:02:06 +0000558if (ENABLE_GUI AND Qt5Widgets_FOUND AND Qt5WebKitWidgets_FOUND)
559 add_subdirectory(gui)
José Fonsecae68c87f2011-07-28 00:32:54 +0100560endif ()
José Fonseca17311e82011-05-08 11:12:08 +0100561
562
563##############################################################################
564# Packaging
565
José Fonseca05ba4192011-09-17 21:18:57 +0100566install (
567 FILES
José Fonseca21278192015-01-20 14:27:04 +0000568 README.markdown
José Fonsecac345e0d2015-01-20 14:22:54 +0000569 docs/BUGS.markdown
570 docs/NEWS.markdown
José Fonseca21278192015-01-20 14:27:04 +0000571 docs/USAGE.markdown
José Fonseca27440922011-11-01 08:27:12 +0000572 DESTINATION ${DOC_INSTALL_DIR}
Carl Worthe9236072011-10-18 16:06:05 -0700573)
José Fonseca8fae49d2012-12-11 07:22:16 +0000574install (
575 FILES LICENSE
576 DESTINATION ${DOC_INSTALL_DIR}
577 RENAME LICENSE.txt
578)
José Fonseca0dc84852011-05-14 10:46:24 +0100579
Jose Fonsecaa5255fd2015-01-26 14:38:39 +0000580set (CPACK_PACKAGE_VERSION_MAJOR "7")
José Fonseca17311e82011-05-08 11:12:08 +0100581set (CPACK_PACKAGE_VERSION_MINOR "0")
582
583# Use current date in YYYYMMDD format as patch number
584execute_process (
585 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
586 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
587)
588
José Fonseca63c02f32012-02-29 10:55:55 +0000589# cpack mistakenly detects Mingw-w64 as win32
590if (MINGW)
591 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
592 set (CPACK_SYSTEM_NAME win64)
593 endif ()
594endif ()
595
José Fonsecafa54c8a2011-06-02 14:48:38 +0100596# See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
José Fonseca17311e82011-05-08 11:12:08 +0100597if (WIN32)
José Fonseca99ff4a72015-03-18 15:13:30 +0000598 if (CMAKE_VERSION VERSION_LESS 3.1)
599 set (CPACK_GENERATOR "ZIP")
600 else ()
601 set (CPACK_GENERATOR "7Z")
602 endif ()
José Fonsecafa54c8a2011-06-02 14:48:38 +0100603elseif (APPLE)
604 set (CPACK_GENERATOR "DragNDrop")
605else ()
José Fonseca7e0b44f2011-06-06 19:36:37 +0100606 set (CPACK_GENERATOR "TBZ2")
José Fonsecafa54c8a2011-06-02 14:48:38 +0100607endif ()
José Fonseca17311e82011-05-08 11:12:08 +0100608
609include(CPack)