I am preparing to adapt an existing AVR C/C++ application to support a different AVR processor (and subsequently a non-AVR processor), and before I get started, I'd like to make an appropriate choice for how to deal with the different compilation paths that would be needed to accommodate differing target types. My experience level with Atmel Studio 7 is "an hour after beginner", thanks to the outstanding support I've encountered here so far (thank you!)
Is it possible (if so, how?) to select my target processor type at the start of my C/C++ source file (using the GNU C/C++ toolchain in Atmel Studio 7, or potentially a completely different IDE/toolchain), rather than (or as an override to) the target type normally configured in Atmel Studio 7 solution/project?
Ideally, I'd like to have something like this ("why" is noted below):
// Beginning of main.cpp file - or any other c/cpp in the same project/solution) is here
// Today, choose target X, not target Y or Z - tomorrow we might choose target Y or Z rather than target X.
//#define target is Y
//#define target is Z
// What would I put here, #include the header file for processor of type X?
// What would I put here, #include the header file for processor of type Y?
// What goes here might be different, assuming target Z is not to be handled by the Atmel Studio 7 GCC tool chain
// in the rest of the code in this file, it would (when encountering something target-specific) look like this:
// A segment of the project source code specific to target X
// A segment of the project source code specific to target Y
// A segment of the project source code specific to target Z
I am open to any way to solve this, however, it would be very much preferable if I could use #define and #ifdef statements, as the source code would take different compilation paths depending on which target is currently selected (as in different bits of code to accommodate the detail differences in onboard peripherals present in the differing targets), and would at some point be re-purposed for yet a different (non-AVR, so other toolchain) target type.
"why?" - I am working with an existing program (source code) targeting a specific AVR processor type (which is currently set in the Atmel Studio 7 solution/project settings), and need to create within the same files and project/solution support for another AVR processor type (and a third option for a non-AVR processor type), and be able choose which processor type is going to get built (of course, for Atmel Studio 7 would be constrained to the processor types it supports), preferably using #define and #ifdef type directives (so that the solution has some portability out of Atmel Studio 7 when the need arises.)
Thank you for any advice or request for clarifying questions,