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 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/zlib)
101 set (ZLIB_LIBRARIES zlib)
102 add_subdirectory (zlib EXCLUDE_FROM_ALL)
103 endif (NOT ZLIB_FOUND)
105 include_directories (${ZLIB_INCLUDE_DIRS})
106 link_libraries (${ZLIB_LIBRARIES})
108 # Use bundled LIBPNG if system one can't be found
111 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libpng)
112 set (PNG_DEFINITIONS "")
113 set (PNG_LIBRARIES png)
114 add_subdirectory (libpng EXCLUDE_FROM_ALL)
116 include_directories (${PNG_INCLUDE_DIR})
117 add_definitions (${PNG_DEFINITIONS})
118 link_libraries (${PNG_LIBRARIES})
121 ##############################################################################
122 # Common libraries / utilities
125 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
126 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
127 DEPENDS glproc.py dispatch.py wglapi.py glxapi.py cglapi.py glapi.py gltypes.py stdapi.py
131 set (os os_win32.cpp)
132 set (glws glws_wgl.cpp)
134 set (os os_posix.cpp)
135 set (glws glws_glx.cpp)
138 add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp trace_model_writer.cpp ${os})
140 add_executable (tracedump tracedump.cpp)
141 target_link_libraries (tracedump trace)
142 install (TARGETS tracedump RUNTIME DESTINATION bin)
145 ##############################################################################
150 if (DirectX_D3D_INCLUDE_DIR)
151 include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
154 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d.py > ${CMAKE_CURRENT_BINARY_DIR}/ddraw.cpp
155 DEPENDS d3d.py d3dtypes.py d3dcaps.py ddraw.py trace.py winapi.py stdapi.py
157 add_library (ddraw MODULE ddraw.def ddraw.cpp trace_writer.cpp os_win32.cpp)
158 set_target_properties (ddraw
160 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
161 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
163 install (TARGETS ddraw LIBRARY DESTINATION wrappers)
164 endif (DirectX_D3D_INCLUDE_DIR)
167 if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
168 include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
171 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
172 DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
174 add_library (d3d8 MODULE d3d8.def d3d8.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
175 set_target_properties (d3d8
177 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
178 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
180 install (TARGETS d3d8 LIBRARY DESTINATION wrappers)
181 endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
184 if (DirectX_D3DX9_INCLUDE_DIR)
185 include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
188 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
189 DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
191 add_library (d3d9 MODULE d3d9.def d3d9.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
192 set_target_properties (d3d9
194 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
195 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
197 install (TARGETS d3d9 LIBRARY DESTINATION wrappers)
198 endif (DirectX_D3DX9_INCLUDE_DIR)
201 #if (DirectX_D3D10_INCLUDE_DIR)
202 # include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
203 # add_custom_command (
205 # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
206 # DEPENDS d3d10misc.py winapi.py stdapi.py
208 # add_library (d3d10 MODULE d3d10.def d3d10.cpp trace_writer.cpp os_win32.cpp)
209 # set_target_properties (d3d10 PROPERTIES PREFIX "")
210 # install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
211 #endif (DirectX_D3D10_INCLUDE_DIR)
216 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
217 DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
219 add_library (wgltrace MODULE opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
220 set_target_properties (wgltrace PROPERTIES
223 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
224 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
227 set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
229 install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
232 include_directories (${X11_INCLUDE_DIR})
237 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
238 DEPENDS cgltrace.py gltrace.py trace.py cglapi.py glapi.py glparams.py gltypes.py stdapi.py
241 add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
243 set_target_properties (cgltrace PROPERTIES
245 PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
246 # Specificy the version and reexport GLU symbols
247 LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
248 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
249 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
252 target_link_libraries (cgltrace dl)
254 install (TARGETS cgltrace LIBRARY DESTINATION wrappers)
256 include_directories (${X11_INCLUDE_DIR})
261 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
262 DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
265 add_library (glxtrace SHARED glxtrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
267 set_target_properties (glxtrace PROPERTIES
268 # avoid the default "lib" prefix
272 # Prevent symbol relocations internal to our wrapper library to be
273 # overwritten by the application.
274 set_target_properties (glxtrace PROPERTIES
275 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 glstate_params.cpp
295 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.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
315 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
321 PROPERTY COMPILE_DEFINITIONS "RETRACE"
324 target_link_libraries (glretrace
330 target_link_libraries (glretrace ${X11_X11_LIB})
332 # We use GLX on MacOSX, which is in a separate library
334 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
335 find_library (APPLICATIONSERVICES ApplicationServices)
336 target_link_libraries (glretrace ${X11_GL_LIB} ${APPLICATIONSERVICES})
340 install (TARGETS glretrace RUNTIME DESTINATION bin)
343 ##############################################################################
346 if (QT4_FOUND AND QJSON_FOUND)
347 add_subdirectory(gui)
348 endif (QT4_FOUND AND QJSON_FOUND)
351 ##############################################################################
354 install (FILES LICENSE README TODO DESTINATION doc)
356 set (CPACK_PACKAGE_VERSION_MAJOR "1")
357 set (CPACK_PACKAGE_VERSION_MINOR "0")
359 # Use current date in YYYYMMDD format as patch number
361 COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
362 OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
365 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
367 set (CPACK_GENERATOR "ZIP")
369 set (CPACK_GENERATOR "DragNDrop")
371 set (CPACK_GENERATOR "TGZ")