]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
Basic Linux/GLX tracing support.
[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
8 find_package (ZLIB)
9
10 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
11         # Nobody likes to include windows.h:
12         # - Microsoft's GL/gl.h header depends on windows.h but doesn't include it;
13         # - GLEW temporarily defines the necessary defines but undefines them later
14         # - certain GLUT distributions don't include it;
15         # - most of our programs are meant to be portable so don't include it.
16         #
17         # We could try to replicate the windows.h definitions required by
18         # GL/gl.h, but the build time savings don't compensate the constant
19         # headaches that brings, so instead we force windows.h to be included
20         # on every file.
21         if (MSVC)
22                 add_definitions (-FIwindows.h)
23         else (MSVC)
24                 add_definitions (--include windows.h)
25         endif (MSVC)
26
27         # MSVC & MinGW only define & use APIENTRY
28         add_definitions (-DGLAPIENTRY=__stdcall)
29
30         link_libraries (winmm)
31 endif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
32
33 if (MSVC)
34         # Enable math constants defines
35         add_definitions (-D_USE_MATH_DEFINES)
36
37         # Silence several MSVC pedantic warnings
38         add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
39         add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
40 endif (MSVC)
41
42 # Use bundled ZLIB if system one can't be found
43 if (NOT ZLIB_FOUND)
44         add_library (zlib STATIC
45                 zlib/adler32.c
46                 zlib/compress.c
47                 zlib/crc32.c
48                 zlib/gzio.c
49                 zlib/uncompr.c
50                 zlib/deflate.c
51                 zlib/trees.c
52                 zlib/zutil.c
53                 zlib/inflate.c
54                 zlib/infback.c
55                 zlib/inftrees.c
56                 zlib/inffast.c
57         )
58
59         include_directories (zlib)
60         link_libraries (zlib)
61 else (NOT ZLIB_FOUND)
62         include_directories (${ZLIB_INCLUDE_DIRS})
63         link_libraries (${ZLIB_LIBRARIES})
64 endif (NOT ZLIB_FOUND)
65
66 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
67
68 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
69
70         # opengl32.dll
71         add_custom_command (
72                 OUTPUT opengl32.cpp
73                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
74                 DEPENDS opengl32.py gl.py windows.py base.py
75         )
76         add_library (opengl32 SHARED opengl32.def opengl32.cpp log.cpp)
77         set_target_properties (opengl32 PROPERTIES PREFIX "")
78
79 else ()
80
81         # libGL.so
82         add_custom_command (
83                 OUTPUT glx.cpp
84                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glx.py > ${CMAKE_CURRENT_BINARY_DIR}/glx.cpp
85                 DEPENDS glx.py gl.py dl.py base.py
86         )
87         add_library (glxtrace SHARED glx.cpp log.cpp)
88         set_target_properties (glxtrace PROPERTIES PREFIX "")
89         target_link_libraries (glxtrace dl)
90 endif ()
91