]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Fix .dll output directory.
[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 4.7 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     # d3d8.dll
151     if (DirectX_D3D8_INCLUDE_DIR)
152         include_directories (${DirectX_D3D8_INCLUDE_DIR})
153         add_custom_command (
154             OUTPUT d3d8.cpp
155             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
156             DEPENDS d3d8.py trace.py d3d8types.py d3d8caps.py d3dshader.py winapi.py stdapi.py
157         )
158         add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
159         set_target_properties (d3d8
160             PROPERTIES PREFIX ""
161             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
162             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
163         )
164     endif (DirectX_D3D8_INCLUDE_DIR)
165
166     # d3d9.dll
167     if (DirectX_D3DX9_INCLUDE_DIR)
168         include_directories (${DirectX_D3DX9_INCLUDE_DIR})
169         add_custom_command (
170             OUTPUT d3d9.cpp
171             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
172             DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
173         )
174         add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
175         set_target_properties (d3d9
176             PROPERTIES PREFIX ""
177             RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
178             LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
179         )
180     endif (DirectX_D3DX9_INCLUDE_DIR)
181
182     # d3d10.dll
183     #if (DirectX_D3D10_INCLUDE_DIR)
184     #    include_directories (${DirectX_D3D10_INCLUDE_DIR})
185     #    add_custom_command (
186     #        OUTPUT d3d10.cpp
187     #        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
188     #        DEPENDS d3d10misc.py winapi.py stdapi.py
189     #    )
190     #    add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
191     #    set_target_properties (d3d10 PROPERTIES PREFIX "")
192     #endif (DirectX_D3D10_INCLUDE_DIR)
193
194     # opengl32.dll
195     add_custom_command (
196         OUTPUT wgltrace.cpp
197         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
198         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glenum.py winapi.py stdapi.py
199     )
200     add_library (wgltrace SHARED opengl32.def wgltrace.cpp trace_write.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
201     set_target_properties (wgltrace PROPERTIES
202         PREFIX ""
203         OUTPUT_NAME opengl32
204         RUNTIME_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers
205         LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers
206     )
207     if (MINGW)
208         set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
209     endif (MINGW)
210
211 else ()
212     include_directories (${X11_INCLUDE_DIR})
213
214     # libGL.so
215     add_custom_command (
216         OUTPUT glxtrace.cpp
217         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
218         DEPENDS glxtrace.py gltrace.py trace.py glxapi.py glapi.py glstate.py glenum.py stdapi.py
219     )
220
221     add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
222
223     set_target_properties (glxtrace PROPERTIES
224         # avoid the default "lib" prefix
225         PREFIX ""
226     )
227
228     # Prevent symbol relocations internal to our wrapper library to be
229     # overwritten by the application.
230     if (NOT APPLE)
231         set_target_properties (glxtrace PROPERTIES
232             LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
233         )
234     endif (NOT APPLE)
235
236     target_link_libraries (glxtrace dl)
237 endif ()
238
239 if (WIN32)
240     set (os os_win32.cpp)
241     set (glws glws_wgl.cpp)
242 else (WIN32)
243     set (os os_posix.cpp)
244     set (glws glws_glx.cpp)
245 endif (WIN32)
246
247 add_library (trace trace_model.cpp trace_parser.cpp trace_write.cpp ${os})
248
249 add_executable (tracedump tracedump.cpp)
250 target_link_libraries (tracedump trace)
251
252 add_custom_command (
253     OUTPUT glretrace_gl.cpp
254     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
255     DEPENDS glretrace.py retrace.py codegen.py glapi.py glenum.py stdapi.py
256 )
257
258 add_custom_command (
259     OUTPUT glretrace_state.cpp
260     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_state.cpp
261     DEPENDS glstate.py glapi.py glenum.py stdapi.py
262 )
263
264 include_directories (
265     ${CMAKE_CURRENT_BINARY_DIR}
266     ${OPENGL_INCLUDE_PATH}
267 )
268
269 add_executable (glretrace
270     glretrace_gl.cpp
271     glretrace_main.cpp
272     glretrace_state.cpp
273     retrace.cpp
274     ${glws}
275     image.cpp 
276     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
277 )
278
279 set_property (
280     TARGET glretrace
281     APPEND
282     PROPERTY COMPILE_DEFINITIONS "RETRACE"
283 )
284
285 target_link_libraries (glretrace
286     trace
287     ${OPENGL_gl_LIBRARY}
288 )
289
290 if (NOT WIN32)
291     target_link_libraries (glretrace ${X11_LIBRARIES})
292 endif (NOT WIN32)
293
294 if (QT4_FOUND AND QJSON_FOUND)
295     add_subdirectory(gui)
296 endif (QT4_FOUND AND QJSON_FOUND)