change the default CFLAGS/CXXFLAGS

2,085 views
Skip to first unread message

Noam Meltzer

unread,
Jul 28, 2015, 7:35:14 AM7/28/15
to The Meson Build System
Hi,

By default meson adds several compiler flags, for example:

class GnuCPPCompiler(CPPCompiler):
...
old_warn = ['-Wall', '-pedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
    ...
    

Is it possible to disable these defaults? (i.e., start with no flags at all?)

My use case, is that I try to port a legacy project into meson build and this project wiil *not* compile that way.
Specifically:
1. in gcc-4.4.6 '-pedantic' is not a warning flag but rather an error flag.
2. One of the above warning flags actually issues warnings. So now I can't use '-Werror' which the project used to.

Best regards,
Noam Meltzer

Igor Gnatenko

unread,
Jul 28, 2015, 7:37:16 AM7/28/15
to Noam Meltzer, The Meson Build System
You can use $ meson --buildtype=plain. Then you will avoid all meson pre-defined flags.

--
You received this message because you are subscribed to the Google Groups "The Meson Build System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mesonbuild+...@googlegroups.com.
To post to this group, send email to meson...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mesonbuild/0f18e781-a430-47e5-9bad-c272bc03e295%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

-Igor Gnatenko

Jussi Pakkanen

unread,
Jul 28, 2015, 5:29:09 PM7/28/15
to Noam Meltzer, The Meson Build System
On Tue, Jul 28, 2015 at 2:35 PM, Noam Meltzer <tsn...@gmail.com> wrote:
By default meson adds several compiler flags, for example:

class GnuCPPCompiler(CPPCompiler):
...
old_warn = ['-Wall', '-pedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
Is it possible to disable these defaults? (i.e., start with no flags at all?)

Much like with pkg-config it is highly recommended to use pedantic and fix any issues raised, it is among the easiest ways to improve your code quality. Now obviously there are several cases where you can't do that. In those cases you can do the following.

Built type flags are put at the beginning of the command line. You can override them by adding either per-target flags or global flags. So for example you can do this:

add_global_arguments('-Wno-pedantic', language : 'cpp')

This will override the build type default flags. If it does not it's a bug and we need to fix it. I'm not sure if gcc 4.6 has -no-pedantic but at least you can disable the individual problematic flags with -Wno-some-test-flags.

You can also use --buildtype=plain as Igor Gnatenko mentioned but note that you also lose debug flags. So you need to do something like this:

CPPFLAGS=-g meson src build --buildtype=plain

Noam Meltzer

unread,
Aug 2, 2015, 5:09:09 AM8/2/15
to Jussi Pakkanen, The Meson Build System
On Wed, Jul 29, 2015 at 12:29 AM Jussi Pakkanen <jpak...@gmail.com> wrote:
On Tue, Jul 28, 2015 at 2:35 PM, Noam Meltzer <tsn...@gmail.com> wrote:
By default meson adds several compiler flags, for example:

class GnuCPPCompiler(CPPCompiler):
...
old_warn = ['-Wall', '-pedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
Is it possible to disable these defaults? (i.e., start with no flags at all?)

Much like with pkg-config it is highly recommended to use pedantic and fix any issues raised, it is among the easiest ways to improve your code quality. Now obviously there are several cases where you can't do that. In those cases you can do the following.
Unfortunately, this is one of these cases. 

Built type flags are put at the beginning of the command line. You can override them by adding either per-target flags or global flags. So for example you can do this:

add_global_arguments('-Wno-pedantic', language : 'cpp')

This will override the build type default flags. If it does not it's a bug and we need to fix it. I'm not sure if gcc 4.6 has -no-pedantic but at least you can disable the individual problematic flags with -Wno-some-test-flags.
There's no "-no-pedantic" for gcc 4.4.6. I couldn't find the  

You can also use --buildtype=plain as Igor Gnatenko mentioned but note that you also lose debug flags. So you need to do something like this:

CPPFLAGS=-g meson src build --buildtype=plain

Thanks. "--buildtype=plain" is what I was looking for. 

Rob

unread,
Aug 6, 2015, 12:11:12 PM8/6/15
to The Meson Build System, tsn...@gmail.com
I tried adding:
add_global_arguments('-Wno-pedantic', language : 'cpp')

And it doesn't override the pedantic setting, the command line now looks like this:
[1/6] clang++ '-Wno-pedantic' '-Wall' '-Wpedantic' '-Winvalid-pch' '-Wnon-virtual-dtor' '' '-g' '-Imeson-test@exe' '-I..' '-I.' '-I3rdParty/dlib-18.16/.' '-I/home/rhd/src/meson-test-app/3rdParty/dlib-18.16/.' '-MMD' '-MQ' 'meson-test@exe/main.cpp.o' '-MF' 'meson-test@exe/main.cpp.o.d' -o 'meson-test@exe/main.cpp.o' -c ../main.cpp

Is this the expected behavior?

Jussi Pakkanen

unread,
Aug 6, 2015, 1:15:34 PM8/6/15
to Rob, The Meson Build System, Noam Meltzer
On Thu, Aug 6, 2015 at 7:11 PM, Rob <rdool...@gmail.com> wrote:

I tried adding:
add_global_arguments('-Wno-pedantic', language : 'cpp')

And it doesn't override the pedantic setting, the command line now looks like this:
[1/6] clang++ '-Wno-pedantic' '-Wall' '-Wpedantic' '-Winvalid-pch' '-Wnon-virtual-dtor' '' '-g' '-Imeson-test@exe' '-I..' '-I.' '-I3rdParty/dlib-18.16/.' '-I/home/rhd/src/meson-test-app/3rdParty/dlib-18.16/.' '-MMD' '-MQ' 'meson-test@exe/main.cpp.o' '-MF' 'meson-test@exe/main.cpp.o.d' -o 'meson-test@exe/main.cpp.o' -c ../main.cpp

Is this the expected behavior?

This was the case in old versions but that was changed. Which version are you using?
 

Rob

unread,
Aug 6, 2015, 1:19:00 PM8/6/15
to The Meson Build System, rdool...@gmail.com, tsn...@gmail.com
 $ ~/src/meson/meson.py -v
0.26.0-research

it was just grabbed from github a week or so ago - 0728484ef77a8bcec542384abc0c7a82544e77ab

Jussi Pakkanen

unread,
Aug 6, 2015, 4:13:23 PM8/6/15
to Rob, The Meson Build System, Noam Meltzer
On Thu, Aug 6, 2015 at 8:18 PM, Rob <rdool...@gmail.com> wrote:
 
 $ ~/src/meson/meson.py -v
0.26.0-research

it was just grabbed from github a week or so ago - 0728484ef77a8bcec542384abc0c7a82544e77ab

This is fixed in trunk now. Thanks for reporting it.
 

Rob

unread,
Aug 7, 2015, 2:11:11 AM8/7/15
to The Meson Build System, rdool...@gmail.com, tsn...@gmail.com


On Thursday, August 6, 2015 at 1:13:23 PM UTC-7, Jussi Pakkanen wrote:

This is fixed in trunk now. Thanks for reporting it.
 
 
Works great... thanks! 
Reply all
Reply to author
Forward
0 new messages