]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
First stab at binary trace and retracing.
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.6)
2
3 project (apitrace)
4
5 find_package (PythonInterp REQUIRED)
6 find_package (OpenGL REQUIRED)
7 find_package (ZLIB)
8
9 find_package (GLUT)
10
11 find_library (GLEW_glew_LIBRARY GLEW
12         /usr/lib
13 )
14
15 find_path (GLEW_INCLUDE_DIR GL/glew.h
16       /usr/include/GL
17 )
18
19 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
20         # Nobody likes to include windows.h:
21         # - Microsoft's GL/gl.h header depends on windows.h but doesn't include it;
22         # - GLEW temporarily defines the necessary defines but undefines them later
23         # - certain GLUT distributions don't include it;
24         # - most of our programs are meant to be portable so don't include it.
25         #
26         # We could try to replicate the windows.h definitions required by
27         # GL/gl.h, but the build time savings don't compensate the constant
28         # headaches that brings, so instead we force windows.h to be included
29         # on every file.
30         if (MSVC)
31                 add_definitions (-FIwindows.h)
32         else (MSVC)
33                 add_definitions (--include windows.h)
34         endif (MSVC)
35
36         # MSVC & MinGW only define & use APIENTRY
37         add_definitions (-DGLAPIENTRY=__stdcall)
38
39         link_libraries (winmm)
40 endif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
41
42 if (MSVC)
43         # Enable math constants defines
44         add_definitions (-D_USE_MATH_DEFINES)
45
46         # Silence several MSVC pedantic warnings
47         add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
48         add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
49         
50         add_definitions (-W4)
51 else ()
52         add_definitions (-Wall)
53 endif ()
54
55 # Use bundled ZLIB if system one can't be found
56 if (NOT ZLIB_FOUND)
57         add_library (zlib STATIC
58                 zlib/adler32.c
59                 zlib/compress.c
60                 zlib/crc32.c
61                 zlib/gzio.c
62                 zlib/uncompr.c
63                 zlib/deflate.c
64                 zlib/trees.c
65                 zlib/zutil.c
66                 zlib/inflate.c
67                 zlib/infback.c
68                 zlib/inftrees.c
69                 zlib/inffast.c
70         )
71
72         include_directories (zlib)
73         link_libraries (zlib)
74 else (NOT ZLIB_FOUND)
75         include_directories (${ZLIB_INCLUDE_DIRS})
76         link_libraries (${ZLIB_LIBRARIES})
77 endif (NOT ZLIB_FOUND)
78
79 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
80
81 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
82
83         # opengl32.dll
84         add_custom_command (
85                 OUTPUT opengl32.cpp
86                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
87                 DEPENDS opengl32.py gl.py windows.py base.py
88         )
89         add_library (opengl32 SHARED opengl32.def opengl32.cpp log.cpp os_win32.cpp)
90         set_target_properties (opengl32 PROPERTIES PREFIX "")
91
92 else ()
93
94         # libGL.so
95         add_custom_command (
96                 OUTPUT glx.cpp
97                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glx.py > ${CMAKE_CURRENT_BINARY_DIR}/glx.cpp
98                 DEPENDS glx.py gl.py dl.py base.py
99         )
100         add_library (glxtrace SHARED glx.cpp log.cpp os_posix.cpp)
101         set_target_properties (glxtrace PROPERTIES PREFIX "")
102         target_link_libraries (glxtrace dl)
103 endif ()
104
105 add_executable (dump dump.cpp trace_model.cpp)
106
107
108 if (GLEW_INCLUDE_DIR)
109         add_custom_command (
110                 OUTPUT glretrace.cpp
111                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace.cpp
112                 DEPENDS glretrace.py glx.py gl.py dl.py base.py
113         )
114
115         include_directories (
116                 ${OPENGL_INCLUDE_PATH}
117                 ${GLUT_INCLUDE_DIR}
118                 ${GLEW_INCLUDE_DIR}
119         )
120
121         add_executable (glretrace glretrace.cpp trace_model.cpp)
122
123         target_link_libraries (glretrace
124                 ${OPENGL_gl_LIBRARY}
125                 ${OPENGL_glu_LIBRARY}
126                 ${GLUT_glut_LIBRARY}
127                 ${GLEW_glew_LIBRARY}
128         )
129 endif (GLEW_INCLUDE_DIR)
130
131