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