Variables in Project.meta

bake allows you to use pre defined and/or user defined variables in your Project.meta file. Defined variables then can be used using the following syntax:

$(MyIncludes)

The variable MyIncludes will be substitued by its value, therefore a real life usage would look something like this:

IncludeDir "$(MyIncludes)"

User defined variables

There are two ways to create user defined variables.

  1. The variable is defined with the –set command line option:
User@Host:~$ bake ... --set MyVar="Hello world!"
  1. THe variable is defined directly in the Project.meta file.
Set MyVar, value: "Hello world!"

Pre defined bake environment variables

Variable Description Example
$(MainConfigName) Evaluates to the main config name Debug
$(MainProjectName) Evaluates to the main project name bootloader
$(ConfigName) Evaluates to the config name lib
$(ProjectName) Evaluates to the project name canDriver
$(ProjectDir) Evaluates to the full path of the project directory C:/Root/MyProject
$(MainProjectDir) Evaluates to the full path of the root projec directory C:/Root/Main
$(OutputDir) Evaluates to the full path of the output directory of the current config build_lib_bootloader_Debug
$(OutputDir,projName,confName) Evaluates to the output dir of a specific config build_lib_some_Debug
$(ArtifactName) Evaluates to the artifact. bootloader_1.0.elf
$(ArtifactNameBase) Evaluates to the base artifact name (Without file exension) bootloader_1.0
$(Time) Evaluates to the current time 2012-12-24 20:00:00 +0200
$(Hostname) Evaluates to the hostname MY_COMPUTER
$(CPPPath) Evaluates to the base path of the c++ compiler /usr/bin
$(CPath) Evaluates to the base path of the c compiler /usr/bin
$(ASMPath) Evaluates to the base path of the assembler /usr/bin
$(ArchiverPath) Evaluates to the base path of the archiver /usr/bin
$(LinkerPath) Evaluates to the base path of the linker /usr/bin
$(/) Evalutes to the directory path seperator of the current platform Windows: \, Other: /
$(:) Evaluates to the path variable seperator of the current platform Windows: ;, Other: :

Tip

It is also possible to retrieve arbitrary an environment variable using the following syntax:

$(EnvironmentVariable)

Evaluates to the Environment with the specified name, if the specified environment variable does not exists it will be substituted by an empty string.

Note

Equal variables in the main config

Variable Is equal to
$(MainConfigName) $(ConfigName)
$(MainProjectName) $(ProjectName)

Warning

Variables in Dependency definitions are not allowed!

Nested variables

It is also possible to nest variables.

Example:

$(OutputDir,$(TheProject),$(TheConfig))
$(ABC$(DEF)GH)

Auto-adjustment of paths to existing projects

Warning

If paths to other projects are needed, e.g. to “bootloaderUpdater”, don’t write a hard coded relative path like this:

CommandLine "../bootloaderUpdater/tools/PrimaryBootloader2Include.exe

If paths to other projects are needed, e.g. to “bootloaderUpdater” just reference it starting from the project folder.

Example:

CommandLine "bootloaderUpdater/tools/PrimaryBootloader2Include.exe

or:

IncludeDir "myProjectName/bootloaderUpdater/whatever"

bake recognizes that the first part of the path is a valid project name and calculates the relative path to the project automatically. If you have the special case that the referenced project is contained in an other workspace root, you can use the -w parameter or you define a roots.bake.

Note

The path auto adjustment is applied for the following elements:

  • IncludeDir
  • ExternalLibrary
  • ExternalLibrarySearchPath
  • UserLibrary
  • CommandLine