summaryrefslogtreecommitdiff
path: root/meson.build
blob: ad24d316a7e4fc6f747bdd2c0df3fb6811c65d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
project(
    'virtual-media',
    'cpp',
    default_options: [
        'warning_level=3',
        'werror=true',
        'cpp_std=c++20',
        'cpp_rtti=false',
    ],
    license: 'Apache-2.0',
    version: '0.1',
)

if get_option('cpp_std') != 'c++20'
    error('This project requires c++20 support')
endif

cxx = meson.get_compiler('cpp')

build = get_option('buildtype')
optimization = get_option('optimization')
summary('Build Type',build, section : 'Build Info')
summary('Optimization',optimization, section : 'Build Info')

#remove debug information for minsize buildtype
if(get_option('buildtype') == 'minsize')
  add_project_arguments('-DNDEBUG', language : 'cpp')
endif

#Disable lto when compiling with no optimization
if(get_option('optimization') == '0')
  add_project_arguments('-fno-lto', language: 'cpp')
  message('Disabling lto & its supported features as optimization is disabled')
endif

incdir = include_directories('src')

add_project_arguments(
  cxx.get_supported_arguments([
  '-Wold-style-cast',
  '-Wcast-align',
  '-Wunused',
  '-Wunused-parameter',
  '-Wconversion',
  '-Wsign-conversion',
  '-Wno-attributes',
   ]),
  language: 'cpp'
)

# temporarily disable those flags until async dbus fixes are not merged
# See http://goto.intel.com/async-dbus-pr for status
add_project_arguments(
  cxx.get_supported_arguments([
  '-Wno-missing-field-initializers',
  '-Wno-unused-parameter',
  '-Wno-unused',
   ]),
  language: 'cpp'
)

if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
add_project_arguments(
  cxx.get_supported_arguments([
    '-Weverything',
    '-Wno-c++98-compat',
    '-Wno-c++98-compat-pedantic',
    '-Wno-global-constructors',
    '-Wno-exit-time-destructors',
    '-Wno-shadow',
    '-Wno-used-but-marked-unused',
    '-Wno-documentation-unknown-command',
    '-Wno-weak-vtables',
    '-Wno-documentation',
    '-Wno-padded',
    '-Wcovered-switch-default',
    '-Wcomma',
    '-Wextra-semi',
    '-Wzero-as-null-pointer-constant',
    '-Wswitch-enum',
    '-Wnull-dereference',
    '-Wdouble-promotion',
    '-Wformat=2',
  ]),
  language:'cpp')
endif

if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
  add_project_arguments(
    cxx.get_supported_arguments([
     '-Wduplicated-cond',
     '-Wduplicated-branches',
     '-Wlogical-op',
     '-Wnull-dereference',
     '-Wdouble-promotion',
     '-Wformat=2',
     ]),
    language:'cpp')

  if (get_option('buildtype') != 'plain')
    if (get_option('b_lto') == true and get_option('optimization')!='0')
#Reduce the binary size by removing unnecessary
#dynamic symbol table entries

      add_project_arguments(
       cxx.get_supported_arguments([
       '-fno-fat-lto-objects',
       '-fvisibility=hidden',
       '-fvisibility-inlines-hidden'
       ]),
       language: 'cpp')

      if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
        add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
      endif
    endif
  endif
endif

security_flags = [
'-fstack-protector-strong',
'-fPIE',
'-fPIC',
'-D_FORTIFY_SOURCE=2',
'-Wformat',
'-Wformat-security'
]

## Add security flags for builds of type 'release','debugoptimized' and 'minsize'

if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
  add_project_arguments(
   cxx.get_supported_arguments([
    security_flags
  ]),
  language: 'cpp')
endif

systemd = dependency('systemd')
udev = dependency('udev')
# this will add appopriate udev library linkage to executable.
udev_lib_dep = declare_dependency(link_args: ['-ludev'])


if cxx.has_header('nlohmann/json.hpp')
    nlohmann_json = declare_dependency()
else
    nlohmann_json_proj = subproject('nlohmann', required: true)
    nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep')
    nlohmann_json = nlohmann_json.as_system('system')
endif

sdbusplus = dependency('sdbusplus', required: false)
if not sdbusplus.found()
  sdbusplus_proj = subproject('sdbusplus', required: true)
  sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
  sdbusplus = sdbusplus.as_system('system')
endif

boost = dependency('boost',
                   modules: ['coroutine', 'iostreams', 'filesystem',
			     'program_options', 'regex', 'system'],
                   version: '>=1.77',
                   fallback : ['boost', 'boost_dep'],
                   static: false,
                   required: true)


add_project_arguments(
cxx.get_supported_arguments([
'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
'-DBOOST_ASIO_DISABLE_THREADS',
'-DBOOST_NO_RTTI',
'-DBOOST_NO_TYPEID',
'-DBOOST_ALLOW_DEPRECATED_HEADERS'
]),
language : 'cpp')

systemd_system_unit_dir = systemd.get_pkgconfig_variable(
    'systemdsystemunitdir'
)


configure_file(input: 'xyz.openbmc_project.VirtualMedia.service',
               output: 'xyz.openbmc_project.VirtualMedia.service',
               install_dir: systemd_system_unit_dir,
               copy: true,
               install: true)

configure_file(input : 'tmpfiles.d/virtual-media.conf',
               output : 'virtual-media.conf',
               copy : true,
               install_dir: '/etc/tmpfiles.d',
               install : true)

configure_file(input : 'virtual-media.json',
               output : 'virtual-media.json',
               copy : true,
               install_dir: '/etc/',
               install : true)

srcfiles_app = [ 'src/main.cpp',
                 'src/resources.cpp',
                 'src/state/activating_state.cpp',
               ]

bindir = get_option('prefix') + '/' +get_option('bindir')

if get_option('legacy-mode').enabled()
  add_project_arguments(
    cxx.get_supported_arguments([
      '-DLEGACY_MODE_ENABLED=ON',]),
    language: 'cpp')
endif

executable('virtual-media',
           srcfiles_app,
           dependencies: [ systemd, boost, udev, udev_lib_dep,
                           sdbusplus, nlohmann_json,
           ],
           include_directories: incdir,
           install: true,
           install_dir:bindir)

#Tests are placed in the tests folder, with it's own meson.build
if (get_option('tests').enabled())
    subdir('tests')
endif