1 cmake_minimum_required (VERSION 2.8)
6 ##############################################################################
9 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
11 # Set default built type
12 if (NOT CMAKE_BUILD_TYPE)
13 set (CMAKE_BUILD_TYPE Debug
15 STRING "Choose the build type, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel."
17 endif (NOT CMAKE_BUILD_TYPE)
19 set (CMAKE_USE_PYTHON_VERSION 2.6)
21 find_package (PythonInterp REQUIRED)
22 find_package (OpenGL REQUIRED)
23 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit)
27 # Always use the bundled zlib and libpng sources on Windows to make it easy
28 # to deploy the wrappers DLLs
31 find_package (X11 REQUIRED)
33 # We use GLX on MacOSX, which is in a separate library
35 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
36 set(X11_LIBRARIES ${X11_LIBRARIES} ${X11_GL_LIB})
39 find_package (DirectX)
43 ##############################################################################
44 # Set global build options
46 include (CheckCXXCompilerFlag)
49 # MSVC & MinGW only define & use APIENTRY
50 add_definitions (-DGLAPIENTRY=__stdcall)
52 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
53 add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
55 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
56 if (CXX_COMPILER_FLAG_VISIBILITY)
57 add_definitions ("-fvisibility=hidden")
58 endif (CXX_COMPILER_FLAG_VISIBILITY)
62 # C99 includes for msvc
63 include_directories (msvc)
65 # Enable math constants defines
66 add_definitions (-D_USE_MATH_DEFINES)
69 add_definitions (-DNOMINMAX)
72 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
73 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
75 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
76 add_definitions (-wd4505) # unreferenced local function has been removed
77 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
78 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
79 add_definitions (-wd4018) # signed/unsigned mismatch
82 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
84 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
85 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
87 if (${flag_var} MATCHES "/MD")
88 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
89 endif (${flag_var} MATCHES "/MD")
93 add_definitions (-Wall)
94 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
95 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
99 # Put all executables into the same top level build directory, regardless of
100 # which subdirectory they are declared
101 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
103 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
106 ##############################################################################
107 # Bundled dependencies
109 # Use bundled ZLIB if system one can't be found
111 include_directories (${ZLIB_INCLUDE_DIRS})
112 link_libraries (${ZLIB_LIBRARIES})
114 add_library (zlib STATIC
128 include_directories (zlib)
129 link_libraries (zlib)
132 # Use bundled LIBPNG if system one can't be found
134 include_directories (${PNG_INCLUDE_DIR})
135 add_definitions (${PNG_DEFINITIONS})
136 link_libraries (${PNG_LIBRARIES})
138 add_library (png STATIC
155 include_directories (libpng)
160 ##############################################################################
161 # Common libraries / utilities
164 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
165 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
166 DEPENDS glproc.py dispatch.py wglapi.py glxapi.py glapi.py gltypes.py stdapi.py
170 set (os os_win32.cpp)
171 set (glws glws_wgl.cpp)
173 set (os os_posix.cpp)
174 set (glws glws_glx.cpp)
177 add_library (trace trace_model.cpp trace_parser.cpp trace_write.cpp ${os})
179 add_executable (tracedump tracedump.cpp)
180 target_link_libraries (tracedump trace)
181 install (TARGETS tracedump RUNTIME DESTINATION bin)
184 ##############################################################################
189 if (DirectX_D3D8_INCLUDE_DIR)
190 include_directories (${DirectX_D3D8_INCLUDE_DIR})
193 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
194 DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py d3dshader.py winapi.py stdapi.py
196 add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
197 set_target_properties (d3d8
199 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
200 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
202 install (TARGETS d3d8 RUNTIME DESTINATION wrappers)
203 endif (DirectX_D3D8_INCLUDE_DIR)
206 if (DirectX_D3DX9_INCLUDE_DIR)
207 include_directories (${DirectX_D3DX9_INCLUDE_DIR})
210 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
211 DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
213 add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
214 set_target_properties (d3d9
216 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
217 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
219 install (TARGETS d3d9 RUNTIME DESTINATION wrappers)
220 endif (DirectX_D3DX9_INCLUDE_DIR)
223 #if (DirectX_D3D10_INCLUDE_DIR)
224 # include_directories (${DirectX_D3D10_INCLUDE_DIR})
225 # add_custom_command (
227 # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
228 # DEPENDS d3d10misc.py winapi.py stdapi.py
230 # add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
231 # set_target_properties (d3d10 PROPERTIES PREFIX "")
232 # install (TARGETS d3d10 RUNTIME DESTINATION wrappers)
233 #endif (DirectX_D3D10_INCLUDE_DIR)
238 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
239 DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
241 add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_write.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
242 set_target_properties (wgltrace PROPERTIES
245 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
246 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
249 set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
251 install (TARGETS wgltrace RUNTIME DESTINATION wrappers)
254 include_directories (${X11_INCLUDE_DIR})
259 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
260 DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
263 add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
265 set_target_properties (glxtrace PROPERTIES
266 # avoid the default "lib" prefix
270 # Prevent symbol relocations internal to our wrapper library to be
271 # overwritten by the application.
273 set_target_properties (glxtrace PROPERTIES
274 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
278 target_link_libraries (glxtrace dl)
280 install (TARGETS glxtrace LIBRARY DESTINATION lib)
284 ##############################################################################
288 OUTPUT glretrace_gl.cpp
289 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
290 DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
294 OUTPUT glretrace_state.cpp
295 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_state.cpp
296 DEPENDS glstate.py glparams.py gltypes.py stdapi.py
299 include_directories (
300 ${CMAKE_CURRENT_BINARY_DIR}
301 ${OPENGL_INCLUDE_PATH}
304 add_executable (glretrace
313 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
319 PROPERTY COMPILE_DEFINITIONS "RETRACE"
322 target_link_libraries (glretrace
328 target_link_libraries (glretrace ${X11_LIBRARIES})
331 install (TARGETS glretrace RUNTIME DESTINATION bin)
334 ##############################################################################
337 if (QT4_FOUND AND QJSON_FOUND)
338 add_subdirectory(gui)
339 endif (QT4_FOUND AND QJSON_FOUND)
342 ##############################################################################
345 set (CPACK_PACKAGE_VERSION_MAJOR "1")
346 set (CPACK_PACKAGE_VERSION_MINOR "0")
348 # Use current date in YYYYMMDD format as patch number
350 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
351 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
355 set (CPACK_GENERATOR "ZIP")
357 set (CPACK_GENERATOR "TGZ")