1 cmake_minimum_required (VERSION 2.8)
6 ##############################################################################
9 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
11 set (CMAKE_USE_PYTHON_VERSION 2.6)
13 find_package (PythonInterp REQUIRED)
14 find_package (OpenGL REQUIRED)
15 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit)
19 # Always use the bundled zlib and libpng sources on Windows to make it easy
20 # to deploy the wrappers DLLs
23 find_package (X11 REQUIRED)
26 find_package (DirectX)
30 ##############################################################################
31 # Set global build options
33 include (CheckCXXCompilerFlag)
36 # MSVC & MinGW only define & use APIENTRY
37 add_definitions (-DGLAPIENTRY=__stdcall)
39 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
40 add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
42 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
43 if (CXX_COMPILER_FLAG_VISIBILITY)
44 add_definitions ("-fvisibility=hidden")
45 endif (CXX_COMPILER_FLAG_VISIBILITY)
49 # C99 includes for msvc
50 include_directories (msvc)
52 # Enable math constants defines
53 add_definitions (-D_USE_MATH_DEFINES)
56 add_definitions (-DNOMINMAX)
59 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
60 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
62 add_definitions (-wd4063) # not a valid value for switch of enum
63 add_definitions (-wd4127) # conditional expression is constant
64 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
65 add_definitions (-wd4505) # unreferenced local function has been removed
66 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
67 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
68 add_definitions (-wd4018) # signed/unsigned mismatch
71 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
73 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
74 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
76 if (${flag_var} MATCHES "/MD")
77 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
78 endif (${flag_var} MATCHES "/MD")
82 add_definitions (-Wall)
83 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
84 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
88 # Put all executables into the same top level build directory, regardless of
89 # which subdirectory they are declared
90 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
92 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
95 ##############################################################################
96 # Bundled dependencies
98 # Use bundled ZLIB if system one can't be found
100 include_directories (${ZLIB_INCLUDE_DIRS})
101 link_libraries (${ZLIB_LIBRARIES})
103 add_library (zlib STATIC
117 include_directories (zlib)
118 link_libraries (zlib)
121 # Use bundled LIBPNG if system one can't be found
123 include_directories (${PNG_INCLUDE_DIR})
124 add_definitions (${PNG_DEFINITIONS})
125 link_libraries (${PNG_LIBRARIES})
127 add_library (png STATIC
144 include_directories (libpng)
149 ##############################################################################
150 # Common libraries / utilities
153 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
154 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
155 DEPENDS glproc.py dispatch.py wglapi.py glxapi.py cglapi.py glapi.py gltypes.py stdapi.py
159 set (os os_win32.cpp)
160 set (glws glws_wgl.cpp)
162 set (os os_posix.cpp)
163 set (glws glws_glx.cpp)
166 add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp ${os})
168 add_executable (tracedump tracedump.cpp)
169 target_link_libraries (tracedump trace)
170 install (TARGETS tracedump RUNTIME DESTINATION bin)
173 ##############################################################################
178 if (DirectX_D3D_INCLUDE_DIR)
179 include_directories (${DirectX_D3D_INCLUDE_DIR})
182 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d.py > ${CMAKE_CURRENT_BINARY_DIR}/ddraw.cpp
183 DEPENDS d3d.py d3dtypes.py d3dcaps.py ddraw.py trace.py winapi.py stdapi.py
185 add_library (ddraw SHARED ddraw.def ddraw.cpp trace_writer.cpp os_win32.cpp)
186 set_target_properties (ddraw
188 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
189 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
191 install (TARGETS ddraw RUNTIME DESTINATION wrappers)
192 endif (DirectX_D3D_INCLUDE_DIR)
195 if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
196 include_directories (${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
199 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
200 DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
202 add_library (d3d8 SHARED d3d8.def d3d8.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
203 set_target_properties (d3d8
205 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
206 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
208 install (TARGETS d3d8 RUNTIME DESTINATION wrappers)
209 endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
212 if (DirectX_D3DX9_INCLUDE_DIR)
213 include_directories (${DirectX_D3DX9_INCLUDE_DIR})
216 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
217 DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
219 add_library (d3d9 SHARED d3d9.def d3d9.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
220 set_target_properties (d3d9
222 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
223 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
225 install (TARGETS d3d9 RUNTIME DESTINATION wrappers)
226 endif (DirectX_D3DX9_INCLUDE_DIR)
229 #if (DirectX_D3D10_INCLUDE_DIR)
230 # include_directories (${DirectX_D3D10_INCLUDE_DIR})
231 # add_custom_command (
233 # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
234 # DEPENDS d3d10misc.py winapi.py stdapi.py
236 # add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_writer.cpp os_win32.cpp)
237 # set_target_properties (d3d10 PROPERTIES PREFIX "")
238 # install (TARGETS d3d10 RUNTIME DESTINATION wrappers)
239 #endif (DirectX_D3D10_INCLUDE_DIR)
244 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
245 DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
247 add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
248 set_target_properties (wgltrace PROPERTIES
251 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
252 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
255 set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
257 install (TARGETS wgltrace RUNTIME DESTINATION wrappers)
260 include_directories (${X11_INCLUDE_DIR})
265 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
266 DEPENDS cgltrace.py gltrace.py trace.py cglapi.py glapi.py glparams.py gltypes.py stdapi.py
269 add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
271 set_target_properties (cgltrace PROPERTIES
273 PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
274 # Specificy the version and reexport GLU symbols
275 LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
276 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
277 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
280 target_link_libraries (cgltrace dl)
282 install (TARGETS cgltrace LIBRARY DESTINATION lib)
284 include_directories (${X11_INCLUDE_DIR})
289 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
290 DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
293 add_library (glxtrace SHARED glxtrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
295 set_target_properties (glxtrace PROPERTIES
296 # avoid the default "lib" prefix
300 # Prevent symbol relocations internal to our wrapper library to be
301 # overwritten by the application.
302 set_target_properties (glxtrace PROPERTIES
303 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
306 target_link_libraries (glxtrace dl)
308 install (TARGETS glxtrace LIBRARY DESTINATION lib)
312 ##############################################################################
316 OUTPUT glretrace_gl.cpp
317 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
318 DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
322 OUTPUT glstate_params.cpp
323 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
324 DEPENDS glstate.py glparams.py gltypes.py stdapi.py
327 include_directories (
328 ${CMAKE_CURRENT_BINARY_DIR}
329 ${OPENGL_INCLUDE_PATH}
332 add_executable (glretrace
343 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
349 PROPERTY COMPILE_DEFINITIONS "RETRACE"
352 target_link_libraries (glretrace
358 target_link_libraries (glretrace ${X11_X11_LIB})
360 # We use GLX on MacOSX, which is in a separate library
362 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
363 find_library (APPLICATIONSERVICES ApplicationServices)
364 target_link_libraries (glretrace ${X11_GL_LIB} ${APPLICATIONSERVICES})
368 install (TARGETS glretrace RUNTIME DESTINATION bin)
371 ##############################################################################
374 if (QT4_FOUND AND QJSON_FOUND)
375 add_subdirectory(gui)
376 endif (QT4_FOUND AND QJSON_FOUND)
379 ##############################################################################
382 install (FILES LICENSE README TODO DESTINATION doc)
384 set (CPACK_PACKAGE_VERSION_MAJOR "1")
385 set (CPACK_PACKAGE_VERSION_MINOR "0")
387 # Use current date in YYYYMMDD format as patch number
389 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
390 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
394 set (CPACK_GENERATOR "ZIP")
396 set (CPACK_GENERATOR "TGZ")