It is not uncommon to need to build the same BSP with different projects, or the same driver under different BSPs.   Often this means needing to build the code in different ways for different needs.  Of course any good C/C++ programmer knows to use macros to control how the code is built, and any good Platform Builder user knows to use environment variables to control the build.

The dilemma is how to tie the environment variables together with the macros.  Unfortunately this is not automatic, you can't check for the environment variables in your C/C++ code.

The solution is to use CDEFINES.  CDEFINES is an environment variable that is used to pass command line arguments to the C compiler.  So that means that we need to set CDEFINES prior to compiling.

CDEFINES can be set in a sources file for a particular folder, or CDEFINES can be set in sources.cmn for an entire tree.  To do this and use the environment variables you will need to check the value of the environment variable, then set CDEFINES as needed.  Example:

!IF "$(MY_ENV_VAR)"=="1"
CDEFINES=$(CDEFINES) -DMY_DEFINE
!ENDIF

Which checks to see if MY_ENV_VAR is set to one, then adds the -D flag, which defines a macro, and defines MY_DEFINE.  An important part of this is setting CDEFINES=$(CDEFINES) plus something.  This ensures that in setting CDEFINES that the existing CDEFINES is not deleted.

You can now check to see if MY_DEFINE is defined in your C/C++ code.

Go to Summary of Building Windows CE

Copyright © 2008 – Bruce Eitman
All Rights Reserved