]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Fix MacOSX build.
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2
3 include (CheckCXXCompilerFlag)
4
5 project (apitrace)
6
7 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
8
9 # Set default built type
10 if (NOT CMAKE_BUILD_TYPE)
11     set (CMAKE_BUILD_TYPE Debug
12         CACHE
13         STRING "Choose the build type, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel."
14         FORCE)
15 endif (NOT CMAKE_BUILD_TYPE)
16
17 set (CMAKE_USE_PYTHON_VERSION 2.6)
18
19 find_package (PythonInterp REQUIRED)
20 find_package (OpenGL REQUIRED)
21 find_package (Qt4 COMPONENTS QtCore QtGui QtWebKit)
22 find_package (QJSON)
23
24 if (NOT WIN32)
25     # Always use the bundled zlib and libpng sources on Windows to make it easy
26     # to deploy the wrappers DLLs
27     find_package (ZLIB)
28     find_package (PNG)
29     find_package (X11 REQUIRED)
30
31     # We use GLX on MacOSX, which is in a separate library
32     if (APPLE)
33         find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
34         set(X11_LIBRARIES ${X11_LIBRARIES} ${X11_GL_LIB})
35     endif (APPLE)
36 else (NOT WIN32)
37     find_package (DirectX)
38 endif (NOT WIN32)
39
40 if (WIN32)
41     # MSVC & MinGW only define & use APIENTRY
42     add_definitions (-DGLAPIENTRY=__stdcall)
43 else (WIN32)
44     CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
45     if (CXX_COMPILER_FLAG_VISIBILITY)
46         add_definitions ("-fvisibility=hidden")
47     endif (CXX_COMPILER_FLAG_VISIBILITY)
48 endif (WIN32)
49
50 if (MSVC)
51     # C99 includes for msvc
52     include_directories (msvc)
53
54     # Enable math constants defines
55     add_definitions (-D_USE_MATH_DEFINES)
56
57     # No min/max macros
58     add_definitions (-DNOMINMAX)
59
60     # Adjust warnings
61     add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
62     add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
63     add_definitions (-W4)
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 # Put all executables into the same top level build directory, regardless of
88 # which subdirectory they are declared
89 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
90
91 # Use bundled ZLIB if system one can't be found
92 if (ZLIB_FOUND)
93     include_directories (${ZLIB_INCLUDE_DIRS})
94     link_libraries (${ZLIB_LIBRARIES})
95 else (ZLIB_FOUND)
96     add_library (zlib STATIC
97         zlib/adler32.c
98         zlib/compress.c
99         zlib/crc32.c
100         zlib/gzio.c
101         zlib/uncompr.c
102         zlib/deflate.c
103         zlib/trees.c
104         zlib/zutil.c
105         zlib/inflate.c
106         zlib/infback.c
107         zlib/inftrees.c
108         zlib/inffast.c
109     )
110     include_directories (zlib)
111     link_libraries (zlib)
112 endif (ZLIB_FOUND)
113
114 # Use bundled LIBPNG if system one can't be found
115 if (PNG_FOUND)
116     include_directories (${PNG_INCLUDE_DIR})
117     add_definitions (${PNG_DEFINITIONS})
118     link_libraries (${PNG_LIBRARIES})
119 else (PNG_FOUND)
120     add_library (png STATIC
121         libpng/png.c
122         libpng/pngerror.c
123         libpng/pngget.c
124         libpng/pngmem.c
125         libpng/pngpread.c
126         libpng/pngread.c
127         libpng/pngrio.c
128         libpng/pngrtran.c
129         libpng/pngrutil.c
130         libpng/pngset.c
131         libpng/pngtrans.c
132         libpng/pngwio.c
133         libpng/pngwrite.c
134         libpng/pngwtran.c
135         libpng/pngwutil.c
136     )
137     include_directories (libpng)
138     link_libraries (png)
139 endif (PNG_FOUND)
140
141 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
142
143 add_custom_command (
144     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
145     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
146     DEPENDS glproc.py dispatch.py wglapi.py glxapi.py glapi.py glenum.py stdapi.py
147 )
148
149 if (WIN32)
150     # Put wrappers in a separate directory
151     set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers)
152
153     # d3d8.dll
154     #if (DirectX_D3D8_FOUND)
155     #    include_directories (${DirectX_D3D8_INCLUDE_DIR})
156     #    add_custom_command (
157     #        OUTPUT d3d8.cpp
158     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
159     #        DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py stdapi.py
160     #    )
161     #    add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
162     #    set_target_properties (d3d8 PROPERTIES PREFIX "")
163     #endif (DirectX_D3D8_FOUND)
164
165     # d3d9.dll
166     if (DirectX_D3DX9_FOUND)
167         include_directories (${DirectX_D3DX9_INCLUDE_DIR})
168         add_custom_command (
169             OUTPUT d3d9.cpp
170             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
171             DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
172         )
173         add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
174         set_target_properties (d3d9 PROPERTIES PREFIX "")
175     endif (DirectX_D3DX9_FOUND)
176
177     # d3d10.dll
178     #if (DirectX_D3D10_FOUND)
179     #    include_directories (${DirectX_D3D10_INCLUDE_DIR})
180     #    add_custom_command (
181     #        OUTPUT d3d10.cpp
182     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
183     #        DEPENDS d3d10misc.py winapi.py stdapi.py
184     #    )
185     #    add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
186     #    set_target_properties (d3d10 PROPERTIES PREFIX "")
187     #endif (DirectX_D3D10_FOUND)
188
189     # opengl32.dll
190     add_custom_command (
191         OUTPUT wgltrace.cpp
192         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
193         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glenum.py winapi.py stdapi.py
194     )
195     add_library (opengl SHARED opengl32.def wgltrace.cpp trace_write.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
196     set_target_properties (opengl PROPERTIES
197         PREFIX ""
198         OUTPUT_NAME opengl32)
199     if (MINGW)
200         set_target_properties(opengl PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
201     endif (MINGW)
202
203 else ()
204     include_directories (${X11_INCLUDE_DIR})
205
206     # libGL.so
207     add_custom_command (
208         OUTPUT glxtrace.cpp
209         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
210         DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glenum.py stdapi.py
211     )
212
213     add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
214
215     set_target_properties (glxtrace PROPERTIES
216         # avoid the default "lib" prefix
217         PREFIX ""
218     )
219
220     # Prevent symbol relocations internal to our wrapper library to be
221     # overwritten by the application.
222     if (NOT APPLE)
223         set_target_properties (glxtrace PROPERTIES
224             LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
225         )
226     endif (NOT APPLE)
227
228     target_link_libraries (glxtrace dl)
229 endif ()
230
231 if (WIN32)
232     set (os os_win32.cpp)
233     set (glws glws_wgl.cpp)
234 else (WIN32)
235     set (os os_posix.cpp)
236     set (glws glws_glx.cpp)
237 endif (WIN32)
238
239 add_library (trace trace_model.cpp trace_parser.cpp trace_write.cpp ${os})
240
241 add_executable (tracedump tracedump.cpp)
242 target_link_libraries (tracedump trace)
243
244 add_custom_command (
245     OUTPUT glretrace_gl.cpp
246     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
247     DEPENDS glretrace.py retrace.py codegen.py glapi.py glenum.py stdapi.py
248 )
249
250 add_custom_command (
251     OUTPUT glretrace_state.cpp
252     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_state.cpp
253     DEPENDS glstate.py glapi.py glenum.py stdapi.py
254 )
255
256 include_directories (
257     ${CMAKE_CURRENT_BINARY_DIR}
258     ${OPENGL_INCLUDE_PATH}
259 )
260
261 add_executable (glretrace
262     glretrace_gl.cpp
263     glretrace_main.cpp
264     glretrace_state.cpp
265     retrace.cpp
266     ${glws}
267     image.cpp 
268     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
269 )
270
271 set_property (
272     TARGET glretrace
273     APPEND
274     PROPERTY COMPILE_DEFINITIONS "RETRACE"
275 )
276
277 target_link_libraries (glretrace
278     trace
279     ${OPENGL_gl_LIBRARY}
280 )
281
282 if (NOT WIN32)
283     target_link_libraries (glretrace ${X11_LIBRARIES})
284 endif (NOT WIN32)
285
286 if (QT4_FOUND AND QJSON_FOUND)
287     add_subdirectory(gui)
288 endif (QT4_FOUND AND QJSON_FOUND)