|
1 | 1 | set(PRESENTATION_BACKENDS xlib xcb wayland) |
2 | | -set(PRESENTATION_BACKEND xlib CACHE STRING |
3 | | - "Presentation backend chosen at configure time") |
4 | | -set_property(CACHE PRESENTATION_BACKEND PROPERTY STRINGS |
5 | | - ${PRESENTATION_BACKENDS}) |
| 2 | +set(PRESENTATION_BACKEND |
| 3 | + xlib |
| 4 | + CACHE STRING "Presentation backend chosen at configure time" |
| 5 | +) |
| 6 | +set_property(CACHE PRESENTATION_BACKEND PROPERTY STRINGS ${PRESENTATION_BACKENDS}) |
6 | 7 |
|
7 | 8 | list(FIND PRESENTATION_BACKENDS ${PRESENTATION_BACKEND} index) |
8 | 9 | if(index EQUAL -1) |
9 | | - message(FATAL_ERROR "Presentation backend must be one of |
10 | | - ${PRESENTATION_BACKENDS}") |
| 10 | + message(FATAL_ERROR "Presentation backend must be one of ${PRESENTATION_BACKENDS}") |
11 | 11 | endif() |
12 | 12 |
|
13 | 13 | message(STATUS "Using presentation backend: ${PRESENTATION_BACKEND}") |
14 | 14 |
|
| 15 | +find_package(X11) |
15 | 16 |
|
16 | | -if( PRESENTATION_BACKEND MATCHES "xlib" ) |
17 | | - find_package(X11 REQUIRED) |
18 | | - if (BUILD_TESTS AND ((NOT X11_Xxf86vm_LIB) OR (NOT X11_Xrandr_LIB))) |
| 17 | +find_package(PkgConfig) |
| 18 | + |
| 19 | +if(PKG_CONFIG_FOUND) |
| 20 | + pkg_search_module(XCB xcb) |
| 21 | + |
| 22 | + pkg_search_module(WAYLAND_CLIENT wayland-client) |
| 23 | +endif() |
| 24 | + |
| 25 | + |
| 26 | +if(PRESENTATION_BACKEND MATCHES "xlib") |
| 27 | + if(BUILD_TESTS AND (NOT X11_Xxf86vm_LIB OR NOT X11_Xrandr_LIB)) |
19 | 28 | message(FATAL_ERROR "OpenXR tests using xlib backend requires Xxf86vm and Xrandr") |
20 | 29 | endif() |
21 | 30 |
|
22 | | - add_definitions( -DSUPPORT_X ) |
23 | | - add_definitions( -DOS_LINUX_XLIB ) |
24 | | - set( XLIB_LIBRARIES |
25 | | - ${X11_LIBRARIES} |
26 | | - ${X11_Xxf86vm_LIB} |
27 | | - ${X11_Xrandr_LIB} ) |
28 | | - |
29 | | -elseif( PRESENTATION_BACKEND MATCHES "xcb" ) |
30 | | - find_package(PkgConfig REQUIRED) |
31 | | - # XCB + XCB GLX is limited to OpenGL 2.1 |
32 | | - # add_definitions( -DOS_LINUX_XCB ) |
33 | | - # XCB + Xlib GLX 1.3 |
34 | | - add_definitions( -DOS_LINUX_XCB_GLX ) |
35 | | - |
36 | | - pkg_search_module(X11 REQUIRED x11) |
37 | | - pkg_search_module(XCB REQUIRED xcb) |
| 31 | + if(TARGET openxr-gfxwrapper) |
| 32 | + target_compile_definitions(openxr-gfxwrapper PUBLIC OS_LINUX_XLIB) |
| 33 | + target_link_libraries(openxr-gfxwrapper PRIVATE ${X11_X11_LIB} ${X11_Xxf86vm_LIB} ${X11_Xrandr_LIB}) |
| 34 | + |
| 35 | + if(TARGET OpenGL::OpenGL) |
| 36 | + target_link_libraries(openxr-gfxwrapper PUBLIC OpenGL::OpenGL) |
| 37 | + elseif(TARGET OpenGL::GLX) |
| 38 | + target_link_libraries(openxr-gfxwrapper PUBLIC OpenGL::GLX) |
| 39 | + else() |
| 40 | + target_link_libraries(openxr-gfxwrapper PUBLIC ${OPENGL_LIBRARIES} ${OPENGL_glx_LIBRARY}) |
| 41 | + endif() |
| 42 | + endif() |
| 43 | +elseif(PRESENTATION_BACKEND MATCHES "xcb") |
38 | 44 | pkg_search_module(XCB_RANDR REQUIRED xcb-randr) |
39 | 45 | pkg_search_module(XCB_KEYSYMS REQUIRED xcb-keysyms) |
40 | 46 | pkg_search_module(XCB_GLX REQUIRED xcb-glx) |
41 | 47 | pkg_search_module(XCB_DRI2 REQUIRED xcb-dri2) |
42 | 48 | pkg_search_module(XCB_ICCCM REQUIRED xcb-icccm) |
43 | 49 |
|
44 | | - set( XCB_LIBRARIES |
45 | | - ${XCB_LIBRARIES} |
46 | | - ${XCB_KEYSYMS_LIBRARIES} |
47 | | - ${XCB_RANDR_LIBRARIES} |
48 | | - ${XCB_GLX_LIBRARIES} |
49 | | - ${XCB_DRI2_LIBRARIES} |
50 | | - ${X11_LIBRARIES} ) |
51 | | - |
52 | | -elseif( PRESENTATION_BACKEND MATCHES "wayland" ) |
53 | | - find_package(PkgConfig REQUIRED) |
54 | | - pkg_search_module(WAYLAND_CLIENT REQUIRED wayland-client) |
| 50 | + if(TARGET openxr-gfxwrapper) |
| 51 | + # XCB + XCB GLX is limited to OpenGL 2.1 |
| 52 | + # target_compile_definitions(openxr-gfxwrapper PUBLIC OS_LINUX_XCB ) |
| 53 | + # XCB + Xlib GLX 1.3 |
| 54 | + target_compile_definitions(openxr-gfxwrapper PUBLIC OS_LINUX_XCB_GLX) |
| 55 | + |
| 56 | + target_link_libraries(openxr-gfxwrapper PRIVATE ${X11_X11_LIB} ${XCB_KEYSYMS_LIBRARIES} ${XCB_RANDR_LIBRARIES}) |
| 57 | + endif() |
| 58 | +elseif(PRESENTATION_BACKEND MATCHES "wayland") |
| 59 | + |
55 | 60 | pkg_search_module(WAYLAND_EGL REQUIRED wayland-egl) |
56 | 61 | pkg_search_module(WAYLAND_SCANNER REQUIRED wayland-scanner) |
57 | 62 | pkg_search_module(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.7) |
58 | 63 | pkg_search_module(EGL REQUIRED egl) |
59 | 64 |
|
60 | | - add_definitions( -DOS_LINUX_WAYLAND ) |
61 | | - set( WAYLAND_LIBRARIES |
62 | | - ${EGL_LIBRARIES} |
63 | | - ${WAYLAND_CLIENT_LIBRARIES} |
64 | | - ${WAYLAND_EGL_LIBRARIES} ) |
65 | | - |
66 | | - # generate wayland protocols |
67 | | - set(WAYLAND_PROTOCOLS_DIR ${PROJECT_SOURCE_DIR}/wayland-protocols/) |
68 | | - file(MAKE_DIRECTORY ${WAYLAND_PROTOCOLS_DIR}) |
69 | | - |
70 | | - pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir) |
71 | | - pkg_get_variable(WAYLAND_SCANNER wayland-scanner wayland_scanner) |
72 | | - |
73 | | - set(PROTOCOL xdg-shell-unstable-v6) |
74 | | - set(PROTOCOL_XML |
75 | | - ${WAYLAND_PROTOCOLS_DATADIR}/unstable/xdg-shell/${PROTOCOL}.xml) |
76 | | - |
77 | | - if( EXISTS ${PROTOCOL_XML} ) |
78 | | - execute_process(COMMAND |
79 | | - ${WAYLAND_SCANNER} |
80 | | - code |
81 | | - ${PROTOCOL_XML} |
82 | | - ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.c) |
83 | | - execute_process(COMMAND |
84 | | - ${WAYLAND_SCANNER} |
85 | | - client-header |
86 | | - ${PROTOCOL_XML} |
87 | | - ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.h) |
88 | | - |
89 | | - set( WAYLAND_PROTOCOL_SRC |
90 | | - ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.c |
91 | | - ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.h ) |
92 | | - |
93 | | - include_directories(${WAYLAND_PROTOCOLS_DIR}) |
94 | | - else() |
95 | | - message(FATAL_ERROR |
96 | | - "xdg-shell-unstable-v6.xml not found in " |
97 | | - ${WAYLAND_PROTOCOLS_DATADIR} |
98 | | - "\nYour wayland-protocols package does not " |
99 | | - "contain xdg-shell-unstable-v6.") |
| 65 | + if(TARGET openxr-gfxwrapper) |
| 66 | + # generate wayland protocols |
| 67 | + set(WAYLAND_PROTOCOLS_DIR ${PROJECT_BINARY_DIR}/wayland-protocols/) |
| 68 | + file(MAKE_DIRECTORY ${WAYLAND_PROTOCOLS_DIR}) |
| 69 | + |
| 70 | + pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir) |
| 71 | + pkg_get_variable(WAYLAND_SCANNER wayland-scanner wayland_scanner) |
| 72 | + |
| 73 | + set(PROTOCOL xdg-shell-unstable-v6) |
| 74 | + set(PROTOCOL_XML ${WAYLAND_PROTOCOLS_DATADIR}/unstable/xdg-shell/${PROTOCOL}.xml) |
| 75 | + |
| 76 | + if(NOT EXISTS ${PROTOCOL_XML}) |
| 77 | + message(FATAL_ERROR "xdg-shell-unstable-v6.xml not found in " ${WAYLAND_PROTOCOLS_DATADIR} |
| 78 | + "\nYour wayland-protocols package does not " "contain xdg-shell-unstable-v6." |
| 79 | + ) |
| 80 | + endif() |
| 81 | + add_custom_command( |
| 82 | + OUTPUT ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.c |
| 83 | + COMMAND ${WAYLAND_SCANNER} code ${PROTOCOL_XML} ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.c |
| 84 | + VERBATIM |
| 85 | + ) |
| 86 | + add_custom_command( |
| 87 | + OUTPUT ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.h |
| 88 | + COMMAND ${WAYLAND_SCANNER} client-header ${PROTOCOL_XML} ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.h |
| 89 | + VERBATIM |
| 90 | + ) |
| 91 | + |
| 92 | + target_sources(openxr-gfxwrapper |
| 93 | + PRIVATE |
| 94 | + ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.c |
| 95 | + ${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.h |
| 96 | + ) |
| 97 | + |
| 98 | + target_include_directories(openxr-gfxwrapper PUBLIC ${WAYLAND_PROTOCOLS_DIR}) |
| 99 | + target_link_libraries( |
| 100 | + openxr-gfxwrapper PRIVATE ${EGL_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} |
| 101 | + ) |
| 102 | + target_compile_definitions(openxr-gfxwrapper PUBLIC OS_LINUX_WAYLAND) |
| 103 | + target_link_libraries(openxr-gfxwrapper PRIVATE ${EGL_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES}) |
100 | 104 | endif() |
101 | 105 | endif() |
0 commit comments