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