c28b8df83d4964fbf412455e09a7baa54799ca07
[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         'eal', # everything depends on eal
14         'ring',
15         'rcu', # rcu depends on ring
16         'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
17         'cmdline',
18         'metrics', # bitrate/latency stats depends on this
19         'hash',    # efd depends on this
20         'timer',   # eventdev depends on this
21         'acl', 'bbdev', 'bitratestats', 'cfgfile',
22         'compressdev', 'cryptodev',
23         'distributor', 'efd', 'eventdev',
24         'gro', 'gso', 'ip_frag', 'jobstats',
25         'kni', 'latencystats', 'lpm', 'member',
26         'power', 'pdump', 'rawdev',
27         'rib', 'reorder', 'sched', 'security', 'stack', 'vhost',
28         # ipsec lib depends on net, crypto and security
29         'ipsec',
30         #fib lib depends on rib
31         'fib',
32         # add pkt framework libs which use other libs from above
33         'port', 'table', 'pipeline',
34         # flow_classify lib depends on pkt framework table lib
35         'flow_classify', 'bpf', 'telemetry']
36
37 if is_windows
38         libraries = ['kvargs','eal'] # only supported libraries for windows
39 endif
40
41 default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
42 if cc.has_argument('-Wno-format-truncation')
43         default_cflags += '-Wno-format-truncation'
44 endif
45
46 enabled_libs = [] # used to print summary at the end
47
48 foreach l:libraries
49         build = true
50         reason = '<unknown reason>' # set if build == false to explain why
51         name = l
52         use_function_versioning = false
53         sources = []
54         headers = []
55         includes = []
56         cflags = default_cflags
57         objs = [] # other object files to link against, used e.g. for
58                   # instruction-set optimized versions of code
59
60         # use "deps" for internal DPDK dependencies, and "ext_deps" for
61         # external package/library requirements
62         ext_deps = []
63         deps = []
64         # eal is standard dependency once built
65         if dpdk_conf.has('RTE_LIBRTE_EAL')
66                 deps += ['eal']
67         endif
68
69         dir_name = 'librte_' + l
70         subdir(dir_name)
71
72         if build
73                 shared_deps = ext_deps
74                 static_deps = ext_deps
75                 foreach d:deps
76                         if not is_variable('shared_rte_' + d)
77                                 error('Missing internal dependency "@0@" for @1@ [@2@]'
78                                                 .format(d, name, 'lib/' + dir_name))
79                         endif
80                         shared_deps += [get_variable('shared_rte_' + d)]
81                         static_deps += [get_variable('static_rte_' + d)]
82                 endforeach
83         endif
84
85         if not build
86                 dpdk_libs_disabled += name
87                 set_variable(name.underscorify() + '_disable_reason', reason)
88         else
89                 enabled_libs += name
90                 dpdk_conf.set('RTE_LIBRTE_' + name.to_upper(), 1)
91                 install_headers(headers)
92
93                 libname = 'rte_' + name
94                 includes += include_directories(dir_name)
95
96                 if sources.length() == 0
97                         # if no C files, just set a dependency on header path
98                         shared_dep = declare_dependency(include_directories: includes)
99                         static_dep = shared_dep
100                 else
101
102                         if use_function_versioning
103                                 cflags += '-DRTE_USE_FUNCTION_VERSIONING'
104                         endif
105
106                         version_map = '@0@/@1@/rte_@2@_version.map'.format(
107                                         meson.current_source_dir(), dir_name, name)
108
109                         is_experimental = run_command(is_experimental_cmd,
110                                         files(version_map)).returncode()
111
112                         if is_experimental != 0
113                                 lib_version = experimental_abi_version
114                                 so_version = experimental_so_version
115                         else
116                                 lib_version = abi_version
117                                 so_version = stable_so_version
118                         endif
119
120                         # first build static lib
121                         static_lib = static_library(libname,
122                                         sources,
123                                         objects: objs,
124                                         c_args: cflags,
125                                         dependencies: static_deps,
126                                         include_directories: includes,
127                                         install: true)
128                         static_dep = declare_dependency(link_with: static_lib,
129                                         include_directories: includes,
130                                         dependencies: static_deps)
131
132                         if not use_function_versioning
133                                 # use pre-build objects to build shared lib
134                                 sources = []
135                                 objs += static_lib.extract_all_objects(recursive: false)
136                         else
137                                 # for compat we need to rebuild with
138                                 # RTE_BUILD_SHARED_LIB defined
139                                 cflags += '-DRTE_BUILD_SHARED_LIB'
140                         endif
141                         version_map = '@0@/@1@/rte_@2@_version.map'.format(
142                                         meson.current_source_dir(), dir_name, name)
143                         implib = dir_name + '.dll.a'
144
145                         def_file = custom_target(name + '_def',
146                                 command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'],
147                                 input: version_map,
148                                 output: 'rte_@0@_exports.def'.format(name))
149
150                         if is_ms_linker
151                                 lk_args = ['-Wl,/def:' + def_file.full_path(),
152                                         '-Wl,/implib:lib\\' + implib]
153                         else
154                                 lk_args = ['-Wl,--version-script=' + version_map]
155                         endif
156
157                         lk_deps = [version_map, def_file]
158                         if not is_windows
159                                 # on unix systems check the output of the
160                                 # experimental syms script, using it as a
161                                 # dependency of the .so build
162                                 lk_deps += custom_target(name + '.exp_chk',
163                                         command: [check_experimental_syms,
164                                                 version_map, '@INPUT@'],
165                                         capture: true,
166                                         input: static_lib,
167                                         output: name + '.exp_chk')
168                         endif
169
170                         shared_lib = shared_library(libname,
171                                         sources,
172                                         objects: objs,
173                                         c_args: cflags,
174                                         dependencies: shared_deps,
175                                         include_directories: includes,
176                                         link_args: lk_args,
177                                         link_depends: lk_deps,
178                                         version: lib_version,
179                                         soversion: so_version,
180                                         install: true)
181                         shared_dep = declare_dependency(link_with: shared_lib,
182                                         include_directories: includes,
183                                         dependencies: shared_deps)
184
185                         dpdk_libraries = [shared_lib] + dpdk_libraries
186                         dpdk_static_libraries = [static_lib] + dpdk_static_libraries
187                 endif # sources.length() > 0
188
189                 set_variable('shared_rte_' + name, shared_dep)
190                 set_variable('static_rte_' + name, static_dep)
191                 message('lib/@0@: Defining dependency "@1@"'.format(
192                                 dir_name, name))
193         endif # if build
194 endforeach