]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Get d3d9 in buildable state again.
[apitrace] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2
3 project (apitrace)
4
5 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
6
7 # Set default built type
8 if (NOT CMAKE_BUILD_TYPE)
9         set (CMAKE_BUILD_TYPE Debug
10                 CACHE
11                 STRING "Choose the build type, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel."
12                 FORCE)
13 endif (NOT CMAKE_BUILD_TYPE)
14
15 find_package (PythonInterp REQUIRED)
16 find_package (OpenGL REQUIRED)
17 find_package (ZLIB)
18
19 find_package (DirectX)
20
21 find_package (GLUT)
22
23 if (WIN32)
24         # MSVC & MinGW only define & use APIENTRY
25         add_definitions (-DGLAPIENTRY=__stdcall)
26 endif (WIN32)
27
28 if (MSVC)
29         # Enable math constants defines
30         add_definitions (-D_USE_MATH_DEFINES)
31
32         # Adjust warnings
33         add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
34         add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
35         add_definitions (-W4)
36         add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
37         add_definitions (-wd4505) # unreferenced local function has been removed
38         add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
39         # XXX: it's safer to use ssize_t everywhere instead of disabling warning
40         add_definitions (-wd4018) # signed/unsigned mismatch
41         
42         # Use static runtime
43         # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
44         foreach (flag_var
45                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
46                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
47         )
48                 if (${flag_var} MATCHES "/MD")
49                         string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
50                 endif (${flag_var} MATCHES "/MD")
51         endforeach (flag_var)
52     
53     # C99 headers
54     include_directories (c99)
55 else ()
56         # Adjust warnings
57         add_definitions (-Wall)
58         # XXX: it's safer to use ssize_t everywhere instead of disabling warning
59         add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
60 endif ()
61
62 # Use bundled ZLIB if system one can't be found
63 if (NOT ZLIB_FOUND)
64         add_library (zlib STATIC
65                 zlib/adler32.c
66                 zlib/compress.c
67                 zlib/crc32.c
68                 zlib/gzio.c
69                 zlib/uncompr.c
70                 zlib/deflate.c
71                 zlib/trees.c
72                 zlib/zutil.c
73                 zlib/inflate.c
74                 zlib/infback.c
75                 zlib/inftrees.c
76                 zlib/inffast.c
77         )
78
79         include_directories (zlib)
80         link_libraries (zlib)
81 else (NOT ZLIB_FOUND)
82         include_directories (${ZLIB_INCLUDE_DIRS})
83         link_libraries (${ZLIB_LIBRARIES})
84 endif (NOT ZLIB_FOUND)
85
86 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
87
88 if (WIN32)
89         # Put wrappers in a separate directory
90         set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers)
91
92         # d3d8.dll
93     #if (DirectX_D3D8_FOUND)
94         #       include_directories (${DirectX_D3D8_INCLUDE_DIR})
95         #       add_custom_command (
96         #               OUTPUT d3d8.cpp
97         #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
98         #               DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py stdapi.py
99         #       )
100         #       add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
101         #       set_target_properties (d3d8 PROPERTIES PREFIX "")
102         #endif (DirectX_D3D8_FOUND)
103
104         # d3d9.dll
105     if (DirectX_D3DX9_FOUND)
106                 include_directories (${DirectX_D3DX9_INCLUDE_DIR})
107                 add_custom_command (
108                         OUTPUT d3d9.cpp
109                         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
110                         DEPENDS d3d9.py trace.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
111                 )
112                 add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
113                 set_target_properties (d3d9 PROPERTIES PREFIX "")
114         endif (DirectX_D3DX9_FOUND)
115
116         # d3d10.dll
117         #if (DirectX_D3D10_FOUND)
118         #       include_directories (${DirectX_D3D10_INCLUDE_DIR})
119         #       add_custom_command (
120         #               OUTPUT d3d10.cpp
121         #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
122         #               DEPENDS d3d10misc.py winapi.py stdapi.py
123         #       )
124         #       add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
125         #       set_target_properties (d3d10 PROPERTIES PREFIX "")
126         #endif (DirectX_D3D10_FOUND)
127
128         # opengl32.dll
129         add_custom_command (
130                 OUTPUT opengl32.cpp
131                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
132                 DEPENDS wgltrace.py trace.py wglapi.py glapi.py glenum.py winapi.py stdapi.py
133         )
134         add_library (opengl SHARED opengl32.def opengl32.cpp trace_write.cpp os_win32.cpp)
135         set_target_properties (opengl PROPERTIES
136                 PREFIX ""
137                 OUTPUT_NAME opengl32)
138         if (MINGW)
139                 SET_TARGET_PROPERTIES(opengl PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.def")
140         endif (MINGW)
141
142 else ()
143
144         # libGL.so
145         add_custom_command (
146                 OUTPUT glxtrace.cpp
147                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
148                 DEPENDS glxtrace.py trace.py glxapi.py glapi.py glenum.py stdapi.py
149         )
150
151         add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp)
152         set_target_properties (glxtrace PROPERTIES PREFIX "")
153         target_link_libraries (glxtrace dl)
154 endif ()
155
156 add_executable (dump dump.cpp trace_model.cpp)
157
158 if (WIN32)
159     set (os os_win32.cpp)
160 else (WIN32)
161     set (os os_posix.cpp)
162 endif (WIN32)
163
164 if (GLUT_INCLUDE_DIR)
165         add_custom_command (
166                 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
167                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
168                 DEPENDS glproc.py wglapi.py glxapi.py glapi.py glenum.py stdapi.py
169         )
170
171         add_custom_command (
172                 OUTPUT glretrace.cpp
173                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace.cpp
174                 DEPENDS glretrace.py retrace.py codegen.py glapi.py glenum.py stdapi.py
175         )
176
177         include_directories (
178                 ${CMAKE_CURRENT_BINARY_DIR}
179                 ${OPENGL_INCLUDE_PATH}
180                 ${GLUT_INCLUDE_DIR}
181         )
182
183         add_executable (glretrace glretrace.cpp trace_model.cpp ${os} ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
184
185         target_link_libraries (glretrace
186                 ${OPENGL_gl_LIBRARY}
187                 ${OPENGL_glu_LIBRARY}
188                 ${GLUT_glut_LIBRARY}
189         )
190 endif (GLUT_INCLUDE_DIR)
191
192