[build2] how to compile different executables with different flags
Boris Kolpackov
boris at codesynthesis.com
Tue Oct 29 10:17:31 UTC 2019
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).
More information about the users
mailing list