gbm: factor out gbm_window_{init,teardown}
[mesa-waffle.git] / src / waffle / CMakeLists.txt
blobfa00bd878d2fb8ab5f2a02b7ac8e822fd1b86c9a
1 # ----------------------------------------------------------------------------
2 # Applies to all targets in this CMakeLists.
3 # ----------------------------------------------------------------------------
5 add_definitions(
6     -DWAFFLE_API_VERSION=${waffle_api_version}
7     -DWAFFLE_API_EXPERIMENTAL
8     )
10 include_directories(
11     android
12     api
13     cgl
14     core
15     egl
16     glx
17     linux
18     nacl
19     surfaceless_egl
20     wayland
21     wgl
22     x11
23     xegl
25     ${egl_INCLUDE_DIRS}
26     ${gbm_INCLUDE_DIRS}
27     ${gl_INCLUDE_DIRS}
28     ${GLEXT_INCLUDE_DIR}
29     ${libudev_INCLUDE_DIRS}
30     ${nacl_INCLUDE_DIRS}
31     ${wayland-client_INCLUDE_DIRS}
32     ${wayland-egl_INCLUDE_DIRS}
33     ${x11-xcb_INCLUDE_DIRS}
34     )
36 # ----------------------------------------------------------------------------
37 # Target: waffle (shared library)
38 # ----------------------------------------------------------------------------
40 list(APPEND waffle_libdeps
41     ${THREADS_LIBRARIES}
42     )
44 if(waffle_on_linux)
45     if(waffle_has_x11)
46         list(APPEND waffle_libdeps
47             ${x11-xcb_LDFLAGS}
48             )
49     endif()
50     if(waffle_has_gbm)
51         list(APPEND waffle_libdeps
52             ${libudev_LDFLAGS}
53             )
54     endif()
55 endif()
57 if(waffle_has_nacl)
58     list(APPEND waffle_libdeps
59         ${nacl_LDFLAGS}
60         )
61 endif()
63 set(waffle_sources
64     api/api_priv.c
65     api/waffle_attrib_list.c
66     api/waffle_config.c
67     api/waffle_context.c
68     api/waffle_display.c
69     api/waffle_dl.c
70     api/waffle_enum.c
71     api/waffle_error.c
72     api/waffle_gl_misc.c
73     api/waffle_init.c
74     api/waffle_window.c
75     core/wcore_attrib_list.c
76     core/wcore_config_attrs.c
77     core/wcore_display.c
78     core/wcore_error.c
79     core/wcore_tinfo.c
80     core/wcore_util.c
81     )
83 if(waffle_on_mac)
84     list(APPEND waffle_sources
85         cgl/cgl_config.m
86         cgl/cgl_context.m
87         cgl/cgl_display.m
88         cgl/cgl_dl.m
89         cgl/cgl_error.m
90         cgl/cgl_platform.m
91         cgl/cgl_window.m
92         cgl/WaffleGLView.m
93         )
94     list(APPEND waffle_libdeps
95         ${OPENGL_gl_LIBRARY}
96         )
97 endif()
99 if(waffle_has_egl)
100     list(APPEND waffle_sources
101         egl/wegl_config.c
102         egl/wegl_context.c
103         egl/wegl_display.c
104         egl/wegl_platform.c
105         egl/wegl_util.c
106         egl/wegl_surface.c
107         )
108 endif()
110 if(waffle_has_glx)
111     list(APPEND waffle_sources
112         glx/glx_config.c
113         glx/glx_context.c
114         glx/glx_display.c
115         glx/glx_platform.c
116         glx/glx_window.c
117         )
118 endif()
120 if(waffle_on_linux)
121     list(APPEND waffle_sources
122         linux/linux_dl.c
123         linux/linux_platform.c
124         )
125     list(APPEND waffle_libdeps
126         dl
127         pthread
128         )
129 endif()
131 if(waffle_has_surfaceless_egl)
132     list(APPEND waffle_sources
133         surfaceless_egl/sl_display.c
134         surfaceless_egl/sl_platform.c
135         surfaceless_egl/sl_window.c
136     )
137 endif()
139 if(waffle_has_wayland)
140     list(APPEND waffle_sources
141         wayland/wayland_display.c
142         wayland/wayland_platform.c
143         wayland/wayland_window.c
144         wayland/wayland_wrapper.c
145     )
146 endif()
148 if(waffle_has_x11)
149     list(APPEND waffle_sources
150         x11/x11_display.c
151         x11/x11_window.c
152         )
153 endif()
155 if(waffle_has_x11_egl)
156     list(APPEND waffle_sources
157         xegl/xegl_display.c
158         xegl/xegl_platform.c
159         xegl/xegl_window.c
160     )
161 endif()
163 if(waffle_has_gbm)
164     list(APPEND waffle_sources
165         gbm/wgbm_config.c
166         gbm/wgbm_display.c
167         gbm/wgbm_platform.c
168         gbm/wgbm_window.c
169     )
170 endif()
172 if(waffle_on_windows)
173     list(APPEND waffle_sources
174         wgl/wgl_config.c
175         wgl/wgl_context.c
176         wgl/wgl_display.c
177         wgl/wgl_dl.c
178         wgl/wgl_error.c
179         wgl/wgl_platform.c
180         wgl/wgl_window.c
181         )
183     list(APPEND waffle_libdeps
184         opengl32.lib
185         )
186 endif()
188 if(waffle_has_nacl)
189     list(APPEND waffle_sources
190         nacl/nacl_config.c
191         nacl/nacl_context.c
192         nacl/nacl_display.c
193         nacl/nacl_dl.c
194         nacl/nacl_platform.c
195         nacl/nacl_window.c
196         )
197     list(APPEND waffle_cxx_sources
198         nacl/nacl_container.cpp
199         )
200 endif()
202 # CMake will pass to the C compiler only C sources. CMake does not recognize the
203 # .m extension and ignores any such files in the source lists. To coerce CMake
204 # to pass .m files to the compiler, we must lie and claim that they are
205 # C sources.
206 set_source_files_properties(
207     ${waffle_sources}
208     PROPERTIES
209     LANGUAGE C
210     )
212 if(waffle_on_windows)
213     configure_file(
214         waffle.def.in
215         ${CMAKE_CURRENT_SOURCE_DIR}/${waffle_libname}.def
216         @ONLY
217         )
219     list(APPEND waffle_sources
220         ${waffle_libname}.def
221         )
222 endif()
224 include_directories(
225     ${GLX_INLCLUDE_DIRS}
226     ${X11_INCLUDE_DIRS}
227     ${X11-XCB_INCLUDE_DIRS}
228     ${XCB_INCLUDE_DIRS}
229     )
231 add_library(${waffle_libname} SHARED ${waffle_sources} ${waffle_cxx_sources})
233 # Debian's packaging system emits warnings if wflinfo directly links to any
234 # library that it doesn't directly use. Silence the warnings by annotating
235 # libwaffle's library dependencies as private, which prevents wflinfo from
236 # linking to them.
237 if(CMAKE_VERSION VERSION_LESS "2.8.12")
238     # On older CMake, we must rely on hacking the LINK_INTERFACE_LIBRARIES
239     # property.
240     if(NOT waffle_on_mac)
241         set_target_properties(${waffle_libname}
242             PROPERTIES
243             LINK_INTERFACE_LIBRARIES ""
244             )
245     endif()
246 else()
247     # CMake 2.8.12 introduced the PRIVATE keyword to target_link_libraries().
248     # All libraries listed after PRIVATE get annotated as such.
249     list(INSERT waffle_libdeps 0 PRIVATE)
250 endif()
252 target_link_libraries(${waffle_libname} ${waffle_libdeps})
254 set_target_properties(${waffle_libname}
255     PROPERTIES
256     SOVERSION ${waffle_soversion}
257     VERSION ${waffle_soversion}.${waffle_minor_version}.${waffle_patch_version}
258     )
260 if(waffle_on_windows)
261     set_target_properties(${waffle_libname}
262         PROPERTIES
263         PREFIX ""
264     )
265 endif()
267 install(
268     TARGETS ${waffle_libname}
269     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
270     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
271     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
272     COMPONENT libraries
273     )
275 # ----------------------------------------------------------------------------
276 # Target: waffle_static
277 # ----------------------------------------------------------------------------
279 # The unittest executable needs access to waffle's internal symbols. Yet, the
280 # sources in libwaffle.so are compiled with -fvisibility=hidden.
281 # One solution is to additionally build a static libwaffle and let the
282 # unittest executable link to that. Visibility options do not apply to static
283 # libraries; that is, all symbols are public.
285 add_library(waffle_static
286     STATIC
287     EXCLUDE_FROM_ALL
288     ${waffle_sources}
289     )
291 target_link_libraries(waffle_static ${waffle_libdeps})
293 set_target_properties(waffle_static
294     PROPERTIES
295     OUTPUT_NAME "waffle-static-${waffle_major_version}"
296     )
298 # ----------------------------------------------------------------------------
299 # Unit Tests
300 # ----------------------------------------------------------------------------
302 function(add_unittest unittest_name)
303     if(NOT waffle_build_tests)
304         return()
305     endif()
307     add_executable(${unittest_name} ${ARGN})
308     set_target_properties(${unittest_name}
309         PROPERTIES
310             RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
311     )
312     target_link_libraries(${unittest_name}
313         cmocka
314         waffle_static
315     )
316     add_custom_target(${unittest_name}_run
317         COMMAND "${unittest_name}"
318     )
319     add_dependencies(check ${unittest_name}_run)
321     if(VALGRIND_EXECUTABLE)
322         add_custom_target(valgrind_${unittest_name}_run
323             DEPENDS ${unittest_name}
324             COMMAND ${VALGRIND_EXECUTABLE} $<TARGET_FILE:${unittest_name}>
325         )
326         add_dependencies(valgrind-check valgrind_${unittest_name}_run)
327     endif()
328 endfunction()
330 add_unittest(wcore_attrib_list_unittest
331     core/wcore_attrib_list_unittest.c
333 add_unittest(wcore_config_attrs_unittest
334     core/wcore_config_attrs_unittest.c
336 add_unittest(wcore_error_unittest
337     core/wcore_error_unittest.c