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