]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
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 (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
63     add_definitions (-wd4505) # unreferenced local function has been removed
64     add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
65     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
66     add_definitions (-wd4018) # signed/unsigned mismatch
67     
68     # Use static runtime
69     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
70     foreach (flag_var
71         CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
72         CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
73     )
74         if (${flag_var} MATCHES "/MD")
75             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
76         endif (${flag_var} MATCHES "/MD")
77     endforeach (flag_var)
78 else ()
79     # Adjust warnings
80     add_definitions (-Wall)
81     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
82     add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
83 endif ()
84
85
86 # Put all executables into the same top level build directory, regardless of
87 # which subdirectory they are declared
88 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
89
90 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
91
92
93 ##############################################################################
94 # Bundled dependencies
95
96 # Use bundled ZLIB if system one can't be found
97 if (ZLIB_FOUND)
98     include_directories (${ZLIB_INCLUDE_DIRS})
99     link_libraries (${ZLIB_LIBRARIES})
100 else (ZLIB_FOUND)
101     add_subdirectory (zlib)
102     include_directories (zlib)
103     link_libraries (zlib)
104 endif (ZLIB_FOUND)
105
106 # Use bundled LIBPNG if system one can't be found
107 if (PNG_FOUND)
108     include_directories (${PNG_INCLUDE_DIR})
109     add_definitions (${PNG_DEFINITIONS})
110     link_libraries (${PNG_LIBRARIES})
111 else (PNG_FOUND)
112     add_library (png STATIC
113         libpng/png.c
114         libpng/pngerror.c
115         libpng/pngget.c
116         libpng/pngmem.c
117         libpng/pngpread.c
118         libpng/pngread.c
119         libpng/pngrio.c
120         libpng/pngrtran.c
121         libpng/pngrutil.c
122         libpng/pngset.c
123         libpng/pngtrans.c
124         libpng/pngwio.c
125         libpng/pngwrite.c
126         libpng/pngwtran.c
127         libpng/pngwutil.c
128     )
129     include_directories (libpng)
130     link_libraries (png)
131 endif (PNG_FOUND)
132
133
134 ##############################################################################
135 # Common libraries / utilities
136
137 add_custom_command (
138     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
139     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
140     DEPENDS glproc.py dispatch.py wglapi.py glxapi.py cglapi.py glapi.py gltypes.py stdapi.py
141 )
142
143 if (WIN32)
144     set (os os_win32.cpp)
145     set (glws glws_wgl.cpp)
146 else (WIN32)
147     set (os os_posix.cpp)
148     set (glws glws_glx.cpp)
149 endif (WIN32)
150
151 add_library (trace trace_model.cpp trace_parser.cpp trace_writer.cpp ${os})
152
153 add_executable (tracedump tracedump.cpp)
154 target_link_libraries (tracedump trace)
155 install (TARGETS tracedump RUNTIME DESTINATION bin) 
156
157
158 ##############################################################################
159 # API tracers
160
161 if (WIN32)
162     # d3d8.dll
163     if (DirectX_D3D8_INCLUDE_DIR)
164         include_directories (${DirectX_D3D8_INCLUDE_DIR})
165         add_custom_command (
166             OUTPUT d3d8.cpp
167             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
168             DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
169         )
170         add_library (d3d8 SHARED d3d8.def d3d8.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
171         set_target_properties (d3d8
172             PROPERTIES PREFIX ""
173             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
174             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
175         )
176         install (TARGETS d3d8 RUNTIME DESTINATION wrappers)
177     endif (DirectX_D3D8_INCLUDE_DIR)
178
179     # d3d9.dll
180     if (DirectX_D3DX9_INCLUDE_DIR)
181         include_directories (${DirectX_D3DX9_INCLUDE_DIR})
182         add_custom_command (
183             OUTPUT d3d9.cpp
184             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
185             DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
186         )
187         add_library (d3d9 SHARED d3d9.def d3d9.cpp d3dshader.cpp trace_writer.cpp os_win32.cpp)
188         set_target_properties (d3d9
189             PROPERTIES PREFIX ""
190             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
191             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
192         )
193         install (TARGETS d3d9 RUNTIME DESTINATION wrappers)
194     endif (DirectX_D3DX9_INCLUDE_DIR)
195
196     # d3d10.dll
197     #if (DirectX_D3D10_INCLUDE_DIR)
198     #    include_directories (${DirectX_D3D10_INCLUDE_DIR})
199     #    add_custom_command (
200     #        OUTPUT d3d10.cpp
201     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
202     #        DEPENDS d3d10misc.py winapi.py stdapi.py
203     #    )
204     #    add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_writer.cpp os_win32.cpp)
205     #    set_target_properties (d3d10 PROPERTIES PREFIX "")
206     #    install (TARGETS d3d10 RUNTIME DESTINATION wrappers)
207     #endif (DirectX_D3D10_INCLUDE_DIR)
208
209     # opengl32.dll
210     add_custom_command (
211         OUTPUT wgltrace.cpp
212         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
213         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
214     )
215     add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
216     set_target_properties (wgltrace PROPERTIES
217         PREFIX ""
218         OUTPUT_NAME opengl32
219         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
220         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
221     )
222     if (MINGW)
223         set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
224     endif (MINGW)
225     install (TARGETS wgltrace RUNTIME DESTINATION wrappers)
226
227 elseif (APPLE)
228     include_directories (${X11_INCLUDE_DIR})
229
230     # libGL.dylib
231     add_custom_command (
232         OUTPUT cgltrace.cpp
233         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
234         DEPENDS cgltrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
235     )
236
237     add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
238
239     set_target_properties (cgltrace PROPERTIES
240         # libGL.dylib
241         OUTPUT_NAME GL
242         # match the version
243         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0"
244         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
245         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
246     )
247
248     target_link_libraries (cgltrace dl)
249
250     # Symbolic link from system's libGL.dylib
251     add_custom_command (
252         TARGET cgltrace
253         COMMAND ln -sf /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib ${PROJECT_BINARY_DIR}/wrappers/libGL.system.dylib
254     )
255
256     install (TARGETS cgltrace LIBRARY DESTINATION lib)
257 else ()
258     include_directories (${X11_INCLUDE_DIR})
259
260     # libGL.so
261     add_custom_command (
262         OUTPUT glxtrace.cpp
263         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
264         DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
265     )
266
267     add_library (glxtrace SHARED glxtrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
268
269     set_target_properties (glxtrace PROPERTIES
270         # avoid the default "lib" prefix
271         PREFIX ""
272     )
273
274     # Prevent symbol relocations internal to our wrapper library to be
275     # overwritten by the application.
276     set_target_properties (glxtrace PROPERTIES
277         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
278     )
279
280     target_link_libraries (glxtrace dl)
281     
282     install (TARGETS glxtrace LIBRARY DESTINATION lib)
283 endif ()
284
285
286 ##############################################################################
287 # API retracers
288
289 add_custom_command (
290     OUTPUT glretrace_gl.cpp
291     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
292     DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
293 )
294
295 add_custom_command (
296     OUTPUT glstate_params.cpp
297     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
298     DEPENDS glstate.py glparams.py gltypes.py stdapi.py
299 )
300
301 include_directories (
302     ${CMAKE_CURRENT_BINARY_DIR}
303     ${OPENGL_INCLUDE_PATH}
304 )
305
306 add_executable (glretrace
307     glretrace_gl.cpp
308     glretrace_cgl.cpp
309     glretrace_glx.cpp
310     glretrace_wgl.cpp
311     glretrace_main.cpp
312     glstate.cpp
313     glstate_params.cpp
314     retrace.cpp
315     ${glws}
316     image.cpp 
317     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
318 )
319
320 set_property (
321     TARGET glretrace
322     APPEND
323     PROPERTY COMPILE_DEFINITIONS "RETRACE"
324 )
325
326 target_link_libraries (glretrace
327     trace
328     ${OPENGL_gl_LIBRARY}
329 )
330
331 if (NOT WIN32)
332     target_link_libraries (glretrace ${X11_X11_LIB})
333
334     # We use GLX on MacOSX, which is in a separate library
335     if (APPLE)
336         find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
337         find_library (APPLICATIONSERVICES ApplicationServices)
338         target_link_libraries (glretrace ${X11_GL_LIB} ${APPLICATIONSERVICES})
339     endif (APPLE)
340 endif (NOT WIN32)
341
342 install (TARGETS glretrace RUNTIME DESTINATION bin) 
343
344
345 ##############################################################################
346 # GUI
347
348 if (QT4_FOUND AND QJSON_FOUND)
349     add_subdirectory(gui)
350 endif (QT4_FOUND AND QJSON_FOUND)
351
352
353 ##############################################################################
354 # Packaging
355
356 install (FILES LICENSE README TODO DESTINATION doc)
357
358 set (CPACK_PACKAGE_VERSION_MAJOR "1")
359 set (CPACK_PACKAGE_VERSION_MINOR "0")
360
361 # Use current date in YYYYMMDD format as patch number 
362 execute_process (
363     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
364     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
365 )
366
367 if (WIN32)
368     set (CPACK_GENERATOR "ZIP")
369 else (WIN32)
370     set (CPACK_GENERATOR "TGZ")
371 endif (WIN32)
372
373 include(CPack)