Meson working with data/assets and portable/relative paths

柔情痞子 提交于 2020-01-03 03:32:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!