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