meson-build

How can I get all options from meson_options.txt


Is there any facility (cli, online, etc) where from one meson_options.txt file I can get all the options filled in with the defaults?

e.g.

$ meson_get_all_options
CMD -Doption=true -Doption2=42

Solution

    1. Run meson setup to create default build configuration
    2. Run meson introspect --buildoptions to dump all options in JSON format
    3. Parse JSON output
    4. Filter out records with section=user

    Example code in Lua:

    -- some JSON decoder required
    local json = require"json"
    
    local projdir = "/path/to/project"
    local tempdir = "/tmp/build"
    
    assert(os.execute(string.format("meson setup %s %s >/dev/null", tempdir, projdir)))
    
    local handle = io.popen(string.format("meson introspect %s --buildoptions", tempdir))
    local data = json.decode(handle:read("*all"))
    handle:close()
    
    for i, v in ipairs(data) do
        if v.section == "user" then
            io.write(string.format("-D%s=%s ", v.name, v.value))
        end
    end
    
    os.execute(string.format("rm -r %s", tempdir))