1project( 2 'swayidle', 3 'c', 4 version: '1.7.1', 5 license: 'MIT', 6 meson_version: '>=0.50.0', 7 default_options: [ 8 'c_std=c11', 9 'warning_level=2', 10 'werror=true', 11 ], 12) 13 14add_project_arguments( 15 [ 16 '-Wno-unused-parameter', 17 '-Wno-unused-result', 18 '-Wundef', 19 '-Wvla', 20 ], 21 language: 'c', 22) 23 24sysconfdir = get_option('sysconfdir') 25prefix = get_option('prefix') 26add_project_arguments( 27 '-DSYSCONFDIR="@0@"'.format(join_paths(prefix, sysconfdir)), 28 language : 'c') 29 30wayland_client = dependency('wayland-client') 31wayland_protos = dependency('wayland-protocols', version: '>=1.14') 32wayland_server = dependency('wayland-server') 33bash_comp = dependency('bash-completion', required: false) 34fish_comp = dependency('fish', required: false) 35 36scdoc = find_program('scdoc', required: get_option('man-pages')) 37wayland_scanner = find_program('wayland-scanner') 38 39wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir') 40 41if wayland_server.version().version_compare('>=1.14.91') 42 code_type = 'private-code' 43else 44 code_type = 'code' 45endif 46 47wayland_scanner_code = generator( 48 wayland_scanner, 49 output: '@BASENAME@-protocol.c', 50 arguments: [code_type, '@INPUT@', '@OUTPUT@'], 51) 52 53wayland_scanner_client = generator( 54 wayland_scanner, 55 output: '@BASENAME@-client-protocol.h', 56 arguments: ['client-header', '@INPUT@', '@OUTPUT@'], 57) 58 59client_protos_src = wayland_scanner_code.process('idle.xml') 60client_protos_headers = wayland_scanner_client.process('idle.xml') 61 62lib_client_protos = static_library( 63 'client_protos', 64 [client_protos_src, client_protos_headers], 65 dependencies: [wayland_client] 66) # for the include directory 67 68client_protos = declare_dependency( 69 link_with: lib_client_protos, 70 sources: client_protos_headers, 71) 72 73swayidle_deps = [ 74 client_protos, 75 wayland_client, 76 wayland_server, 77] 78 79if get_option('sd-bus-provider') == 'auto' 80 if not get_option('logind').disabled() 81 assert(get_option('auto_features').auto(), 'sd-bus-provider must not be set to auto since auto_features != auto') 82 endif 83 sdbus = dependency('libsystemd', 84 required: false, 85 not_found_message: 'libsystemd not found, trying libelogind', 86 ) 87 if not sdbus.found() 88 sdbus = dependency('libelogind', 89 required: false, 90 not_found_message: 'libelogind not found, trying basu', 91 ) 92 endif 93 if not sdbus.found() 94 sdbus = dependency('basu', required: false) 95 endif 96else 97 sdbus = dependency(get_option('sd-bus-provider'), required: get_option('logind')) 98endif 99 100logind_deps_found = sdbus.found() 101if get_option('logind').enabled() and not logind_deps_found 102 error('Building with -Dlogind=enabled, but sd-bus has not been not found') 103endif 104have_logind = (not get_option('logind').disabled()) and logind_deps_found 105 106if have_logind 107 swayidle_deps += sdbus 108endif 109 110conf_data = configuration_data() 111 112conf_data.set10('HAVE_LIBSYSTEMD', sdbus.found() and sdbus.name() == 'libsystemd') 113conf_data.set10('HAVE_LIBELOGIND', sdbus.found() and sdbus.name() == 'libelogind') 114conf_data.set10('HAVE_BASU', sdbus.found() and sdbus.name() == 'basu') 115conf_data.set10('HAVE_LOGIND', have_logind) 116 117configure_file(output: 'config.h', configuration: conf_data) 118 119executable( 120 'swayidle', [ 121 'main.c', 122 ], 123 dependencies: swayidle_deps, 124 install: true, 125) 126 127if scdoc.found() 128 sh = find_program('sh') 129 mandir = get_option('mandir') 130 man_files = [ 131 'swayidle.1.scd', 132 ] 133 foreach filename : man_files 134 topic = filename.split('.')[-3].split('/')[-1] 135 section = filename.split('.')[-2] 136 output = '@0@.@1@'.format(topic, section) 137 138 custom_target( 139 output, 140 input: filename, 141 output: output, 142 command: [ 143 sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc.path(), output) 144 ], 145 install: true, 146 install_dir: '@0@/man@1@'.format(mandir, section) 147 ) 148 endforeach 149endif 150 151datadir = get_option('datadir') 152 153if get_option('zsh-completions') 154 zsh_files = files( 155 'completions/zsh/_swayidle', 156 ) 157 zsh_install_dir = datadir + '/zsh/site-functions' 158 159 install_data(zsh_files, install_dir: zsh_install_dir) 160endif 161 162if get_option('bash-completions') 163 bash_files = files( 164 'completions/bash/swayidle', 165 ) 166 if bash_comp.found() 167 bash_install_dir = bash_comp.get_pkgconfig_variable('completionsdir') 168 else 169 bash_install_dir = datadir + '/bash-completion/completions' 170 endif 171 172 install_data(bash_files, install_dir: bash_install_dir) 173endif 174 175if get_option('fish-completions') 176 fish_files = files( 177 'completions/fish/swayidle.fish', 178 ) 179 if fish_comp.found() 180 fish_install_dir = fish_comp.get_pkgconfig_variable('completionsdir') 181 else 182 fish_install_dir = datadir + '/fish/vendor_completions.d' 183 endif 184 185 install_data(fish_files, install_dir: fish_install_dir) 186endif 187