0

I am compiling code for Microchip dspic33 series processors using Microchip's XC16 compiler.

I have some code that is used in several applications (i.e. it is in a code library). For certain modules, I want to ensure that certain compiler flags are set during compilation, ideally using the pre-processor. In particular, I am interested in testing for the -mauxflash and -code-in-auxflash target flags.

Is there a way to test for compiler options during compilation?

I have tried dumping all the #defines using xc16-gcc -dM -E - < /dev/null, but nothing seems to change. There are 3 defines related to auxflash (AUXFLASH_LENGTH, __AUXFLASH_BASE, and __HAS_AUXFLASH), but nothing related to the target flags.

EBlake
  • 735
  • 7
  • 14

1 Answers1

2

not all flags affect CPP defines, so you might be SOL there. your use of -dM -E is the best way to check.

however, there are a few features that might be useful to you:

  1. -grecord-gcc-switches: this records all the flags used at compile time on a per-object basis in the DWARF info. you could then have a script that checks the objects and throws an error if one was built w/out the flag you care about.
  2. __attribute__((optimize("flags"))): gcc lets you force specific flags on a per-function basis.
  3. #pragma GCC optimize ("flags"): gcc lets you force specific flags at the file level.
Mike Frysinger
  • 2,827
  • 1
  • 21
  • 26
  • Thanks! Unfortunately, the flags get interpreted as -f options instead of -m options, so they are not recognized. I poked around a bit and discovered `#pragma GCC target("flags")`, but using this in XC16 flavoured GCC results in the error `#pragma GCC target is not supported for this machine`. I guess the options you suggested are good for changing optimization levels, etc., but not -m options. – EBlake Mar 10 '16 at 19:22
  • Further to the above, I just realized that the -m options I happen to be concerned with (`auxflash` and `const-in-auxflash`) are memory model options, and not target options. Perhaps there is no way to set these using pragmas. – EBlake Mar 10 '16 at 19:31