Menu

Adding flags

Jussi Pakkanen

The Meson build system has moved

The new home of Meson's documentation is here. The information below is preserved only for posterity. It should be considered out of date.


Adding compiler flags

Often you need to specify extra compiler flags. Meson provides two different ways to achieve this: global flags and per-target flags.

Global flags

Global compiler flags are set with the following command.

add_global_arguments('-std=c99', language : 'c')

This sets the flag that controls the C language standard used.

Global arguments have certain limitations. They all have to be defined before any build targets are specified. This ensures that the global flags are the same for every single source file built in the entire project. For this reason you should set only the most essential flags with this setting.

You should not set debug or optimization flags with this function. Instead they should be specified with the build type feature.

Per target flags

Per target flags are just as simple to define.

executable('prog', 'prog.cc', cpp_args : '-DCPPTHING')

Here we create a C++ executable with an extra preprocessor definition.


Back to index.


Related

Wiki: Manual

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.