Variables in Project.meta

bake allows you to use

  • user defined

  • predefined

  • environment

variables in your Project.meta file. Every environment and predefined variable can be overwritten by the user. If a variable is not found at all, it will be set to an empty string (see below how to change that default behaviour).

Using variables

Variables can be used using the following syntax:

$(ABC)

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

IncludeDir "$(ABC)"

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!"
Set MyVar, cmd: "ruby calcVar.rb"

In the latter one the variable is set to the output of the command.

Predefined 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

$(WorkingDir)

Directory from which bake is called

c:/Workspaces/Project

$(OriginalDir)

Directory of the containing meta file. Useful for relative paths from Adapt files.

c:/Root/admin/adapt/coverage

$(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

$(Uid)

CRC32 over relative path to MainProjectDir plus MainConfigName, e.g. “../libs/utils,Debug”

03FAB429

$(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

$(ToolchainName)

Names of the used DefaultToolchain

GCC

$(/)

Evalutes to the directory path seperator of the current platform

Windows: \, Other: /

$(:)

Evaluates to the path variable seperator of the current platform

Windows: ;, Other: :

$(QacActive)

Evaluates to “yes” if QAC is running (via bakeqac), otherwise “no”.

yes, no

Environment variables

Usually used if system dependent stuff is needed like path to a specific tool etc.

Nested variables

It is also possible to nest variables.

Example:

$(ABC$(DEF)GH)

Complex variables

bake supports three complex variables:

$(OutputDir, <project name>, <config name>)
e.g.:
$(OutputDir, MyGreatLib, Debug)

This will evaluate to the output directory of a specific configuration.

$(ProjectDir, <project name>)

This will evaluate to the directory of a specific project.

$(FilterArguments, <filterName>)

If a filter is specified, the argument of the filter is returned.

Example:

  • cmd: “bake … –do run=–gtest_repeat=2”

  • Project.meta: $(FilterArguments, –gtest_repeat)

  • result: 2

Mandatory variables

If a variable is not found at all, it will be set to an empty string. This can be changed to an error with a “!” sign:

$(PATH_TO_ABC!)
$(OutputDir!, application, Debug)

For convenience, the “!” can be used on every parameter (which means exactly the same as using on the first parameter).

$(OutputDir, application!, Debug)
$(OutputDir, application, Debug!)

Notes and warnings

Equal variables in the main config:

Variable

Is equal to

$(MainConfigName)

$(ConfigName)

$(MainProjectName)

$(ProjectName)

Warning

Variables in Dependency definitions are not allowed!