This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there conditional compilation depending on the project?

Hi there!

In a few weeks, I might have to derive a product from another products. The hardware is the same, but the software is slightly different.

I think, it would be a drag to copy the sources to another directory and and take care of two code versions.

So it would be nice to know, which project it is while compilation time, so that I could use some #ifdef statement to get conditional compilation.

Other than that, I just had the idea to have a "higher source level files that define a compiler constant and then include the low level source files.

Like:


"highlevel.c"
#define OEM
#include "lowlevel.c"

"lowlevel.c"
#ifdef OEM
#include ...
#else
#include ...
#endif

// some common source

#ifdef OEM
// OEM source only
#else
// non OEM source
#endif

// some common source

Then I only need a different linker file to get different fuctions, but only one source file set.

Is there any better way?

Thanks,
Sven

Parents
  • If you use uVision2, you can create a target for each program. In each target, you may specify completely different compiler, assembler, and linker options. You may define macros for the compiler and assembler in the project dialog. You can even specify a different compiler (c51 vs c166).

    In each target you can include or exclude files or groups from the build. If you have a bunch of files that are only used in one program, add them to a group. In the program where they are not used, you can uncheck Include in Build and uVision2 excludes these files from the linkage. So, you can, in effect, have a conditional linkage.

    The benchmarks listed on this web site:

    http://www.keil.com/benchmks/c166_v4_small.asp

    http://www.keil.com/benchmks/c251_v3_xtiny.asp

    http://www.keil.com/benchmks/c51_v6_small.asp

    were created using a single project with multiple targets (each configured for the appropriate compiler). The benchmarks do a lot of stuff and I saw no need to maintain 3 separate projects.

    Let me know if you need more details.

    Jon

Reply
  • If you use uVision2, you can create a target for each program. In each target, you may specify completely different compiler, assembler, and linker options. You may define macros for the compiler and assembler in the project dialog. You can even specify a different compiler (c51 vs c166).

    In each target you can include or exclude files or groups from the build. If you have a bunch of files that are only used in one program, add them to a group. In the program where they are not used, you can uncheck Include in Build and uVision2 excludes these files from the linkage. So, you can, in effect, have a conditional linkage.

    The benchmarks listed on this web site:

    http://www.keil.com/benchmks/c166_v4_small.asp

    http://www.keil.com/benchmks/c251_v3_xtiny.asp

    http://www.keil.com/benchmks/c51_v6_small.asp

    were created using a single project with multiple targets (each configured for the appropriate compiler). The benchmarks do a lot of stuff and I saw no need to maintain 3 separate projects.

    Let me know if you need more details.

    Jon

Children