]> git.cworth.org Git - apitrace/blob - CMakeLists.txt
More warnings when building with CMake.
[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         
41         add_definitions (-W4)
42 else ()
43         add_definitions (-Wall)
44 endif ()
45
46 # Use bundled ZLIB if system one can't be found
47 if (NOT ZLIB_FOUND)
48         add_library (zlib STATIC
49                 zlib/adler32.c
50                 zlib/compress.c
51                 zlib/crc32.c
52                 zlib/gzio.c
53                 zlib/uncompr.c
54                 zlib/deflate.c
55                 zlib/trees.c
56                 zlib/zutil.c
57                 zlib/inflate.c
58                 zlib/infback.c
59                 zlib/inftrees.c
60                 zlib/inffast.c
61         )
62
63         include_directories (zlib)
64         link_libraries (zlib)
65 else (NOT ZLIB_FOUND)
66         include_directories (${ZLIB_INCLUDE_DIRS})
67         link_libraries (${ZLIB_LIBRARIES})
68 endif (NOT ZLIB_FOUND)
69
70 include_directories (${CMAKE_CURRENT_SOURCE_DIR})
71
72 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
73
74         # opengl32.dll
75         add_custom_command (
76                 OUTPUT opengl32.cpp
77                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
78                 DEPENDS opengl32.py gl.py windows.py base.py
79         )
80         add_library (opengl32 SHARED opengl32.def opengl32.cpp log.cpp os_win32.cpp)
81         set_target_properties (opengl32 PROPERTIES PREFIX "")
82
83 else ()
84
85         # libGL.so
86         add_custom_command (
87                 OUTPUT glx.cpp
88                 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glx.py > ${CMAKE_CURRENT_BINARY_DIR}/glx.cpp
89                 DEPENDS glx.py gl.py dl.py base.py
90         )
91         add_library (glxtrace SHARED glx.cpp log.cpp os_posix.cpp)
92         set_target_properties (glxtrace PROPERTIES PREFIX "")
93         target_link_libraries (glxtrace dl)
94 endif ()
95