问题
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
Here are the meson.buid
files:
# meson.build
project('mygame', 'cpp')
subdir('src')
pkgdatadir = join_paths(get_option('datadir'), 'mygame')
install_subdir('img', install_dir : join_paths([pkgdatadir, 'img']))
And the second file:
# src/meson.build
executable('mygame', 'main.cpp', install : true)
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 ?
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.
I thought of adding a define DATA_PREFIX
set at compile time, or using an environment variable.
See http://mesonbuild.com/Installing.html and http://mesonbuild.com/Reference-manual.html#install_data.
Thank you.
回答1:
I thought of adding a define DATA_PREFIX set at compile time
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
)
Then just include config.h
in your source.
来源:https://stackoverflow.com/questions/46473646/meson-working-with-data-assets-and-portable-relative-paths