bc8eb1d2181715d79263157a7ad5e9b63e1b5923
[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', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
15         'cmdline',
16         'metrics', # bitrate/latency stats depends on this
17         'hash',    # efd depends on this
18         'timer',   # eventdev depends on this
19         'acl', 'bbdev', 'bitratestats', 'cfgfile',
20         'compressdev', 'cryptodev',
21         'distributor', 'efd', 'eventdev',
22         'gro', 'gso', 'ip_frag', 'jobstats',
23         'kni', 'latencystats', 'lpm', 'member',
24         'power', 'pdump', 'rawdev',
25         'rcu', 'rib', 'reorder', 'sched', 'security', 'stack', 'vhost',
26         # ipsec lib depends on net, crypto and security
27         'ipsec',
28         #fib lib depends on rib
29         'fib',
30         # add pkt framework libs which use other libs from above
31         'port', 'table', 'pipeline',
32         # flow_classify lib depends on pkt framework table lib
33         'flow_classify', 'bpf', 'telemetry']
34
35 if is_windows
36         libraries = ['kvargs','eal'] # only supported libraries for windows
37 endif
38
39 default_cflags = machine_args
40 if cc.has_argument('-Wno-format-truncation')
41         default_cflags += '-Wno-format-truncation'
42 endif
43
44 enabled_libs = [] # used to print summary at the end
45
46 foreach l:libraries
47         build = true
48         reason = '<unknown reason>' # set if build == false to explain why
49         name = l
50         version = 1
51         allow_experimental_apis = false
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 allow_experimental_apis
103                                 cflags += '-DALLOW_EXPERIMENTAL_API'
104                         endif
105                         if use_function_versioning
106                                 cflags += '-DRTE_USE_FUNCTION_VERSIONING'
107                         endif
108
109                         if get_option('per_library_versions')
110                                 lib_version = '@0@.1'.format(version)
111                                 so_version = '@0@'.format(version)
112                         else
113                                 lib_version = major_version
114                                 so_version = major_version
115                         endif
116
117                         # first build static lib
118                         static_lib = static_library(libname,
119                                         sources,
120                                         objects: objs,
121                                         c_args: cflags,
122                                         dependencies: static_deps,
123                                         include_directories: includes,
124                                         install: true)
125                         static_dep = declare_dependency(link_with: static_lib,
126                                         include_directories: includes,
127                                         dependencies: static_deps)
128
129                         if not use_function_versioning
130                                 # use pre-build objects to build shared lib
131                                 sources = []
132                                 objs += static_lib.extract_all_objects(recursive: false)
133                         else
134                                 # for compat we need to rebuild with
135                                 # RTE_BUILD_SHARED_LIB defined
136                                 cflags += '-DRTE_BUILD_SHARED_LIB'
137                         endif
138                         version_map = '@0@/@1@/rte_@2@_version.map'.format(
139                                         meson.current_source_dir(), dir_name, name)
140                         implib = dir_name + '.dll.a'
141
142                         def_file = custom_target(name + '_def',
143                                 command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'],
144                                 input: version_map,
145                                 output: 'rte_@0@_exports.def'.format(name))
146                         lk_deps = [version_map, def_file]
147                         if is_windows
148                                 lk_args = ['-Wl,/def:' + def_file.full_path(),
149                                         '-Wl,/implib:lib\\' + implib]
150                         else
151                                 lk_args = ['-Wl,--version-script=' + version_map]
152                                 # on unix systems check the output of the
153                                 # experimental syms script, using it as a
154                                 # dependency of the .so build
155                                 lk_deps += custom_target(name + '.exp_chk',
156                                         command: [check_experimental_syms,
157                                                 version_map, '@INPUT@'],
158                                         capture: true,
159                                         input: static_lib,
160                                         output: name + '.exp_chk')
161                         endif
162
163                         shared_lib = shared_library(libname,
164                                         sources,
165                                         objects: objs,
166                                         c_args: cflags,
167                                         dependencies: shared_deps,
168                                         include_directories: includes,
169                                         link_args: lk_args,
170                                         link_depends: lk_deps,
171                                         version: lib_version,
172                                         soversion: so_version,
173                                         install: true)
174                         shared_dep = declare_dependency(link_with: shared_lib,
175                                         include_directories: includes,
176                                         dependencies: shared_deps)
177
178                         dpdk_libraries = [shared_lib] + dpdk_libraries
179                         dpdk_static_libraries = [static_lib] + dpdk_static_libraries
180                 endif # sources.length() > 0
181
182                 set_variable('shared_rte_' + name, shared_dep)
183                 set_variable('static_rte_' + name, static_dep)
184                 message('lib/@0@: Defining dependency "@1@"'.format(
185                                 dir_name, name))
186         endif # if build
187 endforeach