介子处理数据/资产和可移植/相对路径 [英] Meson working with data/assets and portable/relative paths
问题描述
我想使用 Meson 来用C ++编写一个小游戏.假设这些是我的文件:
I'd like to use Meson to build a little game in C++. Let's say that theses are my file:
.
├── img
│ └── img.png
├── meson.buid
└── src
├── main.cpp
└── meson.build
以下是meson.buid
个文件:
# meson.build
project('mygame', 'cpp')
subdir('src')
pkgdatadir = join_paths(get_option('datadir'), 'mygame')
install_subdir('img', install_dir : join_paths([pkgdatadir, 'img']))
第二个文件:
# src/meson.build
executable('mygame', 'main.cpp', install : true)
在我的C ++代码中,我应该使用哪个路径以可移植(相对?)的方式(Windows,OS X,Linux)加载资产文件,前提是我可能已经创建了捆绑文件应用程序或在系统文件层次结构中安装了(deb)软件包?
In my C++ code, what path should I use to load in a portable (relative ?) way (Windows, OS X, Linux) the assets files, given that I may have created a bundled application or installed a (deb) package in the system file hierarchy ?
在构建目录中使用ninja
进行构建时,我也希望文件路径能够工作,而不必安装所有游戏数据.
I would also like the file paths to work when I build with ninja
in the build directory without having to install at all the game data.
我想在编译时添加一个定义DATA_PREFIX
集,或者使用环境变量.
I thought of adding a define DATA_PREFIX
set at compile time, or using an environment variable.
请参见 http://mesonbuild.com/Installing.html 和谢谢.
推荐答案
我想在编译时添加一个定义DATA_PREFIX集
I thought of adding a define DATA_PREFIX set at compile time
那是我推荐的方法.然后,您可以使用configure_file()
输出包含它的标头:
That is the method I would recommend. You can then use configure_file()
to output a header containing it:
conf = configuration_data()
conf.set_quoted('PACKAGE_DATADIR', join_paths(get_option('prefix'), pkgdatadir))
configure_file(
output: 'config.h',
configuration: conf
)
然后在您的源代码中加入config.h
.
Then just include config.h
in your source.
这篇关于介子处理数据/资产和可移植/相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!