[build2] how to compile different executables with different flags

Alberto Sartori alberto.sartori at sissa.it
Thu Feb 27 08:26:02 UTC 2020


Thanks, Boris! it worked like a charm.

On Tue, Oct 29, 2019 at 11:17 AM Boris Kolpackov <boris at codesynthesis.com>
wrote:

> Alberto Sartori <alberto.sartori at sissa.it> writes:
>
> > I would like to use build2 to build some executables for a course of
> > C++. I have several source files (each one with a main) and I would like
> > to compile a couple of them with a couple of more flags with respect to
> > the others. How can I do that?
> >
> > $ cat build/root.build
> > cxx.std = 14
> >
> > using cxx
> >
> > cxx{*}: extension = cc
> >
> > cxx.coptions=-O3
> > cxx.poptions=-Wall -Wextra
> >
> > $ cat buildfile
> >
> > src = 01_enum.cc      \
> > 02_scoped_enum.cc     \
> > 03_namespace.cc               \
> > 04_why_scoped.cc      \
> > 05_struct_class.cc    \
> > 06_constructor_destructor.cc  \
> > 07_template_class.cc
> >
> > for s : $src
> > {
> >   n = $name($s)
> >   ./: exe{$n".x"} : cxx{$n}
> > }
>
> You can use target-specific variables for that, for example:
>
> obj{01_enum}: cxx.coptions += -Wno-uninitialized
>
> You can also list several targets at once:
>
> obj{01_enum 02_scoped_enum}: cxx.coptions += -Wno-uninitialized
>
> If you want link options instead of compile, then you would use
> the executable target:
>
> exe{01_enum.x}:
> {
>   cxx.loptions += -static
>   cxx.libs += -lpthread
> }
>
> BTW, that .x extension for the executable target makes your project
> non-portable (since you've specified your own extension, build2 will
> do as it's told and use this extension even on Windows).
>


-- 
Alberto Sartori, Ph.D.

Master in High Performance Computing,
www.mhpc.it

SISSA, International School for Advanced Studies
via Bonomea 265, 34136 Trieste, Italy
office: 723, phone: +39 040 3787 851
email: alberto.sartori at sissa.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.build2.org/archives/users/attachments/20200227/b3a07e38/attachment.html>


More information about the users mailing list