<literal>meson setup</literal> command.
<screen>
<userinput>meson setup build</userinput>
</screen>
The setup command takes a <literal>builddir</literal> and a <literal>srcdir</literal>
argument. If no <literal>srcdir</literal> is given, Meson will deduce the
<literal>srcdir</literal> based on the current directory and the location
of <literal>meson.build</literal>. The <literal>builddir</literal> is mandatory.
</para>
<para>
Running <literal>meson setup</literal> loads the build configuration file and sets up the build directory.
Additionally, you can also pass several build options to Meson. Some commonly
used options are mentioned in the subsequent sections. For example:
<screen>
# configure with a different installation prefix
meson setup build --prefix=/home/user/pg-install
# configure to generate a debug build
meson setup build --buildtype=debug
# configure to build with OpenSSL support
meson setup build -Dssl=openssl
</screen>
</para>
<para>
Setting up the build directory is a one-time step. To reconfigure before a
new build, you can simply use the <literal>meson configure</literal> command
<screen>
meson configure -Dcassert=true
</screen>
<command>meson configure</command>'s commonly used command-line options
are explained in <xref linkend="meson-options"/>.
</para>
</step>
<step id="meson-build">
<title>Build</title>
<para>
By default, <productname>Meson</productname> uses the <ulink
url="https://ninja-build.org/">Ninja</ulink> build tool. To build
<productname>PostgreSQL</productname> from source using Meson, you can
simply use the <literal>ninja</literal> command in the build directory.
<screen>
ninja
</screen>
Ninja will automatically detect the number of CPUs in your computer and
parallelize itself accordingly. You can override the number of parallel
processes used with the command line argument <literal>-j</literal>.
</para>
<para>
It should be noted that after the initial configure step,
<command>ninja</command> is the only command you ever need to type to
compile. No matter how you alter your source tree (short of moving it to a
completely new location), Meson will detect the changes and regenerate
itself accordingly. This is especially handy if you have multiple build
directories. Often one of them is used for development (the "debug" build)
and others only every now and then (such as a "static analysis" build).
Any configuration can be built just by cd'ing to the corresponding
directory and running Ninja.
</para>
<para>
If you'd like to build with a backend other than ninja, you can use
configure with the <option>--backend</option> option to select the one you
want to use and then build using <literal>meson compile</literal>. To
learn more about these backends and other arguments you can provide to
ninja, you can refer to the <ulink
url="https://mesonbuild.com/Running-Meson.html#building-from-the-source">
Meson documentation</ulink>.
</para>
</step>
<step>
<title>Regression Tests</title>
<indexterm>
<primary>regression test</primary>
</indexterm>
<para>
If you want to test the newly built server before you install it,
you can run the regression tests at this point. The regression
tests are a test suite to verify that <productname>PostgreSQL</productname>
runs on your machine in the way the developers expected it
to. Type:
<screen>
<userinput>meson test</userinput>
</screen>
(This won't work as root; do it as an unprivileged user.)
See <xref linkend="regress"/> for
detailed information about interpreting the test results. You can
repeat this test at any later time by issuing the same command.
</para>
<para>
To run pg_regress and pg_isolation_regress tests against a running
postgres instance, specify <userinput>--setup running</userinput> as an
argument