blob: 6cafb2062b87b19411a9c9694be70f69388d4583 [file] [log] [blame]
Patrick Williamsecd3bee2025-07-09 11:41:58 -04001project(
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 Tanousb3ef7f22022-03-30 14:03:41 -070018
19# Project related links
20
21project_pretty_name = 'dbus-sensor-tester'
22
23# Validate the c++ Standard
24
Patrick Williamscff0bfa2023-07-12 11:28:17 -050025if get_option('cpp_std') != 'c++23'
26 error('This project requires c++23 support')
Ed Tanousb3ef7f22022-03-30 14:03:41 -070027endif
28
29# Get compiler and default build type
30
31cxx = meson.get_compiler('cpp')
32build = get_option('buildtype')
33optimization = get_option('optimization')
Patrick Williamsecd3bee2025-07-09 11:41:58 -040034summary('Build Type', build, section: 'Build Info')
35summary('Optimization', optimization, section: 'Build Info')
Ed Tanousb3ef7f22022-03-30 14:03:41 -070036
37# Disable lto when compiling with no optimization
Patrick Williamsecd3bee2025-07-09 11:41:58 -040038if (get_option('optimization') == '0')
39 add_project_arguments('-fno-lto', language: 'cpp')
40 message('Disabling lto & its supported features as optimization is disabled')
Ed Tanousb3ef7f22022-03-30 14:03:41 -070041endif
42
43# Add compiler arguments
44
45# -Wpedantic, -Wextra comes by default with warning level
46add_project_arguments(
Patrick Williamsecd3bee2025-07-09 11:41:58 -040047 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 Tanousb3ef7f22022-03-30 14:03:41 -070060)
61
62if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
Patrick Williamsecd3bee2025-07-09 11:41:58 -040063 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 Tanousb3ef7f22022-03-30 14:03:41 -070082endif
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
87if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
Patrick Williamsecd3bee2025-07-09 11:41:58 -040088 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 Tanousb3ef7f22022-03-30 14:03:41 -0700101endif
102
103# Find the dependency modules, if not found use meson wrap to get them
104# automatically during the configure step
105dependencies = []
106
Patrick Williams2c899802025-08-11 11:21:30 -0400107sdbusplus = dependency('sdbusplus')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700108dependencies += sdbusplus
109
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400110cli11 = dependency('cli11', required: false, include_type: 'system')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700111if not cli11.found()
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400112 cli11_proj = subproject('cli11', required: true)
113 cli11 = cli11_proj.get_variable('CLI11_dep')
114 cli11 = cli11.as_system('system')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700115endif
116dependencies += cli11
117
118systemd = dependency('systemd')
119dependencies += [systemd]
120
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400121boost = dependency(
122 'boost',
123 version: '>=1.78.0',
124 required: false,
125 include_type: 'system',
126)
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700127if not boost.found()
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400128 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 Tanousb3ef7f22022-03-30 14:03:41 -0700132endif
133dependencies += boost
134
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400135srcfiles_sensortest = []
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700136
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400137systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir')
138bindir = get_option('prefix') + '/' + get_option('bindir')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700139
140# Generate the executable
141executable(
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400142 'sensortest',
143 srcfiles_sensortest + ['main.cpp'],
144 dependencies: dependencies,
145 link_args: '-Wl,--gc-sections',
146 install: true,
147 install_dir: bindir,
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700148)