compile

Description

This task will run the C++ compiler defined (using the compiler-task) for the current platform in order to compile C++-files to object files. To create an executable or library from the object files, use the linkexe or linklib-tasks.

Parameters

Attribute Description Required
objdir The directory where all object files will be placed. Platform specific endings (typically .o or .obj) will be added to the compiled files
Yes.
debug
true turns on debugging symbols. false optimizes for release. Exactly what is done is determined by the compiler-task that is used.
No. Default: "true"
os
Override the detected OS to use another linker definition. This might be handy when using different compiler suites on the same machine and build script. No. Default:  detected OS name

Parameters specified as nested elements

srcfiles

This is an ant FileSet which selects all c++-files to compile. It can be accessed using an arglist with the name="srcfiles". Make sure only valid C++-files are included.

includepath

An ant Path which tells the compiler where to find #include-files. It can be accessed using an arglist with the name="includepath". A convenient way to use this element is to reference a globally defined path using the "pathref"-attribute.

define

This nested element can be specified any number of times and is used to define preprocessor identifiers. It  can be accessed using an arglist with the name="defines". That arglist will be a list with all defines formatted like "name=value" in a string.

Examples

<compile objdir="tmp/obj">
 <srcfiles dir="source" includes="Hello.cpp"/>
</compile>
This will compile the file Hello.cpp into Hello.o, Hello.obj or whateevr the platform specifies, possibly also putting it in another directory

A more likely example is one which specifies an includepath to the compiler. Here the preprocessor identifier USE_LOWLEVEL_IO is set to 1:
<compile objdir="tmp/obj">
<includepath>
<pathelement path="resource/lib/boost-1.33.1"/>
</includepath>
 <srcfiles dir="source" includes="**/*.cpp"/>
<define name="USE_LOWLEVEL_IO" value="1"/>
</compile>
When the number of  compile targets increases it is a good idea to specify the include path via reference as below:
<property name="debug-flag" value="true/>
<path id="client5-path">
<pathelement path="build/tmp/build/generatedsource"/>
<pathelement path="source/production/main"/>
<pathelement path="resource/lib/boost-1.33.1"/>
<pathelement path="${boost.include.dir}"/>
</path>
<compile objdir="obj/protocol-in" debug=${debug-flag}>
<includepath refid="client5-path"/>
<srcfiles dir="generatedsource" includes="authentication_in/*.cpp,domain_casino_in/*.cpp"/>
</compile>
<compile objdir="obj/protocol-out" debug=${debug-flag}>
<includepath refid="client5-path"/>
<srcfiles dir="generatedsource" includes="authentication_out/*.cpp,domain_casino_out/*.cpp"/>
</compile>