Search code examples
cc-preprocessoriar

GCC -D equivalent for iarbuild.exe


I have a build machine server I am maintaining which is using Makefiles infrastructure.

As part of that infrastructure, I'm passing a few arguments to the Makefile from the build machine (example: user, build-server name, and various build variables known only when compiling for a specific project).

Some of these variables are aggregated to the code using gcc -D directive

-DSOME_VAR=VAL

I've now been asked to migrate an Iar Project into my build system. That is not a problem in itself, only I can't find any way to introduce preprocessor defines using iarbuild.exe command line tool.

I guess I could use an existing H file and edit it before compiling (using sed for example), but that's an ugly hack I would rather avoid if I can.

How do I properly achieve this with IAR?


Solution

  • To my understanding iarbuild does not support passing such parameters directly.

    There are two possibilities that were suggested by IAR support and that both work for me (using 7.40.2):

    1) Use a preinclude file

    • Go to Project->Options->C/C++ Compiler->Preprocessor
    • Add a preinclude file (e.g. preinclude.h)
    • Now have your build script generate that preinclude file before starting iarbuild

    2) Use "Defined symbols"

    • Go to Project->Options->C/C++ Compiler->Preprocessor
    • Add an option to "Defined symbols" and use environment variable, e.g. "SOMEVAR=$_SOMEVAL_$"
    • On the cmd line, set the environment variable, e.g. "set SOMEVAR=myvalue"
    • Run iarbuild

    The 2nd method is little more elegant, but the build will fail if the environment variable is not set, so I'll probably go with the 1st method.