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