Meson

Meson uses a two-stage workflow: first Meson checks the environment (e.g., compiler support and dependency discovery) and generates a low level build file (most likely Ninja). Then, you must call Ninja to actually compile the code.

For QNX, you need to tell Meson during the first stage that you're not using the system C compiler, so Meson can generate second stage build file with QNX's build toolchain instead. This is done by providing Meson with a cross file (cross compiling configuration file).

Meson can't fill the variables from environment variables, so you must fill them in manually. A sample cross file looks like this:

[constants]
# Fill the following
# For QNX8, it's either `x86_64` or `aarch64` right now
target_arch = '$QNX_ARCH'
# For QNX8, it's either `x86_64-pc-nto-qnx8.0.0` or `aarch64-unknown-nto-qnx8.0.0` right now
target = '$QNX_TARGET_NAME'
# SDP host directory, set by `qnxsdp-env.sh`. Check via `echo $QNX_HOST`
qnx_host_path = '$QNX_HOST'
# SDP target directory, set by `qnxsdp-env.sh`. Check via `echo $QNX_TARGET`
qnx_target_path = '$QNX_TARGET'
# Fill the above

[host_machine]
system = 'qnx'
cpu_family = target_arch
cpu = target_arch
endian = 'little'

[built-in options]
c_link_args = ['-lm', '-lsocket', '-lregex']

[properties]
growing_stack = false
# pkg-config settings
sys_root = qnx_target_path
pkg_config_libdir = qnx_target_path + '/system/lib/pkgconfig'

[binaries]
c = [qnx_host_path + '/usr/bin/' + target + '-gcc']
cpp = [qnx_host_path + '/usr/bin/' + target + '-g++']
ar = qnx_host_path + '/usr/bin/' + target + '-ar'
ld = qnx_host_path + '/usr/bin/' + target + '-ld'
strip = qnx_host_path + '/usr/bin/' + target + '-strip'
objcopy = qnx_host_path + '/usr/bin/' + target + '-objcopy'
# Using the host pkg-config
pkg-config = 'pkg-config'
#windres = ''

The above example defines what architecture and target name your QNX target has, and can then assemble the path of C/C++ compiler, ld, etc. Note that for now, the QNX Software Center does not correctly provide pkg-config files.

Before invoking Meson, also check the optional features provided by the project. A list of features can be found at meson_options.txt. For the most part, you can disable things like Python and Lua binding, and tests unless you need them.

Then, you're ready to build!

# First stage: generate second stage build file for Ninja with Meson
# Meson will put everything in a folder to keep it clean. You can call it `build`.
# Optional: You can enable or disable features defined by the project using -D.
#           A list of features defined by the project is usually location in `meson_options.txt` at the same directory alongside `meson.build`.
#           Here, you can disable a feature called "feature"

meson setup build --cross-file=qnx.ini -Dprefix=/system -Dfeature=disabled

# Second stage: if first stage passes, let Meson to call Ninja to build it.
# You can also use ninja directly, but you can let Meson handle it for you.

meson compile -C build

# Finally, deploy it to somewhere. For cross-compiling, you can set DESTDIR to a temporary folder so it can be transferred into an actual QNX system later.

DESTDIR="$your_dest_dir" meson install -C build
Page updated: