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