Subversion Repositories DevTools

Rev

Rev 1750 | Rev 1754 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<project name="ant-cppcompile-task">

        <!-- 
                
                This macrodef is used to streamline and manage a common build framework.

                Many of the options listed below are documented within the cpptasks documentation.
        -->

        <macrodef name="cppcompile">

                <attribute      name="name"
                                        description="The logical name of the package to be built. Typically the ant.project.name"/>

                <attribute      name="version"
                                        description="The version of the package to be built. This may be the logical version rather than the released package version."/>

                <attribute      name="compiler"                 
                                        description="The compiler to be used (bcpp, msvc, suncc). Requires the associated ant-???? package where ???? is the compiler."/>

                <attribute      name="targetname"               
                                        default="@{name}"
                                        description="Optional target package name, which may include some target based identity, if different from the project name. Default to package 'name'"/>

                <attribute      name="buildtype"                        
                                        default="release"
                                        description="Optional type of build, whether 'debug' or 'release'. Defaults to 'release'"/>

                <attribute      name="compilerpath"             
                                        default="$${@{compiler}_bin}"
                                        description="Optional compiler path override. Normally defined within the ant-???? compiler package."/>

                <attribute      name="rtti"                             
                                        default="true"
                                        description="Optional flag, used to enable Run-Time Type Information"/>

                <attribute      name="exceptions"               
                                        default="true"
                                        description="Optional flag, used to enable exception handling support. Defaults to true"/>

                <attribute      name="multithreaded"            
                                        default="true"
                                        description="Optional flag, used to enable multithreaded support. Defaults to true"/>

                <attribute      name="optimize"                 
                                        default="speed"
                                        description="Optional flag, used to specify optimization. Defaults to 'speed', but is overridden to 'none' by debug buildtype."/>

                <attribute      name="outtype"                  
                                        default="executable"
                                        description="Optional flag, used to indicate the type of package being built (static, shared, executable)"/>

                <attribute      name="subsystem"                        
                                        default="console"
                                        description="Optional flag, used to indicate the nature of the subsystem under which the program will run. (gui, console, other)."/>

                <attribute      name="build" 
                                        default="${basedir}/build"
                                        description="The location of the project 'build' folder. Defaults to 'project basedir'/build. You do not normal need to provide this value."/>

                <attribute      name="objdir"                   
                                        default="@{build}/obj"
                                        description="Optional value, used to nominate the build object directory base."/>

                <attribute      name="pkgdir"                   
                                        default="@{build}/pkg"
                                        description="Optional value, used to nominate the build package directory."/>

                <element name="compiler-elements" optional="yes" implicit="yes" description="Any compiler specific parameters."/>

                <sequential>
                        <echo taskname="ant-cppcompile-task">Compiling @{name} Version: @{version}</echo>

                        <!-- Determine any compile type dependent flags
                                 Including naming standards, optimizations, etc -->
                        <if>
                                <equals arg1="@{buildtype}" arg2="debug"/>
                                <then>
                                        <property name="@{name}@{compiler}@{buildtype}-compile_type_symbol" value="D"/>
                                        <property name="@{name}@{compiler}@{buildtype}-debug_flag" value="true"/>
                                        <property name="@{name}@{compiler}@{buildtype}-compile_optimize" value="none"/>
                                </then>
                                <else>
                                        <property name="@{name}@{compiler}@{buildtype}-compile_type_symbol" value="P"/>
                                        <property name="@{name}@{compiler}@{buildtype}-debug_flag" value="false"/>
                                        <if>
                                                <equals arg1="@{optimize}" arg2=""/>
                                                <then>
                                                        <property name="@{name}@{compiler}@{buildtype}-compile_optimize" value="speed"/>
                                                </then>
                                                <else>
                                                        <property name="@{name}@{compiler}@{buildtype}-compile_optimize" value="@{optimize}"/>
                                                </else>
                                        </if>
                                </else>
                        </if>

                        <!-- Identify the compile platform extension -->
                        <condition property="compile.platform" value="win32">
                                <os family="windows"/>
                        </condition>

                        <condition property="compile.platform" value="win32">
                                <os family="dos"/>
                        </condition>

                        <condition property="compile.platform" value="sparc">
                                <os name="SunOS"/>
                        </condition>

                        <!-- Type of target => executable,plugin,shared,static -->
                        <if>
                                <equals arg1="@{outtype}" arg2="executable"/>
                                <then>
                                        <property name="targetfolder" value="bin.${compile.platform}"/>
                                </then>
                                <else>
                                        <property name="targetfolder" value="lib.${compile.platform}"/>
                                </else>
                        </if>

                        <mkdir dir="${objdir}/@{buildtype}_@{compiler}"/>
                        <mkdir dir="${objdir}/@{buildtype}_@{compiler}/@{targetname}"/>
                        <mkdir dir="@{pkgdir}"/>
                        <mkdir dir="@{pkgdir}/${targetfolder}"/>

                        <echo taskname="ant-cppcompile-task">Compile @{name} into @{pkgdir}/${targetfolder}/@{targetname}${version}${@{name}@{compiler}@{buildtype}-compile_type_symbol}</echo>
                        <echo taskname="ant-cppcompile-task">Using Compiler @{compiler} from @{compilerpath}</echo>
                        <echo taskname="ant-cppcompile-task">Placing Objects in ${objdir}/@{buildtype}_@{compiler}/@{targetname}</echo>
                        <echo taskname="ant-cppcompile-task">Use Compiler Includes from ${@{compiler}_include_@{buildtype}}</echo>
                        <echo taskname="ant-cppcompile-task">Use Package Includes from @{pkgdir}/include</echo>
                        <echo taskname="ant-cppcompile-task">Linking with Library ${@{compiler}_lib_@{buildtype}} Files: ${@{compiler}_libraries_@{buildtype}}</echo>

                        <cc name="${@{compiler}_compilername}" 
                                path="@{compilerpath}"
                                rtti="@{rtti}"
                                exceptions="@{exceptions}"
                                multithreaded="@{multithreaded}"
                                optimize="${@{name}@{compiler}@{buildtype}-compile_optimize}"
                                debug="${@{name}@{compiler}@{buildtype}-debug_flag}" 
                                outtype="@{outtype}" 
                                subsystem="@{subsystem}" 
                                outfile="@{pkgdir}/${targetfolder}/@{targetname}${version}${@{name}@{compiler}@{buildtype}-compile_type_symbol}"
                                objdir="${objdir}/@{buildtype}_@{compiler}/@{targetname}">

                                <compiler refid="@{compiler}_compiler_@{buildtype}_@{subsystem}"/>
                                <linker refid="@{compiler}_linker_@{buildtype}_@{subsystem}"/>

                                <includepath path="${@{compiler}_include_@{buildtype}}"/>
                                <includepath path="@{pkgdir}/include"/>

                                <compiler-elements/>
                                
                        </cc>

                </sequential>
        </macrodef>

</project>