project( 'waybar', 'cpp', 'c', version: '4.1.0', license: 'MIT', meson_version: '>= 1.3.0', default_options : [ 'cpp_std=c++23', 'buildtype=release', 'default_library=static' ], ) compiler = meson.get_compiler('cpp') cpp_args = [] cpp_link_args = [] if get_option('libcxx') cpp_args += ['-stdlib=libc++'] cpp_link_args += ['-stdlib=libc++', '-lc++abi'] endif if compiler.has_link_argument('-lc++fs') cpp_link_args += ['-lc++fs'] elif compiler.has_link_argument('-lc++experimental') cpp_link_args += ['-lc++experimental'] elif compiler.has_link_argument('-lstdc++fs') cpp_link_args += ['-lstdc++fs'] endif git = find_program('git', native: true, required: false) if not git.found() add_project_arguments('-DVERSION="@0@"'.format(meson.project_version()), language: 'cpp') else git_path = run_command([git.path(), 'rev-parse', '--show-toplevel']).stdout().strip() if meson.source_root() == git_path git_commit_hash = run_command([git.path(), 'describe', '--always', '--tags']).stdout().strip() git_branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip() version = '"@0@ (branch \'@1@\')"'.format(git_commit_hash, git_branch) add_project_arguments('-DVERSION=@0@'.format(version), language: 'cpp') else add_project_arguments('-DVERSION="@0@"'.format(meson.project_version()), language: 'cpp') endif endif if not compiler.has_header('filesystem') if compiler.has_header('experimental/filesystem') add_project_arguments('-DFILESYSTEM_EXPERIMENTAL', language: 'cpp') else add_project_arguments('-DNO_FILESYSTEM', language: 'cpp') warning('No filesystem header found, some modules may not work') endif endif code = ''' #include #include int main(int argc, char** argv) { locale_t locale = newlocale(LC_ALL, "en_US.UTF-8", nullptr); char* str; str = nl_langinfo_l(_NL_TIME_WEEK_1STDAY, locale); str = nl_langinfo_l(_NL_TIME_FIRST_WEEKDAY, locale); freelocale(locale); return 0; } ''' if compiler.links(code, name : 'nl_langinfo with _NL_TIME_WEEK_1STDAY, _NL_TIME_FIRST_WEEKDAY') add_project_arguments('-DHAVE_LANGINFO_1STDAY', language: 'cpp') endif add_global_arguments(cpp_args, language : 'cpp') add_global_link_arguments(cpp_link_args, language : 'cpp') is_linux = host_machine.system() == 'linux' is_dragonfly = host_machine.system() == 'dragonfly' is_freebsd = host_machine.system() == 'freebsd' is_netbsd = host_machine.system() == 'netbsd' is_openbsd = host_machine.system() == 'openbsd' jsoncpp = dependency('jsoncpp', version : ['>=1.9.4'], fallback : ['jsoncpp', 'jsoncpp_dep']) wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') wayland_protos = dependency('wayland-protocols') sigcpp = dependency('sigc++-3.0', version: ['>=3.4.0']) gtkmm = dependency('gtkmm-4.0', version : ['>=4.12.0']) giounix = dependency('gio-unix-2.0', version: ['>=2.76.4']) spdlog = dependency('spdlog', version : ['>=1.10.0'], fallback : ['spdlog', 'spdlog_dep'], default_options : ['external_fmt=enabled']) gtk_layer_shell = dependency('gtk4-layer-shell-0', version : ['>=1.0.2'], fallback : ['gtk4-layer-shell', 'gtk_layer_shell'], default_options : ['introspection=false', 'vapi=false']) cpp_lib_chrono = compiler.compute_int('__cpp_lib_chrono', prefix : '#include ') have_chrono_timezones = cpp_lib_chrono >= 201611 if have_chrono_timezones code = ''' #include using namespace std::chrono; int main(int argc, char** argv) { const time_zone* tz; return 0; } ''' if not compiler.links(code) have_chrono_timezones = false endif endif if have_chrono_timezones tz_dep = declare_dependency() else tz_dep = dependency('date', required: false, default_options : [ 'use_system_tzdb=true' ], modules : [ 'date::date', 'date::date-tz' ], fallback: [ 'date', 'tz_dep' ]) endif prefix = get_option('prefix') sysconfdir = get_option('sysconfdir') conf_data = configuration_data() conf_data.set('prefix', prefix) add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'cpp') src_files = files( 'src/main.cpp', 'src/client.cpp', 'src/bar.cpp', 'src/config.cpp', 'src/util/portal.cpp', 'src/util/prepare_for_sleep.cpp', 'src/AModule.cpp', 'src/ALabel.cpp', 'src/factory.cpp', 'src/util/ustring_clen.cpp', 'src/group.cpp' ) man_files = files( 'man/waybar-custom.5.scd', 'man/waybar-disk.5.scd', 'man/waybar-idle-inhibitor.5.scd', 'man/waybar-image.5.scd', 'man/waybar-states.5.scd', 'man/waybar-temperature.5.scd', ) if have_chrono_timezones add_project_arguments('-DHAVE_CHRONO_TIMEZONES', language: 'cpp') src_files += files('src/modules/clock.cpp') man_files += files('man/waybar-clock.5.scd') elif tz_dep.found() add_project_arguments('-DHAVE_LIBDATE', language: 'cpp') src_files += files('src/modules/clock.cpp') man_files += files('man/waybar-clock.5.scd') else src_files += files('src/modules/simpleclock.cpp') man_files += files('man/waybar-clock.5.scd') endif if get_option('experimental') add_project_arguments('-DUSE_EXPERIMENTAL', language: 'cpp') endif cava = dependency('cava', version : '>=0.10.1', required: get_option('cava'), fallback : ['cava', 'cava_dep'], not_found_message: 'cava is not found. Building waybar without cava') if cava.found() add_project_arguments('-DHAVE_LIBCAVA', language: 'cpp') src_files += files('src/modules/cava.cpp') man_files += files('man/waybar-cava.5.scd') endif inc_dirs = ['include'] subdir('protocol') executable( 'waybar', [src_files], dependencies: [ gtk_layer_shell, gtkmm, giounix, sigcpp, jsoncpp, wayland_client, wayland_cursor, client_protos, spdlog, cava ], include_directories: inc_dirs, install: true, ) install_data( './resources/config', './resources/style.css', install_dir: sysconfdir + '/xdg/waybar' )