]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Temporarily revert "Upgrade bundled zlib to 1.2.5."
[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 (-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
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
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})
91
92 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
93
94
95 ##############################################################################
96 # Bundled dependencies
97
98 # Use bundled ZLIB if system one can't be found
99 if (ZLIB_FOUND)
100     include_directories (${ZLIB_INCLUDE_DIRS})
101     link_libraries (${ZLIB_LIBRARIES})
102 else (ZLIB_FOUND)
103     add_library (zlib STATIC
104         zlib/adler32.c
105         zlib/compress.c
106         zlib/crc32.c
107         zlib/gzio.c
108         zlib/uncompr.c
109         zlib/deflate.c
110         zlib/trees.c
111         zlib/zutil.c
112         zlib/inflate.c
113         zlib/infback.c
114         zlib/inftrees.c
115         zlib/inffast.c
116     )
117     include_directories (zlib)
118     link_libraries (zlib)
119 endif (ZLIB_FOUND)
120
121 # Use bundled LIBPNG if system one can't be found
122 if (PNG_FOUND)
123     include_directories (${PNG_INCLUDE_DIR})
124     add_definitions (${PNG_DEFINITIONS})
125     link_libraries (${PNG_LIBRARIES})
126 else (PNG_FOUND)
127     add_library (png STATIC
128         libpng/png.c
129         libpng/pngerror.c
130         libpng/pngget.c
131         libpng/pngmem.c
132         libpng/pngpread.c
133         libpng/pngread.c
134         libpng/pngrio.c
135         libpng/pngrtran.c
136         libpng/pngrutil.c
137         libpng/pngset.c
138         libpng/pngtrans.c
139         libpng/pngwio.c
140         libpng/pngwrite.c
141         libpng/pngwtran.c
142         libpng/pngwutil.c
143     )
144     include_directories (libpng)
145     link_libraries (png)
146 endif (PNG_FOUND)
147
148
149 ##############################################################################
150 # Common libraries / utilities
151
152 add_custom_command (
153     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
154     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
155     DEPENDS glproc.py dispatch.py wglapi.py glxapi.py cglapi.py glapi.py gltypes.py stdapi.py
156 )
157
158 if (WIN32)
159     set (os os_win32.cpp)
160     set (glws glws_wgl.cpp)
161 else (WIN32)
162     set (os os_posix.cpp)
163     set (glws glws_glx.cpp)
164 endif (WIN32)
165
166 add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp ${os})
167
168 add_executable (tracedump tracedump.cpp)
169 target_link_libraries (tracedump trace)
170 install (TARGETS tracedump RUNTIME DESTINATION bin) 
171
172
173 ##############################################################################
174 # API tracers
175
176 if (WIN32)
177     # ddraw.dll
178     if (DirectX_D3D_INCLUDE_DIR)
179         include_directories (${DirectX_D3D_INCLUDE_DIR})
180         add_custom_command (
181             OUTPUT ddraw.cpp
182             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d.py > ${CMAKE_CURRENT_BINARY_DIR}/ddraw.cpp
183             DEPENDS d3d.py d3dtypes.py d3dcaps.py ddraw.py trace.py winapi.py stdapi.py
184         )
185         add_library (ddraw SHARED ddraw.def ddraw.cpp trace_writer.cpp os_win32.cpp)
186         set_target_properties (ddraw
187             PROPERTIES PREFIX ""
188             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
189             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
190         )
191         install (TARGETS ddraw RUNTIME DESTINATION wrappers)
192     endif (DirectX_D3D_INCLUDE_DIR)
193
194     # d3d8.dll
195     if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
196         include_directories (${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
197         add_custom_command (
198             OUTPUT d3d8.cpp
199             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
200             DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
201         )
202         add_library (d3d8 SHARED d3d8.def d3d8.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
203         set_target_properties (d3d8
204             PROPERTIES PREFIX ""
205             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
206             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
207         )
208         install (TARGETS d3d8 RUNTIME DESTINATION wrappers)
209     endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
210
211     # d3d9.dll
212     if (DirectX_D3DX9_INCLUDE_DIR)
213         include_directories (${DirectX_D3DX9_INCLUDE_DIR})
214         add_custom_command (
215             OUTPUT d3d9.cpp
216             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
217             DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
218         )
219         add_library (d3d9 SHARED d3d9.def d3d9.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
220         set_target_properties (d3d9
221             PROPERTIES PREFIX ""
222             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
223             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
224         )
225         install (TARGETS d3d9 RUNTIME DESTINATION wrappers)
226     endif (DirectX_D3DX9_INCLUDE_DIR)
227
228     # d3d10.dll
229     #if (DirectX_D3D10_INCLUDE_DIR)
230     #    include_directories (${DirectX_D3D10_INCLUDE_DIR})
231     #    add_custom_command (
232     #        OUTPUT d3d10.cpp
233     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
234     #        DEPENDS d3d10misc.py winapi.py stdapi.py
235     #    )
236     #    add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_writer.cpp os_win32.cpp)
237     #    set_target_properties (d3d10 PROPERTIES PREFIX "")
238     #    install (TARGETS d3d10 RUNTIME DESTINATION wrappers)
239     #endif (DirectX_D3D10_INCLUDE_DIR)
240
241     # opengl32.dll
242     add_custom_command (
243         OUTPUT wgltrace.cpp
244         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
245         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
246     )
247     add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
248     set_target_properties (wgltrace PROPERTIES
249         PREFIX ""
250         OUTPUT_NAME opengl32
251         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
252         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
253     )
254     if (MINGW)
255         set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
256     endif (MINGW)
257     install (TARGETS wgltrace RUNTIME DESTINATION wrappers)
258
259 elseif (APPLE)
260     include_directories (${X11_INCLUDE_DIR})
261
262     # libGL.dylib
263     add_custom_command (
264         OUTPUT cgltrace.cpp
265         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
266         DEPENDS cgltrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
267     )
268
269     add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
270
271     set_target_properties (cgltrace PROPERTIES
272         # libGL.dylib
273         OUTPUT_NAME GL
274         # match the version
275         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0"
276         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
277         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
278     )
279
280     target_link_libraries (cgltrace dl)
281
282     # Symbolic link from system's libGL.dylib
283     add_custom_command (
284         TARGET cgltrace
285         COMMAND ln -sf /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib ${PROJECT_BINARY_DIR}/wrappers/libGL.system.dylib
286     )
287
288     install (TARGETS cgltrace LIBRARY DESTINATION lib)
289 else ()
290     include_directories (${X11_INCLUDE_DIR})
291
292     # libGL.so
293     add_custom_command (
294         OUTPUT glxtrace.cpp
295         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
296         DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
297     )
298
299     add_library (glxtrace SHARED glxtrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
300
301     set_target_properties (glxtrace PROPERTIES
302         # avoid the default "lib" prefix
303         PREFIX ""
304     )
305
306     # Prevent symbol relocations internal to our wrapper library to be
307     # overwritten by the application.
308     set_target_properties (glxtrace PROPERTIES
309         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
310     )
311
312     target_link_libraries (glxtrace dl)
313     
314     install (TARGETS glxtrace LIBRARY DESTINATION lib)
315 endif ()
316
317
318 ##############################################################################
319 # API retracers
320
321 add_custom_command (
322     OUTPUT glretrace_gl.cpp
323     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
324     DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
325 )
326
327 add_custom_command (
328     OUTPUT glstate_params.cpp
329     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
330     DEPENDS glstate.py glparams.py gltypes.py stdapi.py
331 )
332
333 include_directories (
334     ${CMAKE_CURRENT_BINARY_DIR}
335     ${OPENGL_INCLUDE_PATH}
336 )
337
338 add_executable (glretrace
339     glretrace_gl.cpp
340     glretrace_cgl.cpp
341     glretrace_glx.cpp
342     glretrace_wgl.cpp
343     glretrace_main.cpp
344     glstate.cpp
345     glstate_params.cpp
346     retrace.cpp
347     ${glws}
348     image.cpp 
349     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
350 )
351
352 set_property (
353     TARGET glretrace
354     APPEND
355     PROPERTY COMPILE_DEFINITIONS "RETRACE"
356 )
357
358 target_link_libraries (glretrace
359     trace
360     ${OPENGL_gl_LIBRARY}
361 )
362
363 if (NOT WIN32)
364     target_link_libraries (glretrace ${X11_X11_LIB})
365
366     # We use GLX on MacOSX, which is in a separate library
367     if (APPLE)
368         find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
369         find_library (APPLICATIONSERVICES ApplicationServices)
370         target_link_libraries (glretrace ${X11_GL_LIB} ${APPLICATIONSERVICES})
371     endif (APPLE)
372 endif (NOT WIN32)
373
374 install (TARGETS glretrace RUNTIME DESTINATION bin) 
375
376
377 ##############################################################################
378 # GUI
379
380 if (QT4_FOUND AND QJSON_FOUND)
381     add_subdirectory(gui)
382 endif (QT4_FOUND AND QJSON_FOUND)
383
384
385 ##############################################################################
386 # Packaging
387
388 install (FILES LICENSE README TODO DESTINATION doc)
389
390 set (CPACK_PACKAGE_VERSION_MAJOR "1")
391 set (CPACK_PACKAGE_VERSION_MINOR "0")
392
393 # Use current date in YYYYMMDD format as patch number 
394 execute_process (
395     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
396     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
397 )
398
399 if (WIN32)
400     set (CPACK_GENERATOR "ZIP")
401 else (WIN32)
402     set (CPACK_GENERATOR "TGZ")
403 endif (WIN32)
404
405 include(CPack)