简体   繁体   中英

Quoting for preprocessor string on meson

This is my meson build script:

project('conce', 'cpp', version: '1.0.0.0', default_options: 'cpp_std=c++11')

progname = meson.project_name()
progver  = meson.project_version()

progdefs = ['-DUSE_MESON', '-DID=69', '-DVER=\"' + progver + '\"']

bin = executable(progname, 'main.cpp', cpp_args: progdefs)

run_target('run', command: bin)

I would like to define VER with project version. This produce error on compiling main.cpp : error: stray '\' in program . So my question here is, how can I quote my string in meson?

The simple answer is, you don't:-)

Meson automatically escapes any strings you pass on to its APIs if needed, so you don't have to care about escaping. It makes sense that Meson does this for you, as there might be multiple levels that need to be escaped, for example the backend that will actually build your targets, as well as any strings passed to a shell.

In other words, you can solve it by doing this:

progdefs = ['-DUSE_MESON', '-DID=69', '-DVER="' + progver + '"']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM