]> git.notmuchmail.org Git - apitrace/blob - CMakeLists.txt
Dump D3D9 shaders as text, as done previously.
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2
3 include (CheckCXXCompilerFlag)
4
5 project (apitrace)
6
7 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
8
9 # Set default built type
10 if (NOT CMAKE_BUILD_TYPE)
11     set (CMAKE_BUILD_TYPE Debug
12         CACHE
13         STRING "Choose the build type, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel."
14         FORCE)
15 endif (NOT CMAKE_BUILD_TYPE)
16
17 set (CMAKE_USE_PYTHON_VERSION 2.6)
18
19 find_package (PythonInterp REQUIRED)
20 find_package (OpenGL REQUIRED)
21 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit)
22 find_package (QJSON)
23
24 if (NOT WIN32)
25     # Always use the bundled zlib and libpng sources on Windows to make it easy
26     # to deploy the wrappers DLLs
27     find_package (ZLIB)
28     find_package (PNG)
29     find_package (X11 REQUIRED)
30
31     # We use GLX on MacOSX, which is in a separate library
32     if (APPLE)
33         find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
34         set(X11_LIBRARIES ${X11_LIBRARIES} ${X11_GL_LIB})
35     endif (APPLE)
36 else (NOT WIN32)
37     find_package (DirectX)
38 endif (NOT WIN32)
39
40 if (WIN32)
41     # MSVC & MinGW only define & use APIENTRY
42     add_definitions (-DGLAPIENTRY=__stdcall)
43 else (WIN32)
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)
48 endif (WIN32)
49
50 if (MSVC)
51     # C99 includes for msvc
52     include_directories (msvc)
53
54     # Enable math constants defines
55     add_definitions (-D_USE_MATH_DEFINES)
56
57     # No min/max macros
58     add_definitions (-DNOMINMAX)
59
60     # Adjust warnings
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)
63     add_definitions (-W4)
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
69     
70     # Use static runtime
71     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
72     foreach (flag_var
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
75     )
76         if (${flag_var} MATCHES "/MD")
77             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
78         endif (${flag_var} MATCHES "/MD")
79     endforeach (flag_var)
80 else ()
81     # Adjust warnings
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
85 endif ()
86
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})
90
91 # Use bundled ZLIB if system one can't be found
92 if (ZLIB_FOUND)
93     include_directories (${ZLIB_INCLUDE_DIRS})
94     link_libraries (${ZLIB_LIBRARIES})
95 else (ZLIB_FOUND)
96     add_library (zlib STATIC
97         zlib/adler32.c
98         zlib/compress.c
99         zlib/crc32.c
100         zlib/gzio.c
101         zlib/uncompr.c
102         zlib/deflate.c
103         zlib/trees.c
104         zlib/zutil.c
105         zlib/inflate.c
106         zlib/infback.c
107         zlib/inftrees.c
108         zlib/inffast.c
109     )
110     include_directories (zlib)
111     link_libraries (zlib)
112 endif (ZLIB_FOUND)
113
114 # Use bundled LIBPNG if system one can't be found
115 if (PNG_FOUND)
116     include_directories (${PNG_INCLUDE_DIR})
117     add_definitions (${PNG_DEFINITIONS})
118     link_libraries (${PNG_LIBRARIES})
119 else (PNG_FOUND)
120     add_library (png STATIC
121         libpng/png.c
122         libpng/pngerror.c
123         libpng/pngget.c
124         libpng/pngmem.c
125         libpng/pngpread.c
126         libpng/pngread.c
127         libpng/pngrio.c
128         libpng/pngrtran.c
129         libpng/pngrutil.c
130         libpng/pngset.c
131         libpng/pngtrans.c
132         libpng/pngwio.c
133         libpng/pngwrite.c
134         libpng/pngwtran.c
135         libpng/pngwutil.c
136     )
137     include_directories (libpng)
138     link_libraries (png)
139 endif (PNG_FOUND)
140
141 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
142
143 add_custom_command (
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
147 )
148
149 if (WIN32)
150     # d3d8.dll
151     #if (DirectX_D3D8_INCLUDE_DIR)
152     #    include_directories (${DirectX_D3D8_INCLUDE_DIR})
153     #    add_custom_command (
154     #        OUTPUT d3d8.cpp
155     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
156     #        DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py stdapi.py
157     #    )
158     #    add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
159     #    set_target_properties (d3d8 PROPERTIES PREFIX "")
160     #endif (DirectX_D3D8_INCLUDE_DIR)
161
162     # d3d9.dll
163     if (DirectX_D3DX9_INCLUDE_DIR)
164         include_directories (${DirectX_D3DX9_INCLUDE_DIR})
165         add_custom_command (
166             OUTPUT d3d9.cpp
167             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
168             DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
169         )
170         add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
171         set_target_properties (d3d9
172             PROPERTIES PREFIX ""
173             RUNTIME_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers
174             LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers
175         )
176     endif (DirectX_D3DX9_INCLUDE_DIR)
177
178     # d3d10.dll
179     #if (DirectX_D3D10_INCLUDE_DIR)
180     #    include_directories (${DirectX_D3D10_INCLUDE_DIR})
181     #    add_custom_command (
182     #        OUTPUT d3d10.cpp
183     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
184     #        DEPENDS d3d10misc.py winapi.py stdapi.py
185     #    )
186     #    add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
187     #    set_target_properties (d3d10 PROPERTIES PREFIX "")
188     #endif (DirectX_D3D10_INCLUDE_DIR)
189
190     # opengl32.dll
191     add_custom_command (
192         OUTPUT wgltrace.cpp
193         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
194         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glenum.py winapi.py stdapi.py
195     )
196     add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_write.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
197     set_target_properties (wgltrace PROPERTIES
198         PREFIX ""
199         OUTPUT_NAME opengl32
200         RUNTIME_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers
201         LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers
202     )
203     if (MINGW)
204         set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
205     endif (MINGW)
206
207 else ()
208     include_directories (${X11_INCLUDE_DIR})
209
210     # libGL.so
211     add_custom_command (
212         OUTPUT glxtrace.cpp
213         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
214         DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glstate.py glenum.py stdapi.py
215     )
216
217     add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
218
219     set_target_properties (glxtrace PROPERTIES
220         # avoid the default "lib" prefix
221         PREFIX ""
222     )
223
224     # Prevent symbol relocations internal to our wrapper library to be
225     # overwritten by the application.
226     if (NOT APPLE)
227         set_target_properties (glxtrace PROPERTIES
228             LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
229         )
230     endif (NOT APPLE)
231
232     target_link_libraries (glxtrace dl)
233 endif ()
234
235 if (WIN32)
236     set (os os_win32.cpp)
237     set (glws glws_wgl.cpp)
238 else (WIN32)
239     set (os os_posix.cpp)
240     set (glws glws_glx.cpp)
241 endif (WIN32)
242
243 add_library (trace trace_model.cpp trace_parser.cpp trace_write.cpp ${os})
244
245 add_executable (tracedump tracedump.cpp)
246 target_link_libraries (tracedump trace)
247
248 add_custom_command (
249     OUTPUT glretrace_gl.cpp
250     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
251     DEPENDS glretrace.py retrace.py codegen.py glapi.py glenum.py stdapi.py
252 )
253
254 add_custom_command (
255     OUTPUT glretrace_state.cpp
256     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_state.cpp
257     DEPENDS glstate.py glapi.py glenum.py stdapi.py
258 )
259
260 include_directories (
261     ${CMAKE_CURRENT_BINARY_DIR}
262     ${OPENGL_INCLUDE_PATH}
263 )
264
265 add_executable (glretrace
266     glretrace_gl.cpp
267     glretrace_main.cpp
268     glretrace_state.cpp
269     retrace.cpp
270     ${glws}
271     image.cpp 
272     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
273 )
274
275 set_property (
276     TARGET glretrace
277     APPEND
278     PROPERTY COMPILE_DEFINITIONS "RETRACE"
279 )
280
281 target_link_libraries (glretrace
282     trace
283     ${OPENGL_gl_LIBRARY}
284 )
285
286 if (NOT WIN32)
287     target_link_libraries (glretrace ${X11_LIBRARIES})
288 endif (NOT WIN32)
289
290 if (QT4_FOUND AND QJSON_FOUND)
291     add_subdirectory(gui)
292 endif (QT4_FOUND AND QJSON_FOUND)