Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange
Accepted Solution

Creating a new build configuration

'd like to create a new build configuration in Momentics in that will compile my app differently (it will pass some additional C preprocessor macros to the compiler when my project is built).


Let's say I want to base it on Device-Release, but I want to call it Device-Release-Testing instead. I can see how to do this step through the IDE already: (Project -> Build Configurations -> Manage)


This will (I assume) build my project over the top of the arm/o-le.v7/ directory. What I want though, is to have the project built in a new location so that I can ensure my release binaries never get muddled up.

I'd like this configuration instead to be built under the arm-test/o-le.v7/ directory. I believe this should be possible because the 'Device-Profile' configuration does something similar, with builds ending up under arm-p


My question is, how does the build configuration in momentics (stored in the .cproject configuration file) specify this change? I can see the 'Device-Profile' configuraiton inside the .cproject directory - but there is no reference to an 'arm-p' directory, and there is nothing in my application's PRO file that gives any indication of a 'profile' configuration.


I grep'd my entire codebase and I just don't see how to do this - yet it must be possible. What am I missing here?

Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: Creating a new build configuration

I figured out how to do this, in case anyone else is interested. The key is understand that the compilation lifecycle starts with Make, and not qmake / myapp.pro as I first believed. 


By default a Cascades makefile looks like:


QMAKE_TARGET  =  myapp
PROJECT_DIR   := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
I18N_DIR      := $(PROJECT_DIR)/translations

include mk/cs-base.mk

The cs-base.mk (found in your NDK) contains everything you need to understand how the make process works. In cs-base.mk you can see the built-in rules for the Device-Debug, Device-Release, Simulator-Debug configurations. These are hard-coded into the build system.


You don't want to edit cs-base.mk to add your own configurations, so instead add the following lines to the end of the Makefile in your application root:


PROJECT_DIR   := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
I18N_DIR      := $(PROJECT_DIR)/translations

include mk/cs-base.mk

# add the following:
arm-test/Makefile: $(QMAKE_TARGET).pro

   $(info ***** This is my custom make target ***** )
   @mkdir -p arm-test
   cd arm-test && $(QMAKE) -spec blackberry-armv7le-qcc ../$(QMAKE_TARGET).pro CONFIG+=release CONFIG+=device CONFIG+=test
   $(MAKE) -C ./arm-test -f Makefile release

All I did was copy the most appropriate make rules from cs-base.mk, and defined my own rule for the Device-Test-Release configuration. The above make rules do the following:


  1. Creates the arm-test directory
  2. Adds  'test' to the the CONFIG variable - this will be available in my PRO file


Now, you need to create a new Build Configuration in the momentics IDE.


  1. Right-click your project in the project explorer (myapp). From the popup menu select:
  2. Build Configurations -> Manage

In the Manage Configurations dialog, click "New.." and create a new configuration called "Device-Test-Release" (or whatever you want to call yours. Make sure that you Copy Settings from an "Existing Configuration". Pick the most appropriate for your scenario. In my case I based my new build configuration on "Device-Release".


At this point, you select the new build configuration when you build your project:

  1. Right-click your project in the project explorer
  2. Build-Configuraitons -> Set Active
  3. Select the new 'Device-Test-Release" configuration.
  4. Build!

However you will find that nothing different happens. This is because Device-Test-Release is based on Device-Release, so exactly the same thing happens when you build it. We therefore need to modify Device-Test-Release so that our custom rule in our makefile is invoked, instead of the default Device-Release target


Bring up the project properties:

  1. Right-click your project in the project explorer
  2. Select Properties
  3. Goto the C/C++ Build tab
  4. Select Device-Test-Release from the Configuration drop-down
  5. Goto the Behaviour tab
  6. There are two text-fields there ("Build on resource save" and "Build") 
  7. Change the textfields that say "Device-Release" to "Device-Test-Release"
  8. Click Apply 

The procedure above 'links' your build configuraiton in the IDE, with the make target in your Makefile. Now when you build your project (in the Device-Test-Release configuration), it will be built into the arm-test/ directory


There are still two more things you need to do though:


Edit your bar-descriptor.xml file, and add a new configuration, based on what you see for Device-Release. Just copy the Device-Release <configuration> section that is already defined, like so:


<configuration name="Device-Test-Release">
  <asset path="arm-test/o.le-v7/libmyapp.so" entry="true" type="Qnx/Elf">myapp</asset>


You need to make sure that the <asset path=""  specifies your new arm-test directory, and obviously change  <configuration name=""  as well.


Once you have done this, you can finally edit the myapp.pro file, and specify some custom rules in there. All I did was add the following rule:


# put this in the myapp.pro file

test {

 Remember the "CONFIG += test" that we put into the project Makefile? In the above PRO file, we leverage this by creating a test{} rule, which applies only when we build the Device-Test-Release configuration. Whenever the test rule runs, we can add a TEST_BUILD_WHOOP preprocessor definition. Now whenever our source files are compiled (in the test configuration), the TEST_BUILD_WHOOP macro is defined, and we can put custom code in that only gets compiled when we are testing.


i.e. in your myapp.cpp file:



/* whoohoo! building for test */