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 (-wd4127) # conditional expression is constant
63 add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
64 add_definitions (-wd4505) # unreferenced local function has been removed
65 add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
66 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
67 add_definitions (-wd4018) # signed/unsigned mismatch
70 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
72 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
73 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
75 if (${flag_var} MATCHES "/MD")
76 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
77 endif (${flag_var} MATCHES "/MD")
81 add_definitions (-Wall)
82 # XXX: it's safer to use ssize_t everywhere instead of disabling warning
83 add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
87 # Put all executables into the same top level build directory, regardless of
88 # which subdirectory they are declared
89 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
91 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
94 ##############################################################################
95 # Bundled dependencies
97 # Use bundled ZLIB if system one can't be found
99 include_directories (${ZLIB_INCLUDE_DIRS})
100 link_libraries (${ZLIB_LIBRARIES})
102 add_subdirectory (zlib)
103 include_directories (zlib)
104 link_libraries (zlib)
107 # Use bundled LIBPNG if system one can't be found
109 include_directories (${PNG_INCLUDE_DIR})
110 add_definitions (${PNG_DEFINITIONS})
111 link_libraries (${PNG_LIBRARIES})
113 add_library (png STATIC
130 include_directories (libpng)
135 ##############################################################################
136 # Common libraries / utilities
139 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
140 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
141 DEPENDS glproc.py dispatch.py wglapi.py glxapi.py cglapi.py glapi.py gltypes.py stdapi.py
145 set (os os_win32.cpp)
146 set (glws glws_wgl.cpp)
148 set (os os_posix.cpp)
149 set (glws glws_glx.cpp)
152 add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp ${os})
154 add_executable (tracedump tracedump.cpp)
155 target_link_libraries (tracedump trace)
156 install (TARGETS tracedump RUNTIME DESTINATION bin)
159 ##############################################################################
164 if (DirectX_D3D8_INCLUDE_DIR)
165 include_directories (${DirectX_D3D8_INCLUDE_DIR})
168 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
169 DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
171 add_library (d3d8 SHARED d3d8.def d3d8.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
172 set_target_properties (d3d8
174 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
175 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
177 install (TARGETS d3d8 RUNTIME DESTINATION wrappers)
178 endif (DirectX_D3D8_INCLUDE_DIR)
181 if (DirectX_D3DX9_INCLUDE_DIR)
182 include_directories (${DirectX_D3DX9_INCLUDE_DIR})
185 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
186 DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
188 add_library (d3d9 SHARED d3d9.def d3d9.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
189 set_target_properties (d3d9
191 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
192 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
194 install (TARGETS d3d9 RUNTIME DESTINATION wrappers)
195 endif (DirectX_D3DX9_INCLUDE_DIR)
198 #if (DirectX_D3D10_INCLUDE_DIR)
199 # include_directories (${DirectX_D3D10_INCLUDE_DIR})
200 # add_custom_command (
202 # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
203 # DEPENDS d3d10misc.py winapi.py stdapi.py
205 # add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_writer.cpp os_win32.cpp)
206 # set_target_properties (d3d10 PROPERTIES PREFIX "")
207 # install (TARGETS d3d10 RUNTIME DESTINATION wrappers)
208 #endif (DirectX_D3D10_INCLUDE_DIR)
213 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
214 DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
216 add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
217 set_target_properties (wgltrace PROPERTIES
220 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
221 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
224 set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
226 install (TARGETS wgltrace RUNTIME DESTINATION wrappers)
229 include_directories (${X11_INCLUDE_DIR})
234 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
235 DEPENDS cgltrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
238 add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
240 set_target_properties (cgltrace PROPERTIES
244 LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0"
245 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
246 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
249 target_link_libraries (cgltrace dl)
251 # Symbolic link from system's libGL.dylib
254 COMMAND ln -sf /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib ${PROJECT_BINARY_DIR}/wrappers/libGL.system.dylib
257 install (TARGETS cgltrace LIBRARY DESTINATION lib)
259 include_directories (${X11_INCLUDE_DIR})
264 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
265 DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
268 add_library (glxtrace SHARED glxtrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
270 set_target_properties (glxtrace PROPERTIES
271 # avoid the default "lib" prefix
275 # Prevent symbol relocations internal to our wrapper library to be
276 # overwritten by the application.
277 set_target_properties (glxtrace PROPERTIES
278 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
281 target_link_libraries (glxtrace dl)
283 install (TARGETS glxtrace LIBRARY DESTINATION lib)
287 ##############################################################################
291 OUTPUT glretrace_gl.cpp
292 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
293 DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
297 OUTPUT glstate_params.cpp
298 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
299 DEPENDS glstate.py glparams.py gltypes.py stdapi.py
302 include_directories (
303 ${CMAKE_CURRENT_BINARY_DIR}
304 ${OPENGL_INCLUDE_PATH}
307 add_executable (glretrace
318 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
324 PROPERTY COMPILE_DEFINITIONS "RETRACE"
327 target_link_libraries (glretrace
333 target_link_libraries (glretrace ${X11_X11_LIB})
335 # We use GLX on MacOSX, which is in a separate library
337 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
338 find_library (APPLICATIONSERVICES ApplicationServices)
339 target_link_libraries (glretrace ${X11_GL_LIB} ${APPLICATIONSERVICES})
343 install (TARGETS glretrace RUNTIME DESTINATION bin)
346 ##############################################################################
349 if (QT4_FOUND AND QJSON_FOUND)
350 add_subdirectory(gui)
351 endif (QT4_FOUND AND QJSON_FOUND)
354 ##############################################################################
357 install (FILES LICENSE README TODO DESTINATION doc)
359 set (CPACK_PACKAGE_VERSION_MAJOR "1")
360 set (CPACK_PACKAGE_VERSION_MINOR "0")
362 # Use current date in YYYYMMDD format as patch number
364 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
365 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
369 set (CPACK_GENERATOR "ZIP")
371 set (CPACK_GENERATOR "TGZ")