1# -*- mode: meson -*- 2 3# Style objective: be consistent with what mesonbuild.com documents/uses, and/or 4# the meson book: https://meson-manual.com/ 5 6project( 7 'i3status', 8 'c', 9 version: '2.14', 10 default_options: [ 11 'c_std=c11', 12 'warning_level=1', # enable all warnings (-Wall) 13 # TODO(https://github.com/i3/i3/issues/4087): switch to 14 # 'buildtype=debugoptimized', 15 ], 16 # Ubuntu 18.04 (supported until 2023) has meson 0.45. 17 # We can revisit our minimum supported meson version 18 # if it turns out to be too hard to maintain. 19 meson_version: '>=0.45.0', 20) 21 22cc = meson.get_compiler('c') 23add_project_arguments(cc.get_supported_arguments(['-Wunused-value']), language: 'c') 24 25if meson.version().version_compare('>=0.48.0') 26 # https://github.com/mesonbuild/meson/issues/2166#issuecomment-629696911 27 meson.add_dist_script('meson/meson-dist-script') 28else 29 message('meson <0.48.0 detected, dist tarballs will not be filtered') 30endif 31 32################################################################################ 33# Version handling 34################################################################################ 35 36cdata = configuration_data() 37 38version_array = meson.project_version().split('.') 39cdata.set_quoted('I3STATUS_VERSION', '@VCS_TAG@') 40cdata.set_quoted('SYSCONFDIR', join_paths(get_option('prefix'), get_option('sysconfdir'))) 41 42if get_option('b_sanitize').split(',').contains('address') 43 cdata.set('I3STATUS_ASAN_ENABLED', 1) 44endif 45 46cdata.set('HAVE_STRNDUP', cc.has_function('strndup')) 47cdata.set('HAVE_MKDIRP', cc.has_function('mkdirp')) 48 49if get_option('pulseaudio') 50 cdata.set('HAS_PULSEAUDIO', 1) 51endif 52 53# Instead of generating config.h directly, make vcs_tag generate it so that 54# @VCS_TAG@ is replaced. 55config_h_in = configure_file( 56 output: 'config.h.in', 57 configuration: cdata, 58) 59config_h = declare_dependency( 60 sources: vcs_tag( 61 input: config_h_in, 62 output: 'config.h', 63 fallback: meson.project_version() + '-non-git', 64 ) 65) 66 67################################################################################ 68# manpages 69################################################################################ 70 71man1 = join_paths(get_option('mandir'), 'man1') 72 73if get_option('mans') 74 asciidoc = find_program('asciidoc') 75 asciidoc_cdata = configuration_data() 76 asciidoc_cdata.set('PACKAGE_VERSION', meson.project_version()) 77 asciidoc_conf = configure_file( 78 input: 'man/asciidoc.conf.in', 79 output: 'asciidoc.conf', 80 configuration: asciidoc_cdata, 81 ) 82 83 xmlto = find_program('xmlto') 84 85 pod2man = find_program('pod2man') 86 87 man_inputs = [ 88 'man/i3status.man', 89 ] 90 91 foreach m : man_inputs 92 xml = custom_target( 93 m.underscorify()+'_asciidoc', 94 input: m, 95 output: '@BASENAME@.xml', 96 command: [ 97 asciidoc, 98 '-d', 'manpage', 99 '-b', 'docbook', 100 '-f', asciidoc_conf, 101 '-o', '@OUTPUT@', 102 '@INPUT@', 103 ], 104 ) 105 106 custom_target( 107 m.underscorify()+'_xmlto', 108 input: xml, 109 output: '@BASENAME@.1', 110 command: [ 111 xmlto, 112 'man', 113 '-o', 114 '@OUTDIR@', 115 '@INPUT@', 116 ], 117 # We should use install and install_dir instead of install_man as per: 118 # https://github.com/mesonbuild/meson/issues/4981#issuecomment-467084867 119 # https://github.com/mesonbuild/meson/issues/1550#issuecomment-370164307 120 install: true, 121 install_dir: man1, 122 ) 123 endforeach 124 125else 126 if run_command('[', '-f', 'man/i3status.1', ']').returncode() == 0 127 install_data( 128 [ 129 'man/i3status.1', 130 ], 131 install_dir: man1, 132 ) 133 endif 134endif 135 136if meson.version().version_compare('>=0.53') 137 summary('build manpages (-Dmans)', get_option('mans')) 138 summary('build pulseaudio support (-Dpulseaudio)', get_option('pulseaudio')) 139endif 140 141# Required for e.g. struct ucred to be defined as per unix(7). 142add_project_arguments('-D_GNU_SOURCE', language: 'c') 143 144# https://mesonbuild.com/howtox.html#add-math-library-lm-portably 145m_dep = cc.find_library('m', required: false) 146rt_dep = cc.find_library('rt', required: false) 147 148confuse_dep = dependency('libconfuse', method: 'pkg-config') 149yajl_dep = dependency('yajl', method: 'pkg-config') 150 151i3status_srcs = [ 152 'i3status.c', 153 'src/auto_detect_format.c', 154 'src/first_network_device.c', 155 'src/format_placeholders.c', 156 'src/general.c', 157 'src/output.c', 158 'src/print_battery_info.c', 159 'src/print_cpu_temperature.c', 160 'src/print_cpu_usage.c', 161 'src/print_ddate.c', 162 'src/print_disk_info.c', 163 'src/print_eth_info.c', 164 'src/print_ip_addr.c', 165 'src/print_ipv6_addr.c', 166 'src/print_load.c', 167 'src/print_mem.c', 168 'src/print_path_exists.c', 169 'src/print_run_watch.c', 170 'src/print_time.c', 171 'src/print_volume.c', 172 'src/print_wireless_info.c', 173 'src/print_file_contents.c', 174 'src/process_runs.c', 175] 176 177thread_dep = dependency('threads') 178 179i3status_deps = [ 180 thread_dep, 181 m_dep, 182 rt_dep, 183 confuse_dep, 184 yajl_dep, 185 config_h, 186] 187 188if get_option('pulseaudio') 189 pulse_dep = dependency('libpulse', method: 'pkg-config') 190 i3status_deps += [pulse_dep] 191 i3status_srcs += ['src/pulse.c'] 192endif 193 194host_os = host_machine.system() 195if host_os == 'linux' 196 nlgenl_dep = dependency('libnl-genl-3.0', method: 'pkg-config') 197 alsa_dep = dependency('alsa', method: 'pkg-config') 198 i3status_deps += [nlgenl_dep, alsa_dep] 199endif 200if host_os == 'netbsd' 201 prop_dep = cc.find_library('prop') 202 i3status_deps += [prop_dep] 203endif 204 205inc = include_directories('include') 206 207executable( 208 'i3status', 209 i3status_srcs, 210 install: true, 211 include_directories: inc, 212 dependencies: i3status_deps, 213) 214 215install_subdir( 216 'etc', 217 strip_directory: true, 218 install_dir: get_option('sysconfdir'), 219) 220 221# We cannot use configure_file for run-tests.pl.in 222# because configure_file strips the backslash in e.g. \@display, 223# resulting in @display, breaking our Perl code: 224# https://github.com/mesonbuild/meson/issues/7165 225sh = find_program('sh') 226replace_dirs = [ 227 sh, '-c', # Use bash to capture output and mark as executable 228 'sed -e \'s,@abs_top_builddir@,' 229 + meson.current_build_dir() 230 + ',g;s,@abs_top_srcdir@,' 231 + meson.current_source_dir()+',g\'' 232 # Only mark files ending in .pl as executables 233 + ' "$0" > "$1" && { [ "${1##*.}" = pl ] && chmod +x "$1" || true; }', 234 '@INPUT0@', # $0 235 '@OUTPUT0@', # $1 236] 237run_tests = custom_target( 238 'run-tests', 239 input: ['travis/run-tests.pl.in'], 240 output: ['run-tests.pl'], 241 command: replace_dirs, 242 # build this target when running e.g. ninja or ninja test. 243 # This is required for older meson versions (< 0.46.0). 244 build_by_default: true, 245) 246 247perl = find_program('perl') 248if meson.version().version_compare('>=0.46.0') 249 test( 250 'run-tests', 251 perl, 252 args: [run_tests], 253 timeout: 120, # Default of 30 seconds can cause timeouts on slower machines 254 ) 255else 256 # meson < 0.46.0 does not support the depends arg in test targets. 257 # Just hope for the best. 258 test( 259 'run-tests', 260 perl, 261 args: [run_tests], 262 ) 263 message('meson < 0.46 detected, you might need to run ninja test twice') 264endif 265