xref: /dpdk/lib/meson.build (revision 44e830c4)
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright(c) 2017 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 = [ 'compat', # just a header, used for versioning
12	'eal', 'ring', 'mempool', 'mbuf', 'net', 'kvargs', 'ethdev', 'pci', # core
13	'metrics', # bitrate/latency stats depends on this
14	'hash',    # efd depends on this
15	'timer',   # eventdev depends on this
16	'acl', 'bbdev', 'bitratestats', 'cfgfile',
17	'cmdline', 'compressdev', 'cryptodev',
18	'distributor', 'efd', 'eventdev',
19	'gro', 'gso', 'ip_frag', 'jobstats',
20	'kni', 'latencystats', 'lpm', 'member',
21	'meter', 'power', 'pdump', 'rawdev',
22	'reorder', 'sched', 'security', 'vhost',
23	# add pkt framework libs which use other libs from above
24	'port', 'table', 'pipeline',
25	# flow_classify lib depends on pkt framework table lib
26	'flow_classify', 'bpf']
27
28foreach l:libraries
29	build = true
30	name = l
31	version = 1
32	allow_experimental_apis = false
33	sources = []
34	headers = []
35	includes = []
36	cflags = machine_args
37	if cc.has_argument('-Wno-format-truncation')
38	    cflags += '-Wno-format-truncation'
39	endif
40
41	objs = [] # other object files to link against, used e.g. for
42	          # instruction-set optimized versions of code
43
44	# use "deps" for internal DPDK dependencies, and "ext_deps" for
45	# external package/library requirements
46	ext_deps = []
47	deps = ['eal']   # eal is standard dependency except for itself
48	if l == 'eal'
49		deps = []
50	endif
51
52	dir_name = 'librte_' + l
53	subdir(dir_name)
54
55	if build
56		dpdk_conf.set('RTE_LIBRTE_' + name.to_upper(), 1)
57		install_headers(headers)
58
59		libname = 'rte_' + name
60		includes += include_directories(dir_name)
61
62		if sources.length() == 0
63			# if no C files, just set a dependency on header path
64			shared_dep = declare_dependency(include_directories: includes)
65			static_dep = shared_dep
66		else
67			shared_deps = ext_deps
68			static_deps = ext_deps
69			foreach d:deps
70				shared_deps += [get_variable('shared_rte_' + d)]
71				static_deps += [get_variable('static_rte_' + d)]
72			endforeach
73
74			if allow_experimental_apis
75				cflags += '-DALLOW_EXPERIMENTAL_API'
76			endif
77
78			if get_option('per_library_versions')
79				lib_version = '@[email protected]'.format(version)
80				so_version = '@0@'.format(version)
81			else
82				prj_ver = meson.project_version().split('.')
83				lib_version = '@0@.@1@'.format(
84						prj_ver.get(0), prj_ver.get(1))
85				so_version = lib_version
86			endif
87
88			# first build static lib
89			static_lib = static_library(libname,
90					sources,
91					objects: objs,
92					c_args: cflags,
93					dependencies: static_deps,
94					include_directories: includes,
95					install: true)
96			static_dep = declare_dependency(link_with: static_lib,
97					include_directories: includes,
98					dependencies: static_deps)
99
100			# then use pre-build objects to build shared lib
101			sources = []
102			objs += static_lib.extract_all_objects(recursive: false)
103			version_map = '@0@/@1@/rte_@2@_version.map'.format(
104					meson.current_source_dir(), dir_name, name)
105			shared_lib = shared_library(libname,
106					sources,
107					objects: objs,
108					c_args: cflags,
109					dependencies: shared_deps,
110					include_directories: includes,
111					link_args: '-Wl,--version-script=' + version_map,
112					link_depends: version_map,
113					version: lib_version,
114					soversion: so_version,
115					install: true)
116			shared_dep = declare_dependency(link_with: shared_lib,
117					include_directories: includes,
118					dependencies: shared_deps)
119
120			dpdk_libraries = [shared_lib] + dpdk_libraries
121		endif # sources.length() > 0
122
123		set_variable('shared_' + libname, shared_dep)
124		set_variable('static_' + libname, static_dep)
125	endif # if build
126endforeach
127