1 cmake_minimum_required (VERSION 2.8)
6 ##############################################################################
9 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
11 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
13 find_package (PythonInterp REQUIRED)
14 find_package (OpenGL REQUIRED)
15 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit)
19 find_package (X11 REQUIRED)
21 # On Mac OS X, GLX is provided as a separate OpenGL implementation, different
22 # from the standard OpenGL framework which provides support for native Mac OS X
25 find_path (X11_GL_INCLUDE_PATH GL/glx.h ${X11_INC_SEARCH_PATH})
26 if (NOT X11_GL_INCLUDE_PATH)
27 message (SEND_ERROR "Could not find GL/glx.h")
28 endif (NOT X11_GL_INCLUDE_PATH)
29 set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_GL_INCLUDE_PATH})
31 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
33 message (SEND_ERROR "Could not find libGL.dylib")
34 endif (NOT X11_GL_LIB)
36 set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
37 set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
40 include_directories (${X11_INCLUDE_DIR})
44 find_package (DirectX)
48 ##############################################################################
49 # Set global build options
51 include (CheckCXXCompilerFlag)
54 # MSVC & MinGW only define & use APIENTRY
55 add_definitions (-DGLAPIENTRY=__stdcall)
57 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
58 add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
60 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
61 if (CXX_COMPILER_FLAG_VISIBILITY)
62 add_definitions ("-fvisibility=hidden")
63 endif (CXX_COMPILER_FLAG_VISIBILITY)
67 # C99 includes for msvc
68 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msvc)
70 # Enable math constants defines
71 add_definitions (-D_USE_MATH_DEFINES)
74 add_definitions (-DNOMINMAX)
77 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
78 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
80 add_definitions (-wd4063) # not a valid value for switch of enum
81 add_definitions (-wd4127) # conditional expression is constant
82 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
83 add_definitions (-wd4505) # unreferenced local function has been removed
84 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
85 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
86 add_definitions (-wd4018) # signed/unsigned mismatch
89 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
91 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
92 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
94 if (${flag_var} MATCHES "/MD")
95 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
96 endif (${flag_var} MATCHES "/MD")
100 add_definitions (-Wall)
101 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
102 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
106 # Put all executables into the same top level build directory, regardless of
107 # which subdirectory they are declared
108 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
111 ##############################################################################
112 # Bundled dependencies
114 # We always use the bundled zlib and libpng sources:
115 # - on Windows to make it easy to deploy the wrappers DLLs
116 # - on unices to prevent symbol collisions when tracing applications that link
117 # against other versions of these libraries
119 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
120 set (ZLIB_LIBRARIES z_bundled)
121 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
123 include_directories (${ZLIB_INCLUDE_DIRS})
124 link_libraries (${ZLIB_LIBRARIES})
126 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
127 set (PNG_DEFINITIONS "")
128 set (PNG_LIBRARIES png_bundled)
130 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
131 include_directories (${PNG_INCLUDE_DIR})
132 add_definitions (${PNG_DEFINITIONS})
133 link_libraries (${PNG_LIBRARIES})
136 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
139 ##############################################################################
140 # Common libraries / utilities
142 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
145 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
146 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
147 DEPENDS glproc.py dispatch.py wglapi.py glxapi.py cglapi.py glapi.py gltypes.py stdapi.py
151 set (os os_win32.cpp)
152 set (glws glws_wgl.cpp)
154 set (os os_posix.cpp)
155 set (glws glws_glx.cpp)
162 trace_model_writer.cpp
169 add_executable (tracedump tracedump.cpp)
170 target_link_libraries (tracedump common)
171 install (TARGETS tracedump RUNTIME DESTINATION bin)
174 ##############################################################################
179 if (DirectX_D3D_INCLUDE_DIR)
180 include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
183 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d.py > ${CMAKE_CURRENT_BINARY_DIR}/ddraw.cpp
184 DEPENDS d3d.py d3dtypes.py d3dcaps.py ddraw.py trace.py winapi.py stdapi.py
186 add_library (ddraw MODULE ddraw.def ddraw.cpp trace_writer.cpp os_win32.cpp)
187 set_target_properties (ddraw
189 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
190 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
192 install (TARGETS ddraw LIBRARY DESTINATION wrappers)
193 endif (DirectX_D3D_INCLUDE_DIR)
196 if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
197 include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
200 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
201 DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
203 add_library (d3d8 MODULE d3d8.def d3d8.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
204 set_target_properties (d3d8
206 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
207 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
209 install (TARGETS d3d8 LIBRARY DESTINATION wrappers)
210 endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
213 if (DirectX_D3DX9_INCLUDE_DIR)
214 include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
217 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
218 DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
220 add_library (d3d9 MODULE d3d9.def d3d9.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
221 set_target_properties (d3d9
223 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
224 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
226 install (TARGETS d3d9 LIBRARY DESTINATION wrappers)
227 endif (DirectX_D3DX9_INCLUDE_DIR)
230 #if (DirectX_D3D10_INCLUDE_DIR)
231 # include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
232 # add_custom_command (
234 # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
235 # DEPENDS d3d10misc.py winapi.py stdapi.py
237 # add_library (d3d10 MODULE d3d10.def d3d10.cpp trace_writer.cpp os_win32.cpp)
238 # set_target_properties (d3d10 PROPERTIES PREFIX "")
239 # install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
240 #endif (DirectX_D3D10_INCLUDE_DIR)
245 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
246 DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
248 add_library (wgltrace MODULE opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
249 set_target_properties (wgltrace PROPERTIES
252 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
253 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
256 set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
258 install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
264 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
265 DEPENDS cgltrace.py gltrace.py trace.py cglapi.py glapi.py glparams.py gltypes.py stdapi.py
268 add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
270 set_target_properties (cgltrace PROPERTIES
271 # OpenGL framework name
272 PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
273 # Specificy the version and reexport GLU symbols
274 LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
275 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
276 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
279 target_link_libraries (cgltrace dl)
281 install (TARGETS cgltrace LIBRARY DESTINATION wrappers)
286 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
287 DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
290 add_library (glxtrace SHARED
291 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
299 set_target_properties (glxtrace PROPERTIES
300 # avoid the default "lib" prefix
304 # Prevent symbol relocations internal to our wrapper library to be
305 # overwritten by the application.
306 set_target_properties (glxtrace PROPERTIES
307 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
310 target_link_libraries (glxtrace dl ${X11_X11_LIB})
312 install (TARGETS glxtrace LIBRARY DESTINATION lib)
316 ##############################################################################
320 OUTPUT glretrace_gl.cpp
321 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
322 DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
326 OUTPUT glstate_params.cpp
327 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
328 DEPENDS glstate.py glparams.py gltypes.py stdapi.py
331 include_directories (
332 ${CMAKE_CURRENT_BINARY_DIR}
333 ${OPENGL_INCLUDE_PATH}
336 add_executable (glretrace
347 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
353 PROPERTY COMPILE_DEFINITIONS "RETRACE"
356 target_link_libraries (glretrace
361 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
363 # XXX: We use GLX on MacOSX, which is in a separate library.
364 target_link_libraries (glretrace
367 "-framework ApplicationServices" # CGS*
368 ${OPENGL_gl_LIBRARY} # CGL*
371 target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
374 install (TARGETS glretrace RUNTIME DESTINATION bin)
377 ##############################################################################
380 if (QT4_FOUND AND QJSON_FOUND)
381 add_subdirectory(gui)
382 endif (QT4_FOUND AND QJSON_FOUND)
385 ##############################################################################
388 install (FILES LICENSE README.markdown TODO.markdown DESTINATION doc)
390 set (CPACK_PACKAGE_VERSION_MAJOR "1")
391 set (CPACK_PACKAGE_VERSION_MINOR "0")
393 # Use current date in YYYYMMDD format as patch number
395 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
396 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
399 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
401 set (CPACK_GENERATOR "ZIP")
403 set (CPACK_GENERATOR "DragNDrop")
405 set (CPACK_GENERATOR "TBZ2")