aboutsummaryrefslogtreecommitdiff
path: root/src/waffle/CMakeLists.txt
blob: d3ab3ffe7ec612c7c643134ba3c817247eac74e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# ----------------------------------------------------------------------------
# Applies to all targets in this CMakeLists.
# ----------------------------------------------------------------------------

add_definitions(
    -DWAFFLE_API_VERSION=${waffle_api_version}
    -DWAFFLE_API_EXPERIMENTAL
    )

include_directories(
    android
    api
    cgl
    core
    egl
    glx
    linux
    surfaceless_egl
    wayland
    wgl
    x11
    xegl

    ${egl_INCLUDE_DIRS}
    ${gbm_INCLUDE_DIRS}
    ${gl_INCLUDE_DIRS}
    ${GLEXT_INCLUDE_DIR}
    ${libdrm_INCLUDE_DIRS}
    ${nacl_INCLUDE_DIRS}
    ${wayland-client_INCLUDE_DIRS}
    ${wayland-egl_INCLUDE_DIRS}
    ${x11-xcb_INCLUDE_DIRS}
    )

# ----------------------------------------------------------------------------
# Target: waffle (shared library)
# ----------------------------------------------------------------------------

list(APPEND waffle_libdeps
    ${THREADS_LIBRARIES}
    )

if(waffle_on_linux)
    if(waffle_has_x11)
        list(APPEND waffle_libdeps
            ${x11-xcb_LDFLAGS}
            )
    endif()
    if(waffle_has_gbm)
        list(APPEND waffle_libdeps
            ${libdrm_LDFLAGS}
            )
    endif()
endif()

set(waffle_sources
    api/api_priv.c
    api/waffle_attrib_list.c
    api/waffle_config.c
    api/waffle_context.c
    api/waffle_display.c
    api/waffle_dl.c
    api/waffle_enum.c
    api/waffle_error.c
    api/waffle_gl_misc.c
    api/waffle_init.c
    api/waffle_window.c
    core/wcore_attrib_list.c
    core/wcore_config_attrs.c
    core/wcore_display.c
    core/wcore_error.c
    core/wcore_tinfo.c
    core/wcore_util.c
    )

if(waffle_on_mac)
    list(APPEND waffle_sources
        cgl/cgl_config.m
        cgl/cgl_context.m
        cgl/cgl_display.m
        cgl/cgl_dl.m
        cgl/cgl_error.m
        cgl/cgl_platform.m
        cgl/cgl_window.m
        cgl/WaffleGLView.m
        )
    list(APPEND waffle_libdeps
        ${OPENGL_gl_LIBRARY}
        )
endif()

if(waffle_has_egl)
    list(APPEND waffle_sources
        egl/wegl_config.c
        egl/wegl_context.c
        egl/wegl_display.c
        egl/wegl_platform.c
        egl/wegl_util.c
        egl/wegl_surface.c
        )
endif()

if(waffle_has_glx)
    list(APPEND waffle_sources
        glx/glx_config.c
        glx/glx_context.c
        glx/glx_display.c
        glx/glx_platform.c
        glx/glx_window.c
        )
endif()

if(waffle_on_linux)
    list(APPEND waffle_sources
        linux/linux_dl.c
        linux/linux_platform.c
        )
    list(APPEND waffle_libdeps
        dl
        pthread
        )
endif()

if(waffle_has_surfaceless_egl)
    list(APPEND waffle_sources
        surfaceless_egl/sl_config.c
        surfaceless_egl/sl_display.c
        surfaceless_egl/sl_platform.c
        surfaceless_egl/sl_window.c
    )
endif()

macro(wayland_gen xml_file obj_name)
    set(PROTO_FILE wl-${obj_name}-proto.c)
    add_custom_command(
        OUTPUT ${PROTO_FILE}
        COMMAND ${WAYLAND_SCANNER} "private-code" ${xml_file} ${PROTO_FILE}
    )
    list(APPEND waffle_sources ${PROTO_FILE})
endmacro()

macro(wayland_gen_hdr xml_file obj_name)
    set(HDR_FILE wl-${obj_name}-proto.h)
    add_custom_target(wl_${obj_name}_proto_h ALL
        COMMAND ${WAYLAND_SCANNER} "client-header" ${xml_file} ${HDR_FILE}
    )
    list(APPEND waffle_hdrdeps wl_${obj_name}_proto_h)
    # Flip to enable -I builddir
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endmacro()

if(waffle_has_wayland)
    list(APPEND waffle_sources
        wayland/wayland_display.c
        wayland/wayland_platform.c
        wayland/wayland_window.c
        wayland/wayland_wrapper.c
    )
    wayland_gen(${wayland_core_xml} "core")
    wayland_gen(${wayland_xdg_shell_xml} "xdg-shell")
    wayland_gen_hdr(${wayland_xdg_shell_xml} "xdg-shell")
endif()

if(waffle_has_x11)
    list(APPEND waffle_sources
        x11/x11_display.c
        x11/x11_window.c
        )
endif()

if(waffle_has_x11_egl)
    list(APPEND waffle_sources
        xegl/xegl_display.c
        xegl/xegl_platform.c
        xegl/xegl_window.c
    )
endif()

if(waffle_has_gbm)
    list(APPEND waffle_sources
        gbm/wgbm_config.c
        gbm/wgbm_display.c
        gbm/wgbm_platform.c
        gbm/wgbm_window.c
    )
endif()

if(waffle_on_windows)
    list(APPEND waffle_sources
        wgl/wgl_config.c
        wgl/wgl_context.c
        wgl/wgl_display.c
        wgl/wgl_dl.c
        wgl/wgl_error.c
        wgl/wgl_platform.c
        wgl/wgl_window.c
        )

    list(APPEND waffle_libdeps
        opengl32.lib
        )
endif()

# CMake will pass to the C compiler only C sources. CMake does not recognize the
# .m extension and ignores any such files in the source lists. To coerce CMake
# to pass .m files to the compiler, we must lie and claim that they are
# C sources.
set_source_files_properties(
    ${waffle_sources}
    PROPERTIES
    LANGUAGE C
    )

if(waffle_on_windows)
    configure_file(
        waffle.def.in
        ${CMAKE_CURRENT_SOURCE_DIR}/${waffle_libname}.def
        @ONLY
        )

    list(APPEND waffle_sources
        ${waffle_libname}.def
        )
endif()

include_directories(
    ${GLX_INLCLUDE_DIRS}
    ${X11_INCLUDE_DIRS}
    ${X11-XCB_INCLUDE_DIRS}
    ${XCB_INCLUDE_DIRS}
    )

add_library(${waffle_libname} SHARED ${waffle_sources} ${waffle_cxx_sources})

# Debian's packaging system emits warnings if wflinfo directly links to any
# library that it doesn't directly use. Silence the warnings by annotating
# libwaffle's library dependencies as private, which prevents wflinfo from
# linking to them.
if(CMAKE_VERSION VERSION_LESS "2.8.12")
    # On older CMake, we must rely on hacking the LINK_INTERFACE_LIBRARIES
    # property.
    if(NOT waffle_on_mac)
        set_target_properties(${waffle_libname}
            PROPERTIES
            LINK_INTERFACE_LIBRARIES ""
            )
    endif()
else()
    # CMake 2.8.12 introduced the PRIVATE keyword to target_link_libraries().
    # All libraries listed after PRIVATE get annotated as such.
    list(INSERT waffle_libdeps 0 PRIVATE)
endif()

target_link_libraries(${waffle_libname} ${waffle_libdeps})

set_target_properties(${waffle_libname}
    PROPERTIES
    SOVERSION ${waffle_soversion}
    VERSION ${waffle_soversion}.${waffle_minor_version}.${waffle_patch_version}
    )

if(waffle_has_wayland)
    foreach(_hdr ${waffle_hdrdeps})
        add_dependencies(${waffle_libname} ${_hdr})
    endforeach()
endif()

if(waffle_on_windows)
    set_target_properties(${waffle_libname}
        PROPERTIES
        PREFIX ""
    )
endif()

install(
    TARGETS ${waffle_libname}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    COMPONENT libraries
    )

# ----------------------------------------------------------------------------
# Target: waffle_static
# ----------------------------------------------------------------------------

# The unittest executable needs access to waffle's internal symbols. Yet, the
# sources in libwaffle.so are compiled with -fvisibility=hidden.
# One solution is to additionally build a static libwaffle and let the
# unittest executable link to that. Visibility options do not apply to static
# libraries; that is, all symbols are public.

add_library(waffle_static
    STATIC
    EXCLUDE_FROM_ALL
    ${waffle_sources}
    )

target_link_libraries(waffle_static ${waffle_libdeps})

set_target_properties(waffle_static
    PROPERTIES
    OUTPUT_NAME "waffle-static-${waffle_major_version}"
    )

# ----------------------------------------------------------------------------
# Unit Tests
# ----------------------------------------------------------------------------

function(add_unittest unittest_name)
    if(NOT waffle_build_tests)
        return()
    endif()

    add_executable(${unittest_name} ${ARGN})
    set_target_properties(${unittest_name}
        PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
    )
    target_link_libraries(${unittest_name}
        cmocka
        waffle_static
    )
    add_custom_target(${unittest_name}_run
        COMMAND "${unittest_name}"
    )
    add_dependencies(check ${unittest_name}_run)

    if(VALGRIND_EXECUTABLE)
        add_custom_target(valgrind_${unittest_name}_run
            DEPENDS ${unittest_name}
            COMMAND ${VALGRIND_EXECUTABLE} $<TARGET_FILE:${unittest_name}>
        )
        add_dependencies(valgrind-check valgrind_${unittest_name}_run)
    endif()
endfunction()

add_unittest(wcore_attrib_list_unittest
    core/wcore_attrib_list_unittest.c
)
add_unittest(wcore_config_attrs_unittest
    core/wcore_config_attrs_unittest.c
)
add_unittest(wcore_error_unittest
    core/wcore_error_unittest.c
)