03/30/2019 09:36:23 PM (3 years ago)
Ken Moffat <ken@…>
10.0, 10.1, 11.0, 11.1, 9.0, 9.1, lazarus, qt5new, trunk, upgradedb, xry111/intltool, xry111/test-20220226

Start to document some of the differences in cmake and ninja.

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@21415 af4574ff-66df-0310-9fd7-8a98e5e911e0

1 edited


  • introduction/important/building-notes.xml

    r5a8f4f1 rab8c10c8  
    454454  </sect2>
     456  <sect2 id="buildsystems">
     457    <title>Working with different build systems</title>
     459    <para>
     460      There are now three different build systems in common use for
     461      converting C or C++ source code into compiled programs or
     462      libraries, and their details (particularly, finding out about available
     463      options and their default values) differ. It may be easiest to understand
     464      the issues caused by some choices (typically, slow execution, or
     465      unexpected use of, or omission of, optimizatons) by starting with the item
     466      which drew attention to this, the CFLAGS and CXXFLAGS.
     467    </para>
     469    <para>
     470      Most LFS and BLFS builders are probably aware of the basics of CFLAGS
     471      and CXXFLAGS for altering how a program is compiled. Typically, some
     472      form of optimization is used for a released program (-O2 or -O3),
     473      sometimes with the creation of debug symbols (-g) when using -O2.
     474    </para>
     476    <para>
     477      If there are contradictory flags (e.g. multiple different -O values),
     478      the <emphasis>last</emphasis> value will be used. Sometimes this means
     479      that flags specifiedi in environment variables will be picked up before
     480      values hardcoded in the Makefile, and therefore ignored.  For example,
     481      where a user specifies '-O2' and that is followed by '-O3' the build will
     482      use '-O3'.
     483    </para>
     485    <para>
     486      There are various other things which can be passed in CFLAGS or
     487      CXXFLAGS, such as forcing compilation for a specific microarchitecture
     488      (e.g. -march=amdfam10, -march=native) or specifying a specific standard
     489      for C or C++ (-std=c++17 for example). But one thing which has now come
     490      to light is that programmers might include debug assertions in their
     491      code, expecting them to be disabled in releases by using -DNDEBUG.
     492      Specifically, if <xref linkend="mesa"/> is built with these assertions
     493      enabled, some activities such as loading levels of games can take
     494      extremely long times, even on high-class video cards.
     495    </para>
     497    <bridgehead renderas="sect3">Autotools with Make</bridgehead>
     499      <para>
     500       This combination is often described as 'CMMI' (configure, make, make
     501       install) and is used here to also cover the few packages which have a
     502       configure script that is not generated by autotools.
     503      </para>
     505      <para>
     506        Sometimes, running <command>./configure --help</command> will produce
     507        useful options about switches which might be used.  At other times,
     508        after looking at the output from a run of configure you may need to look
     509        at the details of the script to find out what it was actually searching
     510        for.
     511      </para>
     513      <para>
     514       Many configure scripts will pick up any CFLAGS or CXXFLAGS from the
     515       environment, but CMMI packages vary about how these will be mixed with
     516       any flags which would otherwise be used (<emphasis>variously</emphasis>:
     517       ignored, used to replace the programmer's suggestion, used before the
     518       programmer's suggestion, used after the programmer's suggestion).
     519      </para>
     521      <para>
     522       In most CMMI packages, running 'make' will list each command and run
     523       it, interspersed with any warnings. But some packages try to be 'silent'
     524       and only show which file they are compiling or linking instead of showing
     525       the command line. If you need to inspect the command, either because of
     526       an error, or just to see what options and flags are being used, adding
     527       'V=1' to the make invocation may help.
     528     </para>
     530    <bridgehead renderas="sect3">CMake</bridgehead>
     532      <para>
     533        CMake works in a very different way, and it has two backends which can
     534        be used on BLFS: 'make' and 'ninja'. The default backend is make, but
     535        ninja can be faster on large packages with multiple processors. To
     536        use ninja, specify '-G Ninja' in the cmake command.
     537      </para>
     539      <para>
     540        The hardest part of using CMake is knowing what options you might wish
     541        to specify. The only way to get a list of what the package knows about
     542        is to run <command>cmake -LAH</command> and look at the output for that
     543        default configuration.
     544      </para>
     546      <para>
     547        Perhaps the most-important thing about CMake is that it has a variety
     548        of CMAKE_BUILD_TYPE values, and these affect the flags. The default
     549        is that this is not set and no flags are generated. Any CFLAGS or
     550        CXXFLAGS in the environment will be used. If  the programmer has coded
     551        any debug assertions, those will be enabled unless -DNDEBUG is used.
     552        The following CMAKE_BUILD_TYPE values will generate the flags shown,
     553        and these will come <emphasis>after</emphasis> any flags in the
     554        environment and therefore take precedence.
     555      </para>
     557      <itemizedlist>
     558        <listitem>
     559          <para>Debug : '-g'</para>
     560        </listitem>
     561        <listitem>
     562          <para>Release : '-O3 -DNDEBUG'</para>
     563        </listitem>
     564        <listitem>
     565           <para>RelWithDebInfo : '-O2 -g -DNDEBUG'</para>
     566        </listitem>
     567        <listitem>
     568           <para>MinSizeRel : '-Os -DNDEBUG'</para>
     569        </listitem>
     570      </itemizedlist>
     572      <para>
     573        CMake tries to produce quiet builds. To see the details of the commands
     574        which are being run, use 'make VERBOSE=1' or 'ninja -v'.
     575      </para>
     577    <bridgehead renderas="sect3">Meson</bridgehead>
     579      <para>
     580        Meson has some similarities to CMake, but many differences. To get
     581        details of the definesthat you may wish to change is slightly involved
     582        using meson-0.49.2:
     583      </para>
     585<screen><userinput>meson ..
     586meson configure | less</userinput></screen>
     588      <para>
     589        After identifying what to set, meson then needs to be reconfigured:
     590      </para>
     592<screen><userinput>meson --prefix=/usr -Dsome_option=true -Dother_option=false --reconfigure</userinput></screen>
     594      <para>
     595        Alternatively, you could remove the build directory where you did this,
     596        recreate it, and then run meson with the desired switches.
     597      </para>
     599      <para>
     600        Meson provides the following buildtype values, and the flags they enable
     601        come <emphasis>after</emphasis> any flags supplied in the environment and
     602        therefore take precedence.
     603      </para>
     605      <itemizedlist>
     606        <listitem>
     607          <para>plain : no added flags. This is for distributors to supply their
     608          own CLFAGS, CXXFLAGS and LDFLAGS. There is no obvious reason to use
     609          this in BLFS.</para>
     610        </listitem>
     611        <listitem>
     612          <para>debug : '-g'</para>
     613        </listitem>
     614        <listitem>
     615           <para>debugoptimized : '-O2 -g' - this is the default if nothing is
     616           specified, it leaves assertions enabled.</para>
     617        </listitem>
     618        <listitem>
     619           <para>release : '-O3 -DNDEBUG'</para>
     620        </listitem>
     621      </itemizedlist>
     623      <para>
     624        Although the release buildtype is described as enabling -DNDEBUG, and all
     625        CMake Release builds pass that, it has so far only been observed (in
     626        verbose builds) for <xref linkend="mesa"/>. That suggests that it might
     627        only be used when there are debug assertions present.
     628      </para>
     630      <para>
     631        The -DNDEBUG flag can also be provided by passing
     632        <command>-Db_ndebug=true</command>.
     633      </para>
     635      <para>
     636        To see the details of the commands which are being run in a package using
     637        meson, again use 'ninja -v'.
     638      </para>
     640  </sect2>
Note: See TracChangeset for help on using the changeset viewer.