]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Some initial thoughts on the on-demand loading api.
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2
3 project (apitrace)
4
5
6 ##############################################################################
7 # Options
8 #
9 # We use a cached string variable instead of the standard (boolean) OPTION
10 # command so that we can default to auto-detecting optional depencies, while
11 # still providing a mechanism to force/disable these optional dependencies, as
12 # prescribed in http://www.gentoo.org/proj/en/qa/automagic.xml
13
14 set (ENABLE_GUI "AUTO" CACHE STRING "Enable Qt GUI.")
15
16
17 ##############################################################################
18 # Find dependencies
19
20 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
21
22 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
23
24 find_package (PythonInterp REQUIRED)
25 find_package (OpenGL REQUIRED)
26
27 if (ENABLE_GUI)
28     if (NOT (ENABLE_GUI STREQUAL "AUTO"))
29         set (REQUIRE_GUI REQUIRED)
30     endif ()
31     find_package (Qt4 4.7 COMPONENTS QtCore QtGui QtWebKit ${REQUIRE_GUI})
32     find_package (QJSON ${REQUIRE_GUI})
33 endif ()
34
35 if (NOT WIN32)
36     find_package (X11 REQUIRED)
37
38     # On Mac OS X, GLX is provided as a separate OpenGL implementation, different
39     # from the standard OpenGL framework which provides support for native Mac OS X
40     # applications.
41     if (APPLE)
42         find_path (X11_GL_INCLUDE_PATH GL/glx.h ${X11_INC_SEARCH_PATH})
43         if (NOT X11_GL_INCLUDE_PATH)
44             message (SEND_ERROR "Could not find GL/glx.h")
45         endif (NOT X11_GL_INCLUDE_PATH)
46         set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_GL_INCLUDE_PATH})
47
48         find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
49         if (NOT X11_GL_LIB)
50             message (SEND_ERROR "Could not find libGL.dylib")
51         endif (NOT X11_GL_LIB)
52     else ()
53         set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
54         set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
55     endif ()
56
57     include_directories (${X11_INCLUDE_DIR})
58 endif (NOT WIN32)
59
60 if (WIN32)
61     find_package (DirectX)
62 endif (WIN32)
63
64
65 ##############################################################################
66 # Set global build options
67
68 include (CheckCXXCompilerFlag)
69
70 if (WIN32)
71     # MSVC & MinGW only define & use APIENTRY
72     add_definitions (-DGLAPIENTRY=__stdcall)
73
74     # http://msdn.microsoft.com/en-us/library/aa383745.aspx
75     add_definitions (-D_WIN32_WINNT=0x0500 -DWINVER=0x0500)
76 else (WIN32)
77     CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
78     if (CXX_COMPILER_FLAG_VISIBILITY)
79         add_definitions ("-fvisibility=hidden")
80     endif (CXX_COMPILER_FLAG_VISIBILITY)
81 endif (WIN32)
82
83 if (MSVC)
84     # C99 includes for msvc
85     include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/msvc)
86
87     # Enable math constants defines
88     add_definitions (-D_USE_MATH_DEFINES)
89
90     # No min/max macros
91     add_definitions (-DNOMINMAX)
92
93     # Adjust warnings
94     add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
95     add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
96     add_definitions (-W4)
97     add_definitions (-wd4063) # not a valid value for switch of enum
98     add_definitions (-wd4127) # conditional expression is constant
99     add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
100     add_definitions (-wd4505) # unreferenced local function has been removed
101     add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
102     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
103     add_definitions (-wd4018) # signed/unsigned mismatch
104     
105     # Use static runtime
106     # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
107     foreach (flag_var
108         CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
109         CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
110     )
111         if (${flag_var} MATCHES "/MD")
112             string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
113         endif (${flag_var} MATCHES "/MD")
114     endforeach (flag_var)
115 else ()
116     # Adjust warnings
117     add_definitions (-Wall)
118     # XXX: it's safer to use ssize_t everywhere instead of disabling warning
119     add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
120 endif ()
121
122
123 # Put all executables into the same top level build directory, regardless of
124 # which subdirectory they are declared
125 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
126
127
128 ##############################################################################
129 # Bundled dependencies
130 #
131 # We always use the bundled zlib and libpng sources:
132 # - on Windows to make it easy to deploy the wrappers DLLs
133 # - on unices to prevent symbol collisions when tracing applications that link
134 # against other versions of these libraries
135
136 set (ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib)
137 set (ZLIB_LIBRARIES z_bundled)
138 add_subdirectory (thirdparty/zlib EXCLUDE_FROM_ALL)
139
140 include_directories (${ZLIB_INCLUDE_DIRS})
141 link_libraries (${ZLIB_LIBRARIES})
142
143 set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
144 set (SNAPPY_LIBRARIES snappy_bundled)
145 add_subdirectory (thirdparty/snappy EXCLUDE_FROM_ALL)
146
147 include_directories (${SNAPPY_INCLUDE_DIRS})
148 link_libraries (${SNAPPY_LIBRARIES})
149
150 set (PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libpng)
151 set (PNG_DEFINITIONS "")
152 set (PNG_LIBRARIES png_bundled)
153
154 add_subdirectory (thirdparty/libpng EXCLUDE_FROM_ALL)
155 include_directories (${PNG_INCLUDE_DIR})
156 add_definitions (${PNG_DEFINITIONS})
157 link_libraries (${PNG_LIBRARIES})
158
159 # For glext headers
160 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
161
162
163 ##############################################################################
164 # Common libraries / utilities
165
166 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
167
168 add_custom_command (
169     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
170     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
171     DEPENDS glproc.py dispatch.py wglapi.py glxapi.py cglapi.py glapi.py gltypes.py stdapi.py
172 )
173
174 if (WIN32)
175     set (os os_win32.cpp)
176     set (glws glws_wgl.cpp)
177 else (WIN32)
178     set (os os_posix.cpp)
179     set (glws glws_glx.cpp)
180 endif (WIN32)
181
182 add_library (common
183     trace_file.cpp
184     trace_snappyfile.cpp
185     trace_model.cpp
186     trace_parser.cpp
187     trace_writer.cpp
188     trace_local_writer.cpp
189     trace_model_writer.cpp
190     trace_loader.cpp
191     image.cpp
192     image_bmp.cpp
193     image_pnm.cpp
194     image_png.cpp
195     ${os}
196 )
197
198 set_target_properties (common PROPERTIES
199     # Ensure it can be statically linked in shared libraries
200     COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}"
201 )
202
203 link_libraries (common)
204
205 add_executable (tracedump tracedump.cpp)
206 install (TARGETS tracedump RUNTIME DESTINATION bin) 
207
208 add_executable (loadertest loadertest.cpp)
209 install (TARGETS loadertest RUNTIME DESTINATION bin)
210
211 ##############################################################################
212 # API tracers
213
214 if (WIN32)
215     # ddraw.dll
216     if (DirectX_D3D_INCLUDE_DIR)
217         include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
218         add_custom_command (
219             OUTPUT ddraw.cpp
220             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d.py > ${CMAKE_CURRENT_BINARY_DIR}/ddraw.cpp
221             DEPENDS d3d.py d3dtypes.py d3dcaps.py ddraw.py trace.py winapi.py stdapi.py
222         )
223         add_library (ddraw MODULE ddraw.def ddraw.cpp)
224         set_target_properties (ddraw
225             PROPERTIES PREFIX ""
226             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
227             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
228         )
229         install (TARGETS ddraw LIBRARY DESTINATION wrappers)
230     endif (DirectX_D3D_INCLUDE_DIR)
231
232     # d3d8.dll
233     if (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
234         include_directories (SYSTEM ${DirectX_D3D8_INCLUDE_DIR} ${DirectX_D3DX9_INCLUDE_DIR})
235         add_custom_command (
236             OUTPUT d3d8.cpp
237             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
238             DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py winapi.py stdapi.py
239         )
240         add_library (d3d8 MODULE d3d8.def d3d8.cpp d3dshader.cpp)
241         set_target_properties (d3d8
242             PROPERTIES PREFIX ""
243             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
244             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
245         )
246         install (TARGETS d3d8 LIBRARY DESTINATION wrappers)
247     endif (DirectX_D3D8_INCLUDE_DIR AND DirectX_D3DX9_INCLUDE_DIR)
248
249     # d3d9.dll
250     if (DirectX_D3DX9_INCLUDE_DIR)
251         include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
252         add_custom_command (
253             OUTPUT d3d9.cpp
254             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
255             DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py winapi.py stdapi.py
256         )
257         add_library (d3d9 MODULE d3d9.def d3d9.cpp d3dshader.cpp)
258         set_target_properties (d3d9
259             PROPERTIES PREFIX ""
260             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
261             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
262         )
263         install (TARGETS d3d9 LIBRARY DESTINATION wrappers)
264     endif (DirectX_D3DX9_INCLUDE_DIR)
265
266     # d3d10.dll
267     #if (DirectX_D3D10_INCLUDE_DIR)
268     #    include_directories (SYSTEM ${DirectX_D3D10_INCLUDE_DIR})
269     #    add_custom_command (
270     #        OUTPUT d3d10.cpp
271     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
272     #        DEPENDS d3d10misc.py winapi.py stdapi.py
273     #    )
274     #    add_library (d3d10 MODULE d3d10.def d3d10.cpp)
275     #    set_target_properties (d3d10 PROPERTIES PREFIX "")
276     #    install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
277     #endif (DirectX_D3D10_INCLUDE_DIR)
278
279     # opengl32.dll
280     add_custom_command (
281         OUTPUT wgltrace.cpp
282         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
283         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
284     )
285     add_library (wgltrace MODULE opengl32.def
286         wgltrace.cpp
287         glcaps.cpp
288         ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
289     )
290     set_target_properties (wgltrace PROPERTIES
291         PREFIX ""
292         OUTPUT_NAME opengl32
293         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
294         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
295     )
296     if (MINGW)
297         set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
298     endif (MINGW)
299     install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
300
301 elseif (APPLE)
302     # OpenGL framework
303     add_custom_command (
304         OUTPUT cgltrace.cpp
305         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/cgltrace.cpp
306         DEPENDS cgltrace.py gltrace.py trace.py cglapi.py glapi.py glparams.py gltypes.py stdapi.py
307     )
308
309     add_library (cgltrace SHARED
310         cgltrace.cpp
311         glcaps.cpp
312         ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
313     )
314
315     set_target_properties (cgltrace PROPERTIES
316         # OpenGL framework name
317         PREFIX "" OUTPUT_NAME "OpenGL" SUFFIX ""
318         # Specificy the version and reexport GLU symbols
319         LINK_FLAGS "-compatibility_version 1 -current_version 1.0.0 -Wl,-reexport_library,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib"
320         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
321         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
322     )
323
324     target_link_libraries (cgltrace dl)
325
326     install (TARGETS cgltrace LIBRARY DESTINATION wrappers)
327 else ()
328     # libGL.so
329     add_custom_command (
330         OUTPUT glxtrace.cpp
331         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
332         DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glparams.py gltypes.py stdapi.py
333     )
334
335     add_library (glxtrace SHARED
336         ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
337         glxtrace.cpp
338         glcaps.cpp
339         glsnapshot.cpp
340     )
341
342     set_target_properties (glxtrace PROPERTIES
343         # avoid the default "lib" prefix
344         PREFIX ""
345     )
346
347     # Prevent symbol relocations internal to our wrapper library to be
348     # overwritten by the application.
349     set_target_properties (glxtrace PROPERTIES
350         LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
351     )
352
353     target_link_libraries (glxtrace dl ${X11_X11_LIB})
354
355     install (TARGETS glxtrace LIBRARY DESTINATION lib)
356 endif ()
357
358
359 ##############################################################################
360 # API retracers
361
362 add_custom_command (
363     OUTPUT glretrace_gl.cpp
364     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
365     DEPENDS glretrace.py retrace.py codegen.py glapi.py gltypes.py stdapi.py
366 )
367
368 add_custom_command (
369     OUTPUT glstate_params.cpp
370     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
371     DEPENDS glstate.py glparams.py gltypes.py stdapi.py
372 )
373
374 include_directories (
375     ${CMAKE_CURRENT_BINARY_DIR}
376     ${OPENGL_INCLUDE_PATH}
377 )
378
379 add_executable (glretrace
380     glretrace_gl.cpp
381     glretrace_cgl.cpp
382     glretrace_glx.cpp
383     glretrace_wgl.cpp
384     glretrace_main.cpp
385     glstate.cpp
386     glstate_params.cpp
387     retrace.cpp
388     ${glws}
389     image.cpp 
390     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
391 )
392
393 set_property (
394     TARGET glretrace
395     APPEND
396     PROPERTY COMPILE_DEFINITIONS "RETRACE"
397 )
398
399 target_link_libraries (glretrace
400     common
401 )
402
403 if (WIN32)
404     target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
405 elseif (APPLE)
406     # XXX: We use GLX on MacOSX, which is in a separate library.
407     target_link_libraries (glretrace
408         ${X11_GL_LIB}
409         ${X11_X11_LIB}
410         "-framework ApplicationServices" # CGS*
411         ${OPENGL_gl_LIBRARY} # CGL*
412     )
413 else ()
414     target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
415 endif ()
416
417 install (TARGETS glretrace RUNTIME DESTINATION bin) 
418
419
420 ##############################################################################
421 # GUI
422
423 if (ENABLE_GUI AND QT4_FOUND AND QJSON_FOUND)
424     add_subdirectory(gui)
425 endif ()
426
427
428 ##############################################################################
429 # Packaging
430
431 install (FILES LICENSE README.markdown TODO.markdown DESTINATION doc)
432
433 set (CPACK_PACKAGE_VERSION_MAJOR "1")
434 set (CPACK_PACKAGE_VERSION_MINOR "0")
435
436 # Use current date in YYYYMMDD format as patch number 
437 execute_process (
438     COMMAND ${PYTHON_EXECUTABLE} -c "import time, sys; sys.stdout.write(time.strftime('%Y%m%d'))"
439     OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
440 )
441
442 # See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
443 if (WIN32)
444     set (CPACK_GENERATOR "ZIP")
445 elseif (APPLE)
446     set (CPACK_GENERATOR "DragNDrop")
447 else ()
448     set (CPACK_GENERATOR "TBZ2")
449 endif ()
450
451 include(CPack)