1 cmake_minimum_required (VERSION 2.8)
3 include (CheckCXXCompilerFlag)
7 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
9 # Set default built type
10 if (NOT CMAKE_BUILD_TYPE)
11 set (CMAKE_BUILD_TYPE Debug
13 STRING "Choose the build type, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel."
15 endif (NOT CMAKE_BUILD_TYPE)
17 set (CMAKE_USE_PYTHON_VERSION 2.6)
19 find_package (PythonInterp REQUIRED)
20 find_package (OpenGL REQUIRED)
21 find_package (Qt4 COMPONENTS QtCore QtGui QtWebKit)
25 # Always use the bundled zlib and libpng sources on Windows to make it easy
26 # to deploy the wrappers DLLs
29 find_package (X11 REQUIRED)
31 # We use GLX on MacOSX, which is in a separate library
33 find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
34 set(X11_LIBRARIES ${X11_LIBRARIES} ${X11_GL_LIB})
37 find_package (DirectX)
41 # MSVC & MinGW only define & use APIENTRY
42 add_definitions (-DGLAPIENTRY=__stdcall)
44 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
45 if (CXX_COMPILER_FLAG_VISIBILITY)
46 add_definitions ("-fvisibility=hidden")
47 endif (CXX_COMPILER_FLAG_VISIBILITY)
51 # C99 includes for msvc
52 include_directories (msvc)
54 # Enable math constants defines
55 add_definitions (-D_USE_MATH_DEFINES)
58 add_definitions (-DNOMINMAX)
61 add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
62 add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
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
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 # Use bundled ZLIB if system one can't be found
93 include_directories (${ZLIB_INCLUDE_DIRS})
94 link_libraries (${ZLIB_LIBRARIES})
96 add_library (zlib STATIC
110 include_directories (zlib)
111 link_libraries (zlib)
114 # Use bundled LIBPNG if system one can't be found
116 include_directories (${PNG_INCLUDE_DIR})
117 add_definitions (${PNG_DEFINITIONS})
118 link_libraries (${PNG_LIBRARIES})
120 add_library (png STATIC
137 include_directories (libpng)
141 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
144 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
145 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
146 DEPENDS glproc.py dispatch.py wglapi.py glxapi.py glapi.py glenum.py stdapi.py
150 # Put wrappers in a separate directory
151 set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers)
154 #if (DirectX_D3D8_FOUND)
155 # include_directories (${DirectX_D3D8_INCLUDE_DIR})
156 # add_custom_command (
158 # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
159 # DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py stdapi.py
161 # add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
162 # set_target_properties (d3d8 PROPERTIES PREFIX "")
163 #endif (DirectX_D3D8_FOUND)
166 if (DirectX_D3DX9_FOUND)
167 include_directories (${DirectX_D3DX9_INCLUDE_DIR})
170 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
171 DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
173 add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
174 set_target_properties (d3d9 PROPERTIES PREFIX "")
175 endif (DirectX_D3DX9_FOUND)
178 #if (DirectX_D3D10_FOUND)
179 # include_directories (${DirectX_D3D10_INCLUDE_DIR})
180 # add_custom_command (
182 # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
183 # DEPENDS d3d10misc.py winapi.py stdapi.py
185 # add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
186 # set_target_properties (d3d10 PROPERTIES PREFIX "")
187 #endif (DirectX_D3D10_FOUND)
192 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
193 DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glenum.py winapi.py stdapi.py
195 add_library (opengl SHARED opengl32.def wgltrace.cpp trace_write.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
196 set_target_properties (opengl PROPERTIES
198 OUTPUT_NAME opengl32)
200 set_target_properties(opengl PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
204 include_directories (${X11_INCLUDE_DIR})
209 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
210 DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glenum.py stdapi.py
213 add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
215 set_target_properties (glxtrace PROPERTIES
216 # avoid the default "lib" prefix
220 # Prevent symbol relocations internal to our wrapper library to be
221 # overwritten by the application.
223 set_target_properties (glxtrace PROPERTIES
224 LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
228 target_link_libraries (glxtrace dl)
232 set (os os_win32.cpp)
233 set (glws glws_wgl.cpp)
235 set (os os_posix.cpp)
236 set (glws glws_glx.cpp)
239 add_library (trace trace_model.cpp trace_parser.cpp trace_write.cpp ${os})
241 add_executable (tracedump tracedump.cpp)
242 target_link_libraries (tracedump trace)
245 OUTPUT glretrace_gl.cpp
246 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
247 DEPENDS glretrace.py retrace.py codegen.py glapi.py glenum.py stdapi.py
251 OUTPUT glretrace_state.cpp
252 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_state.cpp
253 DEPENDS glstate.py glapi.py glenum.py stdapi.py
256 include_directories (
257 ${CMAKE_CURRENT_BINARY_DIR}
258 ${OPENGL_INCLUDE_PATH}
261 add_executable (glretrace
268 ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
274 PROPERTY COMPILE_DEFINITIONS "RETRACE"
277 target_link_libraries (glretrace
283 target_link_libraries (glretrace ${X11_LIBRARIES})
286 if (QT4_FOUND AND QJSON_FOUND)
287 add_subdirectory(gui)
288 endif (QT4_FOUND AND QJSON_FOUND)