Search code examples
arduinoarduino-ide

Have the Arduino IDE set compiler warnings to error


Is there a way to set the compiler warnings to be interpreted as an error in the Arduino IDE?
Or any generic way to set GCC compiler options?

I have looked at the ~/.arduino/preferences.txt file, but I found nothing that indicates fine-tuned control. I also looked if I could set GCC options via environment variables, but I did not find anything.

I don't want to have verbose compiler output (which you can specify using the IDE) that is way too much distracting non-essential information, and I don't want to waste my time on reading through it.

I want for a compilation to stop on a warning, so code can be cleaned up. My preference would be to be able to set -Werror= options, but a generic -Werror will do for the small code size of .ino projects.

Addendum:

Based on the suggestion in the selected answer, I implemented an avr-g++ script and put that in the path before the normal avr-g++. For that I changed the Arduino command as follows:

-export PATH="${APPDIR}/java/bin:${PATH}"
+export ORGPATH="${APPDIR}/java/bin:${PATH}"
+export PATH="${APPDIR}/extra:${ORGPATH}"

And in the new directory extra in the APPSDIR (where the Arduino command is located), I have an avr-g++ which is a Python script:

#!/usr/bin/env python

import os
import sys
import subprocess

werr = '-Werror'
wall = '-Wall'

cmd = ['avr-g++'] + sys.argv[1:]
os.environ['PATH'] = os.environ['ORGPATH']
fname = sys.argv[-2][:]
if cmd[-2].startswith('/tmp'):
    #print fname, list(fname) # this looks strange
    for i, c in enumerate(cmd):
        if c == '-w':
            cmd[i] = wall
            break
    cmd.insert(1, werr)
subprocess.call(cmd)

So you replace the first command with the original compiler name and reset the environment used to exclude the extra directory.

The fname is actually strange. If you print it, it is only abc.cpp, but its length is much larger and it actually starts with /tmp. So I check for that to decide whether to add/update the compile options.


Solution

  • It looks like you are on Linux. Arduino is a script, so you can set PATH in the script to include a directory at the beginning to a directory containing a program, avr-g++. Then the Java stuff should take the compiler from there, should it not?

    That program then calls the normal /usr/bin/avr-g++ with the extra options.