1if not (get_option('scanner') or get_option('libraries')) 2 error('Either -Dscanner=true or -Dlibraries=true is required') 3endif 4 5wayland_version_h = configuration_data() 6wayland_version_h.set('WAYLAND_VERSION', meson.project_version()) 7wayland_version_h.set('WAYLAND_VERSION_MAJOR', wayland_version[0].to_int()) 8wayland_version_h.set('WAYLAND_VERSION_MINOR', wayland_version[1].to_int()) 9wayland_version_h.set('WAYLAND_VERSION_MICRO', wayland_version[2].to_int()) 10configure_file( 11 input: 'wayland-version.h.in', 12 output: 'wayland-version.h', 13 configuration: wayland_version_h, 14 install: get_option('libraries'), 15 install_dir: join_paths(get_option('prefix'), get_option('includedir')) 16) 17 18 19wayland_util = static_library( 20 'wayland-util', 21 sources: 'wayland-util.c' 22) 23 24wayland_util_dep = declare_dependency( 25 link_with: wayland_util, 26 include_directories: include_directories('.') 27) 28 29if get_option('scanner') 30 # wayland-scanner 31 32 scanner_deps = [ dependency('expat') ] 33 scanner_args = [ '-include', 'config.h' ] 34 35 if get_option('dtd_validation') 36 scanner_deps += dependency('libxml-2.0') 37 scanner_args += '-DHAVE_LIBXML=1' 38 endif 39 40 prog_embed = find_program('embed.py', native: true) 41 42 embed_dtd = custom_target( 43 'wayland.dtd.h', 44 input: '../protocol/wayland.dtd', 45 output: 'wayland.dtd.h', 46 command: [ prog_embed, '@INPUT@', 'wayland_dtd' ], 47 capture: true 48 ) 49 50 wayland_scanner_sources = [ 'scanner.c', embed_dtd ] 51 wayland_scanner_includes = [ root_inc, protocol_inc ] 52 53 wayland_scanner = executable( 54 'wayland-scanner', 55 wayland_scanner_sources, 56 c_args: scanner_args, 57 include_directories: wayland_scanner_includes, 58 dependencies: [ scanner_deps, wayland_util_dep, ], 59 install: true 60 ) 61 62 pkgconfig.generate( 63 name: 'Wayland Scanner', 64 description: 'Wayland scanner', 65 version: meson.project_version(), 66 variables: [ 67 'datarootdir=' + join_paths('${prefix}', get_option('datadir')), 68 'pkgdatadir=' + join_paths('${datarootdir}', meson.project_name()), 69 'bindir=' + join_paths('${prefix}', get_option('bindir')), 70 'wayland_scanner=${bindir}/wayland-scanner' 71 ], 72 filebase: 'wayland-scanner' 73 ) 74 75 if meson.can_run_host_binaries() 76 meson.override_find_program('wayland-scanner', wayland_scanner) 77 endif 78endif 79 80if meson.is_cross_build() or not get_option('scanner') 81 scanner_dep = dependency('wayland-scanner', native: true, version: meson.project_version()) 82 wayland_scanner_for_build = find_program(scanner_dep.get_variable(pkgconfig: 'wayland_scanner')) 83else 84 wayland_scanner_for_build = wayland_scanner 85endif 86 87if get_option('libraries') 88 # wayland libraries 89 90 mathlib_dep = cc.find_library('m', required: false) 91 threads_dep = dependency('threads', required: false) 92 93 wayland_private = static_library( 94 'wayland-private', 95 sources: [ 96 'connection.c', 97 'wayland-os.c' 98 ], 99 dependencies: [ epoll_dep, ffi_dep, rt_dep ] 100 ) 101 102 wayland_private_dep = declare_dependency( 103 link_with: wayland_private, 104 include_directories: include_directories('.') 105 ) 106 107 generated_headers = [ 108 { 109 'scanner_args': ['server-header'], 110 'output': 'wayland-server-protocol.h', 111 'install': true, 112 }, 113 { 114 'scanner_args': ['server-header', '-c'], 115 'output': 'wayland-server-protocol-core.h', 116 'install': false, 117 }, 118 { 119 'scanner_args': ['client-header'], 120 'output': 'wayland-client-protocol.h', 121 'install': true, 122 }, 123 { 124 'scanner_args': ['client-header', '-c'], 125 'output': 'wayland-client-protocol-core.h', 126 'install': false, 127 }, 128 ] 129 130 foreach gen: generated_headers 131 scanner_args = gen['scanner_args'] 132 output_file = gen['output'] 133 install_file = gen['install'] 134 install_dir = join_paths(get_option('prefix'), get_option('includedir')) 135 target_name = output_file.underscorify() 136 137 target = custom_target( 138 target_name, 139 command: [ 140 wayland_scanner_for_build, '-s', scanner_args, 141 '@INPUT@', '@OUTPUT@' 142 ], 143 input: wayland_protocol_xml, 144 output: output_file, 145 install: install_file, 146 install_dir: install_dir 147 ) 148 149 set_variable(target_name, target) 150 endforeach 151 152 wayland_protocol_c = custom_target( 153 'protocol source', 154 command: [ 155 wayland_scanner_for_build, '-s', 'public-code', '@INPUT@', '@OUTPUT@' 156 ], 157 input: wayland_protocol_xml, 158 output: 'wayland-protocol.c' 159 ) 160 161 if wayland_version[0] != '1' 162 # The versioning used for the shared libraries assumes that the major 163 # version of Wayland as a whole will increase to 2 if and only if there 164 # is an ABI break, at which point we should probably bump the SONAME of 165 # all libraries to .so.2. For more details see 166 # https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/177 167 error('We probably need to bump the SONAME of libwayland-server and -client') 168 endif 169 170 wayland_server = library( 171 'wayland-server', 172 sources: [ 173 wayland_server_protocol_core_h, 174 wayland_server_protocol_h, 175 wayland_protocol_c, 176 'wayland-server.c', 177 'wayland-shm.c', 178 'event-loop.c' 179 ], 180 # To avoid an unnecessary SONAME bump, wayland 1.x.y produces 181 # libwayland-server.so.0.x.y. 182 version: '.'.join(['0', wayland_version[1], wayland_version[2]]), 183 dependencies: [ 184 epoll_dep, 185 ffi_dep, 186 wayland_private_dep, 187 wayland_util_dep, 188 mathlib_dep, 189 threads_dep, 190 rt_dep 191 ], 192 include_directories: root_inc, 193 install: true 194 ) 195 196 wayland_server_dep = declare_dependency( 197 link_with: wayland_server, 198 include_directories: [ root_inc, include_directories('.') ], 199 dependencies: [ epoll_dep, ffi_dep, mathlib_dep, threads_dep ], 200 sources: [ 201 wayland_server_protocol_core_h, 202 wayland_server_protocol_h 203 ] 204 ) 205 206 pkgconfig.generate( 207 wayland_server, 208 name: 'Wayland Server', 209 description: 'Server side implementation of the Wayland protocol', 210 version: meson.project_version(), 211 filebase: 'wayland-server', 212 variables: [ 213 'datarootdir=' + join_paths('${prefix}', get_option('datadir')), 214 'pkgdatadir=' + join_paths('${datarootdir}', meson.project_name()) 215 ] 216 ) 217 218 if meson.version().version_compare('>= 0.54.0') 219 meson.override_dependency('wayland-server', wayland_server_dep) 220 endif 221 222 wayland_client = library( 223 'wayland-client', 224 sources: [ 225 wayland_client_protocol_core_h, 226 wayland_client_protocol_h, 227 wayland_protocol_c, 228 'wayland-client.c' 229 ], 230 # To avoid an unnecessary SONAME bump, wayland 1.x.y produces 231 # libwayland-client.so.0.x.y. 232 version: '.'.join(['0', wayland_version[1], wayland_version[2]]), 233 dependencies: [ 234 epoll_dep, 235 ffi_dep, 236 wayland_private_dep, 237 wayland_util_dep, 238 mathlib_dep, 239 threads_dep 240 ], 241 include_directories: root_inc, 242 install: true 243 ) 244 245 pkgconfig.generate( 246 wayland_client, 247 name: 'Wayland Client', 248 description: 'Wayland client side library', 249 version: meson.project_version(), 250 filebase: 'wayland-client', 251 variables: [ 252 'datarootdir=' + join_paths('${prefix}', get_option('datadir')), 253 'pkgdatadir=' + join_paths('${datarootdir}', meson.project_name()) 254 ] 255 ) 256 257 wayland_client_dep = declare_dependency( 258 link_with: wayland_client, 259 include_directories: [ root_inc, include_directories('.') ], 260 sources: [ 261 wayland_client_protocol_core_h, 262 wayland_client_protocol_h 263 ] 264 ) 265 266 if meson.version().version_compare('>= 0.54.0') 267 meson.override_dependency('wayland-client', wayland_client_dep) 268 endif 269 270 install_headers([ 271 'wayland-util.h', 272 'wayland-server.h', 273 'wayland-server-core.h', 274 'wayland-client.h', 275 'wayland-client-core.h', 276 ]) 277endif 278