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