Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 1 | project( |
| 2 | 'dbus-sensor-tester', |
| 3 | 'cpp', |
| 4 | version: '1.0', |
| 5 | meson_version: '>=1.1.1', |
| 6 | default_options: [ |
| 7 | 'b_lto_mode=default', |
| 8 | 'b_lto_threads=0', |
| 9 | 'b_lto=true', |
| 10 | 'b_ndebug=if-release', |
| 11 | 'buildtype=debugoptimized', |
| 12 | 'cpp_rtti=false', |
| 13 | 'cpp_std=c++23', |
| 14 | 'warning_level=3', |
| 15 | 'werror=true', |
| 16 | ], |
| 17 | ) |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 18 | |
| 19 | # Project related links |
| 20 | |
| 21 | project_pretty_name = 'dbus-sensor-tester' |
| 22 | |
| 23 | # Validate the c++ Standard |
| 24 | |
Patrick Williams | cff0bfa | 2023-07-12 11:28:17 -0500 | [diff] [blame] | 25 | if get_option('cpp_std') != 'c++23' |
| 26 | error('This project requires c++23 support') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 27 | endif |
| 28 | |
| 29 | # Get compiler and default build type |
| 30 | |
| 31 | cxx = meson.get_compiler('cpp') |
| 32 | build = get_option('buildtype') |
| 33 | optimization = get_option('optimization') |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 34 | summary('Build Type', build, section: 'Build Info') |
| 35 | summary('Optimization', optimization, section: 'Build Info') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 36 | |
| 37 | # Disable lto when compiling with no optimization |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 38 | if (get_option('optimization') == '0') |
| 39 | add_project_arguments('-fno-lto', language: 'cpp') |
| 40 | message('Disabling lto & its supported features as optimization is disabled') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 41 | endif |
| 42 | |
| 43 | # Add compiler arguments |
| 44 | |
| 45 | # -Wpedantic, -Wextra comes by default with warning level |
| 46 | add_project_arguments( |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 47 | cxx.get_supported_arguments( |
| 48 | [ |
| 49 | '-Wcast-align', |
| 50 | '-Wconversion', |
| 51 | '-Wformat=2', |
| 52 | '-Wold-style-cast', |
| 53 | '-Woverloaded-virtual', |
| 54 | '-Wsign-conversion', |
| 55 | '-Wunused', |
| 56 | '-Wno-attributes', |
| 57 | ], |
| 58 | ), |
| 59 | language: 'cpp', |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 60 | ) |
| 61 | |
| 62 | if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0')) |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 63 | add_project_arguments( |
| 64 | cxx.get_supported_arguments( |
| 65 | [ |
| 66 | '-Weverything', |
| 67 | '-Wno-c++98-compat-pedantic', |
| 68 | '-Wno-c++98-compat', |
| 69 | '-Wno-documentation-unknown-command', |
| 70 | '-Wno-documentation', |
| 71 | '-Wno-exit-time-destructors', |
| 72 | '-Wno-global-constructors', |
| 73 | '-Wno-newline-eof', |
| 74 | '-Wno-padded', |
| 75 | '-Wno-shadow', |
| 76 | '-Wno-used-but-marked-unused', |
| 77 | '-Wno-weak-vtables', |
| 78 | ], |
| 79 | ), |
| 80 | language: 'cpp', |
| 81 | ) |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 82 | endif |
| 83 | |
| 84 | # if compiler is gnu-gcc , and version is > 8.0 then we add few more |
| 85 | # compiler arguments , we know that will pass |
| 86 | |
| 87 | if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0')) |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 88 | add_project_arguments( |
| 89 | cxx.get_supported_arguments( |
| 90 | [ |
| 91 | '-Wduplicated-cond', |
| 92 | '-Wduplicated-branches', |
| 93 | '-Wlogical-op', |
| 94 | '-Wunused-parameter', |
| 95 | '-Wnull-dereference', |
| 96 | '-Wdouble-promotion', |
| 97 | ], |
| 98 | ), |
| 99 | language: 'cpp', |
| 100 | ) |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 101 | endif |
| 102 | |
| 103 | # Find the dependency modules, if not found use meson wrap to get them |
| 104 | # automatically during the configure step |
| 105 | dependencies = [] |
| 106 | |
Patrick Williams | 2c89980 | 2025-08-11 11:21:30 -0400 | [diff] [blame] | 107 | sdbusplus = dependency('sdbusplus') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 108 | dependencies += sdbusplus |
| 109 | |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 110 | cli11 = dependency('cli11', required: false, include_type: 'system') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 111 | if not cli11.found() |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 112 | cli11_proj = subproject('cli11', required: true) |
| 113 | cli11 = cli11_proj.get_variable('CLI11_dep') |
| 114 | cli11 = cli11.as_system('system') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 115 | endif |
| 116 | dependencies += cli11 |
| 117 | |
| 118 | systemd = dependency('systemd') |
| 119 | dependencies += [systemd] |
| 120 | |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 121 | boost = dependency( |
| 122 | 'boost', |
| 123 | version: '>=1.78.0', |
| 124 | required: false, |
| 125 | include_type: 'system', |
| 126 | ) |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 127 | if not boost.found() |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 128 | subproject('boost', required: false) |
| 129 | boost_inc = include_directories('subprojects/boost_1_78_0/', is_system: true) |
| 130 | boost = declare_dependency(include_directories: boost_inc) |
| 131 | boost = boost.as_system('system') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 132 | endif |
| 133 | dependencies += boost |
| 134 | |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 135 | srcfiles_sensortest = [] |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 136 | |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 137 | systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir') |
| 138 | bindir = get_option('prefix') + '/' + get_option('bindir') |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 139 | |
| 140 | # Generate the executable |
| 141 | executable( |
Patrick Williams | ecd3bee | 2025-07-09 11:41:58 -0400 | [diff] [blame] | 142 | 'sensortest', |
| 143 | srcfiles_sensortest + ['main.cpp'], |
| 144 | dependencies: dependencies, |
| 145 | link_args: '-Wl,--gc-sections', |
| 146 | install: true, |
| 147 | install_dir: bindir, |
Ed Tanous | b3ef7f2 | 2022-03-30 14:03:41 -0700 | [diff] [blame] | 148 | ) |