blob: 2a17442f83e09ed99a4c80fc90efd3ff01700b4d [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 Williamsecd3bee2025-07-09 11:41:58 -0400107sdbusplus = dependency('sdbusplus', required: false, include_type: 'system')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700108if not sdbusplus.found()
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400109 sdbusplus_proj = subproject('sdbusplus', required: true)
110 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
111 sdbusplus = sdbusplus.as_system('system')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700112endif
113dependencies += sdbusplus
114
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400115cli11 = dependency('cli11', required: false, include_type: 'system')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700116if not cli11.found()
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400117 cli11_proj = subproject('cli11', required: true)
118 cli11 = cli11_proj.get_variable('CLI11_dep')
119 cli11 = cli11.as_system('system')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700120endif
121dependencies += cli11
122
123systemd = dependency('systemd')
124dependencies += [systemd]
125
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400126boost = dependency(
127 'boost',
128 version: '>=1.78.0',
129 required: false,
130 include_type: 'system',
131)
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700132if not boost.found()
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400133 subproject('boost', required: false)
134 boost_inc = include_directories('subprojects/boost_1_78_0/', is_system: true)
135 boost = declare_dependency(include_directories: boost_inc)
136 boost = boost.as_system('system')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700137endif
138dependencies += boost
139
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400140srcfiles_sensortest = []
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700141
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400142systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir')
143bindir = get_option('prefix') + '/' + get_option('bindir')
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700144
145# Generate the executable
146executable(
Patrick Williamsecd3bee2025-07-09 11:41:58 -0400147 'sensortest',
148 srcfiles_sensortest + ['main.cpp'],
149 dependencies: dependencies,
150 link_args: '-Wl,--gc-sections',
151 install: true,
152 install_dir: bindir,
Ed Tanousb3ef7f22022-03-30 14:03:41 -0700153)