fa8541bca29f87342154459111f9b736ee01dcce
[dpdk.git] / lib / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2017-2019 Intel Corporation
3
4
5 # process all libraries equally, as far as possible
6 # "core" libs first, then others alphebetically as far as possible
7 # NOTE: for speed of meson runs, the dependencies in the subdirectories
8 # sometimes skip deps that would be implied by others, e.g. if mempool is
9 # given as a dep, no need to mention ring. This is especially true for the
10 # core libs which are widely reused, so their deps are kept to a minimum.
11 libraries = [
12         'kvargs', # eal depends on kvargs
13         'telemetry', # basic info querying
14         'eal', # everything depends on eal
15         'ring',
16         'rcu', # rcu depends on ring
17         'mempool',
18         'mbuf',
19         'net',
20         'meter',
21         'ethdev',
22         'pci', # core
23         'cmdline',
24         'metrics', # bitrate/latency stats depends on this
25         'hash',    # efd depends on this
26         'timer',   # eventdev depends on this
27         'acl',
28         'bbdev',
29         'bitratestats',
30         'bpf',
31         'cfgfile',
32         'compressdev',
33         'cryptodev',
34         'distributor',
35         'efd',
36         'eventdev',
37         'gro',
38         'gso',
39         'ip_frag',
40         'jobstats',
41         'kni',
42         'latencystats',
43         'lpm',
44         'member',
45         'pcapng',
46         'power',
47         'rawdev',
48         'regexdev',
49         'dmadev',
50         'rib',
51         'reorder',
52         'sched',
53         'security',
54         'stack',
55         'vhost',
56         'ipsec', # ipsec lib depends on net, crypto and security
57         'fib', #fib lib depends on rib
58         'port', # pkt framework libs which use other libs from above
59         'pdump', # pdump lib depends on bpf
60         'table',
61         'pipeline',
62         'flow_classify', # flow_classify lib depends on pkt framework table lib
63         'graph',
64         'node',
65 ]
66
67 if is_windows
68     libraries = [
69             'kvargs',
70             'telemetry',
71             'eal',
72             'ring',
73             'rcu',
74             'mempool',
75             'mbuf',
76             'net',
77             'meter',
78             'ethdev',
79             'dmadev',
80             'pci',
81             'cmdline',
82             'metrics',
83             'hash',
84             'timer',
85             'bitratestats',
86             'cryptodev',
87             'cfgfile',
88             'gro',
89             'gso',
90             'latencystats',
91             'stack',
92             'security',
93     ] # only supported libraries for windows
94 endif
95
96 optional_libs = [
97         'kni',
98         'power',
99         'vhost',
100 ]
101
102 disabled_libs = []
103 opt_disabled_libs = run_command(list_dir_globs, get_option('disable_libs'),
104         check: true).stdout().split()
105 foreach l:opt_disabled_libs
106     if not optional_libs.contains(l)
107         warning('Cannot disable mandatory library "@0@"'.format(l))
108         continue
109     endif
110     disabled_libs += l
111 endforeach
112
113
114 default_cflags = machine_args
115 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
116 default_cflags += ['-DALLOW_INTERNAL_API']
117
118 if cc.has_argument('-Wno-format-truncation')
119     default_cflags += '-Wno-format-truncation'
120 endif
121
122 enabled_libs = [] # used to print summary at the end
123
124 foreach l:libraries
125     build = true
126     reason = '<unknown reason>' # set if build == false to explain why
127     name = l
128     use_function_versioning = false
129     sources = []
130     headers = []
131     indirect_headers = [] # public headers not directly included by apps
132     driver_sdk_headers = [] # public headers included by drivers
133     includes = []
134     cflags = default_cflags
135     objs = [] # other object files to link against, used e.g. for
136               # instruction-set optimized versions of code
137
138     # use "deps" for internal DPDK dependencies, and "ext_deps" for
139     # external package/library requirements
140     ext_deps = []
141     deps = []
142     # eal is standard dependency once built
143     if dpdk_conf.has('RTE_LIB_EAL')
144         deps += ['eal']
145     endif
146
147     if disabled_libs.contains(l)
148         build = false
149         reason = 'explicitly disabled via build config'
150     else
151         subdir(l)
152     endif
153     if name != l
154         warning('Library name, "@0@", and directory name, "@1@", do not match'.format(name, l))
155     endif
156
157     if not build
158         dpdk_libs_disabled += name
159         set_variable(name.underscorify() + '_disable_reason', reason)
160         continue
161     endif
162
163     shared_deps = ext_deps
164     static_deps = ext_deps
165     foreach d:deps
166         if not is_variable('shared_rte_' + d)
167             error('Missing internal dependency "@0@" for @1@ [@2@]'
168                     .format(d, name, 'lib/' + l))
169         endif
170         shared_deps += [get_variable('shared_rte_' + d)]
171         static_deps += [get_variable('static_rte_' + d)]
172     endforeach
173
174     enabled_libs += name
175     dpdk_conf.set('RTE_LIB_' + name.to_upper(), 1)
176     install_headers(headers)
177     install_headers(indirect_headers)
178     if get_option('enable_driver_sdk')
179         install_headers(driver_sdk_headers)
180     endif
181     dpdk_chkinc_headers += headers
182
183     libname = 'rte_' + name
184     includes += include_directories(l)
185
186     if developer_mode and is_windows and use_function_versioning
187         message('@0@: Function versioning is not supported by Windows.'.format(name))
188     endif
189
190     if use_function_versioning
191         cflags += '-DRTE_USE_FUNCTION_VERSIONING'
192     endif
193     cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=lib.' + l
194
195     # first build static lib
196     static_lib = static_library(libname,
197             sources,
198             objects: objs,
199             c_args: cflags,
200             dependencies: static_deps,
201             include_directories: includes,
202             install: true)
203     static_dep = declare_dependency(
204             include_directories: includes,
205             dependencies: static_deps)
206
207     if not use_function_versioning or is_windows
208         # use pre-build objects to build shared lib
209         sources = []
210         objs += static_lib.extract_all_objects(recursive: false)
211     else
212         # for compat we need to rebuild with
213         # RTE_BUILD_SHARED_LIB defined
214         cflags += '-DRTE_BUILD_SHARED_LIB'
215     endif
216     version_map = '@0@/@1@/version.map'.format(
217             meson.current_source_dir(), l)
218     implib = 'librte_' + l + '.dll.a'
219
220     def_file = custom_target(libname + '_def',
221             command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
222             input: version_map,
223             output: '@0@_exports.def'.format(libname))
224
225     mingw_map = custom_target(libname + '_mingw',
226             command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
227             input: version_map,
228             output: '@0@_mingw.map'.format(libname))
229
230     if is_ms_linker
231         lk_args = ['-Wl,/def:' + def_file.full_path()]
232         if meson.version().version_compare('<0.54.0')
233             lk_args += ['-Wl,/implib:lib\\' + implib]
234         endif
235     else
236         if is_windows
237             lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
238         else
239             lk_args = ['-Wl,--version-script=' + version_map]
240         endif
241     endif
242
243     lk_deps = [version_map, def_file, mingw_map]
244     if developer_mode and not is_windows
245         # on unix systems check the output of the
246         # check-symbols.sh script, using it as a
247         # dependency of the .so build
248         lk_deps += custom_target(name + '.sym_chk',
249                 command: [check_symbols,
250                     version_map, '@INPUT@'],
251                 capture: true,
252                 input: static_lib,
253                 output: name + '.sym_chk')
254     endif
255
256     shared_lib = shared_library(libname,
257             sources,
258             objects: objs,
259             c_args: cflags,
260             dependencies: shared_deps,
261             include_directories: includes,
262             link_args: lk_args,
263             link_depends: lk_deps,
264             version: abi_version,
265             soversion: so_version,
266             install: true)
267     shared_dep = declare_dependency(link_with: shared_lib,
268             include_directories: includes,
269             dependencies: shared_deps)
270
271     dpdk_libraries = [shared_lib] + dpdk_libraries
272     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
273
274     set_variable('shared_rte_' + name, shared_dep)
275     set_variable('static_rte_' + name, static_dep)
276     if developer_mode
277         message('lib/@0@: Defining dependency "@1@"'.format(l, name))
278     endif
279 endforeach