Skip to content

Build options

Jussi Pakkanen edited this page Jun 5, 2016 · 10 revisions

Most non-trivial builds require user-settable options. As an example a program may have two different data backends that are selectable at build time. Meson provides for this by having a option definition file. Its name is meson_options.txt and it is placed at the root of your source tree.

Here is a simple option file.

option('someoption', type : 'string', value : 'optval', description : 'An option')
option('other_one', type : 'boolean', value : false)
option('combo_opt', type : 'combo', choices : ['one', 'two', 'three'], value : 'three')

This demonstrates the three basic option types and their usage. String option is just a free form string and a boolean option is, unsurprisingly, true or false. The combo option can have any value from the strings listed in argument choices. If value is not set, it defaults to empty string for strings, true for booleans or the first element in a combo. You can specify description, which is a free form piece of text describing the option. It defaults to option name.

These options are accessed in Meson code with the get_option function.

optval = get_option('opt_name')

It should be noted that you can not set option values in your Meson scripts. They have to be set externally. The easiest way to change them is to use the Meson GUI or command line tools.

This function also allows you to query the value of Meson's built-in project options. For example, to get the installation prefix you would issue the following command:

prefix = get_option('prefix')

Back to index.

Meson documentation has moved

All documentation is now on the main web site.

This page should be at this address.

Clone this wiki locally