01-16-2013 06:46 PM
'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?
Solved! Go to Solution.
01-20-2013 06:17 AM
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:
QMAKE_TARGET = myapp 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 Device-Test-Release: $(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:
Now, you need to create a new Build Configuration in the momentics IDE.
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:
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:
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"> <entryPointType>Qnx/Cascades</entryPointType> <platformArchitecture>armle-v7</platformArchitecture> <asset path="arm-test/o.le-v7/libmyapp.so" entry="true" type="Qnx/Elf">myapp</asset> </configuration>
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 {
DEFINES += TEST_BUILD_WHOOP
}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:
#ifdef TEST_BUILD_WHOOP /* whoohoo! building for test */ #endif