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