]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Build fixes.
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2
3 project (apitrace)
4
5
6 ##############################################################################
7 # Find dependencies
8
9 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
10
11 set (CMAKE_USE_PYTHON_VERSION 2.6)
12
13 find_package (PythonInterp REQUIRED)
14 find_package (OpenGL REQUIRED)
15 find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit)
16 find_package (QJSON)
17
18 if (NOT WIN32)
19     # Always use the bundled zlib and libpng sources on Windows to make it easy
20     # to deploy the wrappers DLLs
21     find_package (ZLIB)
22     find_package (PNG)
23     find_package (X11 REQUIRED)
24
25 else (NOT WIN32)
26     find_package (DirectX)
27 endif (NOT WIN32)
28
29
30 ##############################################################################
31 # Set global build options
32
33 include (CheckCXXCompilerFlag)
34
35 if (WIN32)
36     # MSVC & MinGW only define & use APIENTRY
37     add_definitions (-DGLAPIENTRY=__stdcall)
38
39     # http://msdn.microsoft.com/en-us/library/aa383745.aspx
40     add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
41 else (WIN32)
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)
46 endif (WIN32)
47
48 if (MSVC)
49     # C99 includes for msvc
50     include_directories (msvc)
51
52     # Enable math constants defines
53     add_definitions (-D_USE_MATH_DEFINES)
54
55     # No min/max macros
56     add_definitions (-DNOMINMAX)
57
58     # Adjust warnings
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)
61     add_definitions (-W4)
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
68     
69     # Use static runtime
70     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
71     foreach (flag_var
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
74     )
75         if (${flag_var} MATCHES "/MD")
76             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
77         endif (${flag_var} MATCHES "/MD")
78     endforeach (flag_var)
79 else ()
80     # Adjust warnings
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
84 endif ()
85
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 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
92
93
94 ##############################################################################
95 # Bundled dependencies
96
97 # Use bundled ZLIB if system one can't be found
98 if (ZLIB_FOUND)
99     include_directories (${ZLIB_INCLUDE_DIRS})
100     link_libraries (${ZLIB_LIBRARIES})
101 else (ZLIB_FOUND)
102     add_subdirectory (zlib)
103     include_directories (zlib)
104     link_libraries (zlib)
105 endif (ZLIB_FOUND)
106
107 # Use bundled LIBPNG if system one can't be found
108 if (PNG_FOUND)
109     include_directories (${PNG_INCLUDE_DIR})
110     add_definitions (${PNG_DEFINITIONS})
111     link_libraries (${PNG_LIBRARIES})
112 else (PNG_FOUND)
113     add_library (png STATIC
114         libpng/png.c
115         libpng/pngerror.c
116         libpng/pngget.c
117         libpng/pngmem.c
118         libpng/pngpread.c
119         libpng/pngread.c
120         libpng/pngrio.c
121         libpng/pngrtran.c
122         libpng/pngrutil.c
123         libpng/pngset.c
124         libpng/pngtrans.c
125         libpng/pngwio.c
126         libpng/pngwrite.c
127         libpng/pngwtran.c
128         libpng/pngwutil.c
129     )
130     include_directories (libpng)
131     link_libraries (png)
132 endif (PNG_FOUND)
133
134
135 ##############################################################################
136 # Common libraries / utilities
137
138 add_custom_command (
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
142 )
143
144 if (WIN32)
145     set (os os_win32.cpp)
146     set (glws glws_wgl.cpp)
147 else (WIN32)
148     set (os os_posix.cpp)
149     set (glws glws_glx.cpp)
150 endif (WIN32)
151
152 add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp ${os})
153
154 add_executable (tracedump tracedump.cpp)
155 target_link_libraries (tracedump trace)
156 install (TARGETS tracedump RUNTIME DESTINATION bin) 
157
158
159 ##############################################################################
160 # API tracers
161
162 if (WIN32)
163     # ddraw.dll
164     if (DirectX_D3D_INCLUDE_DIR)
165         include_directories (${DirectX_D3D_INCLUDE_DIR})
166         add_custom_command (
167             OUTPUT ddraw.cpp
168             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d.py > ${CMAKE_CURRENT_BINARY_DIR}/ddraw.cpp
169             DEPENDS d3d.py d3dtypes.py d3dcaps.py ddraw.py trace.py winapi.py stdapi.py
170         )
171         add_library (ddraw SHARED ddraw.def ddraw.cpp trace_writer.cpp os_win32.cpp)
172         set_target_properties (ddraw
173             PROPERTIES PREFIX ""
174             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
175             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
176         )
177         install (TARGETS ddraw RUNTIME DESTINATION wrappers)
178     endif (DirectX_D3D_INCLUDE_DIR)
179
180     # d3d8.dll
181     if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
182         include_directories (${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
183         add_custom_command (
184             OUTPUT d3d8.cpp
185             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
186             DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
187         )
188         add_library (d3d8 SHARED d3d8.def d3d8.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
189         set_target_properties (d3d8
190             PROPERTIES PREFIX ""
191             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
192             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
193         )
194         install (TARGETS d3d8 RUNTIME DESTINATION wrappers)
195     endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
196
197     # d3d9.dll
198     if (DirectX_D3DX9_INCLUDE_DIR)
199         include_directories (${DirectX_D3DX9_INCLUDE_DIR})
200         add_custom_command (
201             OUTPUT d3d9.cpp
202             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
203             DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
204         )
205         add_library (d3d9 SHARED d3d9.def d3d9.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
206         set_target_properties (d3d9
207             PROPERTIES PREFIX ""
208             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
209             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
210         )
211         install (TARGETS d3d9 RUNTIME DESTINATION wrappers)
212     endif (DirectX_D3DX9_INCLUDE_DIR)
213
214     # d3d10.dll
215     #if (DirectX_D3D10_INCLUDE_DIR)
216     #    include_directories (${DirectX_D3D10_INCLUDE_DIR})
217     #    add_custom_command (
218     #        OUTPUT d3d10.cpp
219     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
220     #        DEPENDS d3d10misc.py winapi.py stdapi.py
221     #    )
222     #    add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_writer.cpp os_win32.cpp)
223     #    set_target_properties (d3d10 PROPERTIES PREFIX "")
224     #    install (TARGETS d3d10 RUNTIME DESTINATION wrappers)
225     #endif (DirectX_D3D10_INCLUDE_DIR)
226
227     # opengl32.dll
228     add_custom_command (
229         OUTPUT wgltrace.cpp
230         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
231         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
232     )
233     add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
234     set_target_properties (wgltrace PROPERTIES
235         PREFIX ""
236         OUTPUT_NAME opengl32
237         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
238         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
239     )
240     if (MINGW)
241         set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
242     endif (MINGW)
243     install (TARGETS wgltrace RUNTIME DESTINATION wrappers)
244
245 elseif (APPLE)
246     include_directories (${X11_INCLUDE_DIR})
247
248     # libGL.dylib
249     add_custom_command (
250         OUTPUT cgltrace.cpp
251         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
252         DEPENDS cgltrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
253     )
254
255     add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
256
257     set_target_properties (cgltrace PROPERTIES
258         # libGL.dylib
259         OUTPUT_NAME GL
260         # match the version
261         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0"
262         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
263         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
264     )
265
266     target_link_libraries (cgltrace dl)
267
268     # Symbolic link from system's libGL.dylib
269     add_custom_command (
270         TARGET cgltrace
271         COMMAND ln -sf /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib ${PROJECT_BINARY_DIR}/wrappers/libGL.system.dylib
272     )
273
274     install (TARGETS cgltrace LIBRARY DESTINATION lib)
275 else ()
276     include_directories (${X11_INCLUDE_DIR})
277
278     # libGL.so
279     add_custom_command (
280         OUTPUT glxtrace.cpp
281         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
282         DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
283     )
284
285     add_library (glxtrace SHARED glxtrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
286
287     set_target_properties (glxtrace PROPERTIES
288         # avoid the default "lib" prefix
289         PREFIX ""
290     )
291
292     # Prevent symbol relocations internal to our wrapper library to be
293     # overwritten by the application.
294     set_target_properties (glxtrace PROPERTIES
295         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
296     )
297
298     target_link_libraries (glxtrace dl)
299     
300     install (TARGETS glxtrace LIBRARY DESTINATION lib)
301 endif ()
302
303
304 ##############################################################################
305 # API retracers
306
307 add_custom_command (
308     OUTPUT glretrace_gl.cpp
309     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
310     DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
311 )
312
313 add_custom_command (
314     OUTPUT glstate_params.cpp
315     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
316     DEPENDS glstate.py glparams.py gltypes.py stdapi.py
317 )
318
319 include_directories (
320     ${CMAKE_CURRENT_BINARY_DIR}
321     ${OPENGL_INCLUDE_PATH}
322 )
323
324 add_executable (glretrace
325     glretrace_gl.cpp
326     glretrace_cgl.cpp
327     glretrace_glx.cpp
328     glretrace_wgl.cpp
329     glretrace_main.cpp
330     glstate.cpp
331     glstate_params.cpp
332     retrace.cpp
333     ${glws}
334     image.cpp 
335     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
336 )
337
338 set_property (
339     TARGET glretrace
340     APPEND
341     PROPERTY COMPILE_DEFINITIONS "RETRACE"
342 )
343
344 target_link_libraries (glretrace
345     trace
346     ${OPENGL_gl_LIBRARY}
347 )
348
349 if (NOT WIN32)
350     target_link_libraries (glretrace ${X11_X11_LIB})
351
352     # We use GLX on MacOSX, which is in a separate library
353     if (APPLE)
354         find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
355         find_library (APPLICATIONSERVICES ApplicationServices)
356         target_link_libraries (glretrace ${X11_GL_LIB} ${APPLICATIONSERVICES})
357     endif (APPLE)
358 endif (NOT WIN32)
359
360 install (TARGETS glretrace RUNTIME DESTINATION bin) 
361
362
363 ##############################################################################
364 # GUI
365
366 if (QT4_FOUND AND QJSON_FOUND)
367     add_subdirectory(gui)
368 endif (QT4_FOUND AND QJSON_FOUND)
369
370
371 ##############################################################################
372 # Packaging
373
374 install (FILES LICENSE README TODO DESTINATION doc)
375
376 set (CPACK_PACKAGE_VERSION_MAJOR "1")
377 set (CPACK_PACKAGE_VERSION_MINOR "0")
378
379 # Use current date in YYYYMMDD format as patch number 
380 execute_process (
381     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
382     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
383 )
384
385 if (WIN32)
386     set (CPACK_GENERATOR "ZIP")
387 else (WIN32)
388     set (CPACK_GENERATOR "TGZ")
389 endif (WIN32)
390
391 include(CPack)