meson & ninja 编译构建指导
升级dpdk-stable-20.11.1版本发现,原来默认make方式构建已经没有了;变成了meson & ninja组合,试了一下,构建速度提升了不少;
meson build && ninja -C build
// sudo ninja -C build install
赶紧去学习下吧, 后面试着把那些又臭又长的Makefile或者CMakeLists.txt替换掉吧,简单看了下manual,感觉和cmake差不多,为啥快也没了解。先学习下傍身!
demo例子就两行,很简洁:
project('tutorial', 'c') # C语言工程
executable('demo', 'main.c') # target为demo 依赖 main.c
官网手册在这里:
https://mesonbuild.com/Reference-manual.html
大概扫了下,感觉比较详细;看了下 DPDK 的 meson.build 比看makefile舒坦多了,整个才100+ line; 即使你不完全明白是啥, 根据cmake也猜出来差不多,关键是个人体验真的变快了。下面把 DPDK 的构建系统说下吧。DPDK下载的是LTS版本(DPDK 20.11.1 (LTS) http://core.dpdk.org/download/ )
meson_options.txt (like default_options in project(), they only have effect when Meson is run for the first time, and command line arguments override any default options in build files)
get_compiler(language)
: returns an object describing a compiler, takes one positional argument which is the language to use
例如获取C compiler:cc = meson.get_compiler('c')
This object is returned by configuration_data() and encapsulates configuration values to be used for generating configuration files。
eg:dpdk_conf = configuration_data() # 用于生成配置文件,支撑一些method,参考描述: configuration data object
host_machine
objec
eg: 判断编译机体系结构: if host_machine.cpu_family().startswith('x86')
[host_machine] system = 'windows' cpu_family = 'x86' cpu = 'i686' endian = 'little'
大概长这样子,主要是为了交叉编译环境使用。
include_directories (since 0.38.0): specifies extra directories for header searches. # 这个和cmake 一样了
eg:
global_inc = include_directories('.', 'config',
'lib/librte_eal/include',
'lib/librte_eal/@0@/include'.format(host_machine.system()), # 注意这里,@0@ .format(XX)还没看哪里说明的语法,先记着杂用就行了
'lib/librte_eal/@0@/include'.format(arch_subdir),
)
subdir() # 描述同camke 构建子目录
void subdir(dir_name, ...)
Enters the specified subdirectory and executes the meson.build file in it.
EG:
subdir('buildtools')
subdir('config')
# build libs and drivers
subdir('buildtools/pmdinfogen') # 注意上面一句 subdir('buildtools') 说明subdir只构建指定的子目录,不会去子目录的子目录。
subdir('lib')
subdir('drivers')
install_subdir() # 指定subdir的 install 路径
void install_subdir(subdir_name,
install_dir : ...,
exclude_files : ...,
exclude_directories : ...,
strip_directory : ...)
Installs the entire given subdirectory and its contents from the source tree to the location specified by the keyword argument install_dir.
eg: 指定路径,包含的文件 和 exclude文件
subdir('examples')
install_subdir('examples',
install_dir: get_option('datadir') + '/dpdk',
exclude_files: 'meson.build')
get_option() #这个东西获取工程可配置参数
value get_option(option_name)
Obtains the value of the project build option specified in the positional argument.
Note that the value returned for built-in options that end in dir such as bindir and libdir is always a path relative to (and inside) the prefix.
条件编译开关形式
if get_option('enable_kmods')
subdir('kernel')
endif
# write the build config
build_cfg = 'rte_build_config.h'
configure_file(output: build_cfg,
configuration: dpdk_conf,
install_dir: join_paths(get_option('includedir'),
get_option('include_subdir_arch')))
支持 foreach
foreach lib:enabled_libs
output_message += lib + ', '
output_count += 1
if output_count == 8
output_message += '\n\t'
output_count = 0
endif
endforeach
message(output_message + '\n') 支持message打印
get_variable() # 动态获取变量值
value get_variable(variable_name, fallback)
This function can be used to dynamically obtain a variable. res = get_variable(varname, fallback) takes the value of varname (which must be a string) and stores the variable of that name into res. If the variable does not exist, the variable fallback is stored to resinstead. If a fallback is not specified, then attempting to read a non-existing variable will cause a fatal error.
meson.build 中出现的相关函数就看完了,很好懂,和cmake语法很像, 后面再看下,编译具体lib怎么处理库和文件 还有编译参数的;
随便看一个 drivers 下面的 meson.build;扫了一眼 200行,可接受;
static_library()
buildtarget static_library(library_name, list_of_sources, ...)
Builds a static library with the given sources. Positional and keyword arguments are otherwise the same as for library, but it has one argument the others don't have:
后面在梳理吧 ~