net.sf.antcontrib.cpptasks
Class CCTask

java.lang.Object
  |
  +--org.apache.tools.ant.ProjectComponent
        |
        +--org.apache.tools.ant.Task
              |
              +--net.sf.antcontrib.cpptasks.CCTask

public class CCTask
extends org.apache.tools.ant.Task

Compile and link task.

This task can compile various source languages and produce executables, shared libraries (aka DLL's) and static libraries. Compiler adaptors are currently available for several C/C++ compilers, FORTRAN, MIDL and Windows Resource files.

Copyright (c) 2001, 2002, Ant-Contrib project.

Licensed under the Apache Software License 1.1, http://www.apache.org/LICENSE.

For use with Jakarta Ant 1.5 or later. This software is not a product of the of the Apache Software Foundation and no endorsement is implied.

THIS SOFTWARE IS PROVIDED 'AS-IS', See http://www.apache.org/LICENSE for additional disclaimers.

To use:
  1. Place cpptasks.jar into jakarta-ant-1.5/lib directory.
  2. Add <taskdef resource="cpptasks.tasks"/> and <typedef resource="cpptasks.types"/> to build.xml.
  3. Add <cc/>, <compiler/> and <linker/> elements to project.
  4. Set path and environment variables to be able to run compiler from command line.
  5. Build project.

Author:
Adam Murdoch, Curt Arnold

Inner Class Summary
static class CCTask.RuntimeType
          Enumerated attribute with the values "dynamic" and "static",
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
CCTask()
           
 
Method Summary
 void addConfiguredCompiler(CompilerDef compiler)
          Adds a compiler definition or reference.
 void addConfiguredCompilerArg(CompilerArgument arg)
          Adds a compiler command-line arg.
 void addConfiguredDefineset(DefineSet defs)
          Adds a defineset.
 void addConfiguredLinker(LinkerDef linker)
          Adds a linker definition.
 void addConfiguredLinkerArg(LinkerArgument arg)
          Adds a linker command-line arg.
 void addFileset(ConditionalFileSet srcSet)
          Adds a source file set.
 void addLibset(LibrarySet libset)
          Adds a library set.
 void addSyslibset(SystemLibrarySet libset)
          Adds a system library set.
protected  int checkForChangedIncludeFiles(java.util.Hashtable targets)
          Checks all targets that are not forced to be rebuilt or are missing object files to be checked for modified include files
protected  LinkerConfiguration collectExplicitObjectFiles(java.util.Vector objectFiles, java.util.Vector sysObjectFiles)
           
 IncludePath createIncludePath()
          Adds an include path.
 PrecompileDef createPrecompile()
          Specifies precompilation prototype file and exclusions.
 SystemIncludePath createSysIncludePath()
          Adds a system include path.
 void execute()
          Executes the task.
 java.lang.String getDataset()
          Gets the dataset.
protected  TargetHistoryTable getLinkHistory(TargetHistoryTable objHistory)
           
protected  TargetInfo getLinkTarget(LinkerConfiguration linkerConfig, java.util.Vector objectFiles, java.util.Vector sysObjectFiles, java.util.Hashtable compileTargets)
           
 java.io.File getObjdir()
           
 java.io.File getOutfile()
           
static java.util.Hashtable getTargetsToBuildByConfiguration(java.util.Hashtable targets)
          Builds a Hashtable to targets needing to be rebuilt keyed by compiler configuration
 void setClassname(java.lang.String classname)
          Sets the default compiler adapter.
 void setDataset(java.lang.String dataset)
          Sets the dataset for OS/390 builds.
 void setDebug(boolean debug)
          Enables or disables generation of debug info.
 void setDependencyDepth(int depth)
          Deprecated.
 void setExceptions(boolean exceptions)
          Enables generation of exception handling code
 void setIncremental(boolean incremental)
          Enables or disables incremental linking.
 void setLibtool(boolean libtool)
          Set use of libtool.
 void setLink(OutputTypeEnum outputType)
          Deprecated.  
 void setMultithreaded(boolean multi)
          Enables or disables generation of multithreaded code
 void setName(CompilerEnum name)
          Sets type of the default compiler and linker.
 void setObjdir(java.io.File dir)
          Sets the destination directory for object files.
 void setOutfile(java.io.File outfile)
          Sets the output file name.
 void setOuttype(OutputTypeEnum outputType)
          Sets the output file type.
 void setProject(org.apache.tools.ant.Project project)
          Sets the project.
 void setRebuild(boolean rebuildAll)
          If set to true, all files will be rebuilt.
 void setRelentless(boolean relentless)
          If set to true, compilation errors will not stop the task until all files have been attempted.
 void setRuntime(CCTask.RuntimeType rtlType)
          Sets the type of runtime library, possible values "dynamic", "static".
 void setSubsystem(SubsystemEnum subsystem)
          Sets the nature of the subsystem under which that the program will execute.
 void setWarnings(CompilerDef.WarningLevel level)
          Enumerated attribute with the values "none", "severe", "default", "production", "diagnostic", and "failtask".
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CCTask

public CCTask()
Method Detail

setObjdir

public void setObjdir(java.io.File dir)
Sets the destination directory for object files.

getObjdir

public java.io.File getObjdir()

setProject

public void setProject(org.apache.tools.ant.Project project)
Sets the project.
Overrides:
setProject in class org.apache.tools.ant.ProjectComponent

addFileset

public void addFileset(ConditionalFileSet srcSet)
Adds a source file set. Files in these filesets will be auctioned to the available compiler configurations, with the default compiler implied by the cc element bidding last. If no compiler is interested in the file, it will be passed to the linker. To have a file be processed by a particular compiler configuration, add a fileset to the corresponding compiler element.

createIncludePath

public IncludePath createIncludePath()
Adds an include path. Include paths will be inherited by nested compiler elements that do not have inherit="false".

createSysIncludePath

public SystemIncludePath createSysIncludePath()
Adds a system include path. Locations and timestamps of files located using the system include paths are not used in dependency analysis. Standard include locations should not be specified. The compiler adapters should recognized the settings from the appropriate environment variables or configuration files. System include paths will be inherited by nested compiler elements that do not have inherit="false".

addConfiguredCompiler

public void addConfiguredCompiler(CompilerDef compiler)
Adds a compiler definition or reference.
Parameters:
compiler - compiler
Throws:
java.lang.NullPointerException - if compiler is null

addConfiguredLinker

public void addConfiguredLinker(LinkerDef linker)
Adds a linker definition. The first linker that is not disqualified by its "if" and "unless" attributes will perform the link. If no child linker element is active, the linker implied by the cc elements name or classname attribute will be used.
Parameters:
linker - linker
Throws:
java.lang.NullPointerException - if linker is null

setDebug

public void setDebug(boolean debug)
Enables or disables generation of debug info.

setLibtool

public void setLibtool(boolean libtool)
Set use of libtool. If set to true, the "libtool " will be prepended to the command line for compatible processors
Parameters:
libtool - If true, use libtool.

setMultithreaded

public void setMultithreaded(boolean multi)
Enables or disables generation of multithreaded code
Parameters:
multi - If true, generated code may be multithreaded.

setExceptions

public void setExceptions(boolean exceptions)
Enables generation of exception handling code

setRebuild

public void setRebuild(boolean rebuildAll)
If set to true, all files will be rebuilt.

setDependencyDepth

public void setDependencyDepth(int depth)
Deprecated. Controls the depth of the dependency evaluation. Used to do a quick check of changes before a full build. Any negative value which will perform full dependency checking. Positive values will truncate dependency checking. A value of 0 will cause only those files that changed to be recompiled, a value of 1 which cause files that changed or that explicitly include a file that changed to be recompiled. Any non-negative value will cause a BuildException to be thrown before attempting a link or completing the task.

createPrecompile

public PrecompileDef createPrecompile()
                               throws org.apache.tools.ant.BuildException
Specifies precompilation prototype file and exclusions. Inherited by all compilers that do not have inherit="false".

setLink

public void setLink(OutputTypeEnum outputType)
Deprecated.  

Sets the output file type. Supported values "executable", "shared", and "static".

setOuttype

public void setOuttype(OutputTypeEnum outputType)
Sets the output file type. Supported values "executable", "shared", and "static".

addConfiguredCompilerArg

public void addConfiguredCompilerArg(CompilerArgument arg)
Adds a compiler command-line arg. Argument will be inherited by all nested compiler elements that do not have inherit="false".

addConfiguredLinkerArg

public void addConfiguredLinkerArg(LinkerArgument arg)
Adds a linker command-line arg. Argument will be inherited by all nested linker elements that do not have inherit="false".

addConfiguredDefineset

public void addConfiguredDefineset(DefineSet defs)
Adds a defineset. Will be inherited by all compiler elements that do not have inherit="false".
Parameters:
defs - Define set

setOutfile

public void setOutfile(java.io.File outfile)
Sets the output file name. If not specified, the task will only compile files and not attempt to link. If an extension is not specified, the task may use a system appropriate extension and prefix, for example, outfile="example" may result in "libexample.so" being created.
Parameters:
outfile - output file name

getOutfile

public java.io.File getOutfile()

setSubsystem

public void setSubsystem(SubsystemEnum subsystem)
Sets the nature of the subsystem under which that the program will execute. Supported subsystems
guiGraphical User Interface
consoleCommand Line Console
otherOther
Parameters:
subsystem - subsystem
Throws:
java.lang.NullPointerException - if subsystem is null

addSyslibset

public void addSyslibset(SystemLibrarySet libset)
Adds a system library set. Timestamps and locations of system library sets are not used in dependency analysis. Essential libraries (such as C Runtime libraries) should not be specified since the task will attempt to identify the correct libraries based on the multithread, debug and runtime attributes. System library sets will be inherited by all linker elements that do not have inherit="false".
Parameters:
libset - library set
Throws:
java.lang.NullPointerException - if libset is null.

addLibset

public void addLibset(LibrarySet libset)
Adds a library set. Library sets will be inherited by all linker elements that do not have inherit="false".
Parameters:
libset - library set
Throws:
java.lang.NullPointerException - if libset is null.

setRelentless

public void setRelentless(boolean relentless)
If set to true, compilation errors will not stop the task until all files have been attempted.
Parameters:
relentless - If true, don't stop on the first compilation error

setName

public void setName(CompilerEnum name)
Sets type of the default compiler and linker. Supported compilers
gcc (default)GCC C++ compiler
g++GCC C++ compiler
c++GCC C++ compiler
msvcMicrosoft Visual C++
bccBorland C++ Compiler
msrcMicrosoft Resource Compiler
brcBorland Resource Compiler
dfCompaq Visual Fortran Compiler
midlMicrosoft MIDL Compiler
iclIntel C++ compiler for Windows (IA-32)
eclIntel C++ compiler for Windows (IA-64)
iccIntel C++ compiler for Linux (IA-32)
eccIntel C++ compiler for Linux (IA-64)
CCSun ONE C++ compiler
aCCHP aC++ C++ Compiler
os390OS390 C Compiler
os400Icc Compiler
sunc89Sun C89 C Compiler
xlCVisualAge C Compiler

setClassname

public void setClassname(java.lang.String classname)
Sets the default compiler adapter. Use the "name" attribute when the compiler is a supported compiler.
Parameters:
classname - fully qualified classname which implements CompilerAdapter

getTargetsToBuildByConfiguration

public static java.util.Hashtable getTargetsToBuildByConfiguration(java.util.Hashtable targets)
Builds a Hashtable to targets needing to be rebuilt keyed by compiler configuration

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Executes the task. Compiles the given files.
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - if someting goes wrong with the build

collectExplicitObjectFiles

protected LinkerConfiguration collectExplicitObjectFiles(java.util.Vector objectFiles,
                                                         java.util.Vector sysObjectFiles)

getLinkTarget

protected TargetInfo getLinkTarget(LinkerConfiguration linkerConfig,
                                   java.util.Vector objectFiles,
                                   java.util.Vector sysObjectFiles,
                                   java.util.Hashtable compileTargets)

getLinkHistory

protected TargetHistoryTable getLinkHistory(TargetHistoryTable objHistory)

checkForChangedIncludeFiles

protected int checkForChangedIncludeFiles(java.util.Hashtable targets)
Checks all targets that are not forced to be rebuilt or are missing object files to be checked for modified include files

setWarnings

public void setWarnings(CompilerDef.WarningLevel level)
Enumerated attribute with the values "none", "severe", "default", "production", "diagnostic", and "failtask".

setRuntime

public void setRuntime(CCTask.RuntimeType rtlType)
Sets the type of runtime library, possible values "dynamic", "static".

setIncremental

public void setIncremental(boolean incremental)
Enables or disables incremental linking.
Parameters:
incremental - new state

getDataset

public java.lang.String getDataset()
Gets the dataset.
Returns:
Returns a String

setDataset

public void setDataset(java.lang.String dataset)
Sets the dataset for OS/390 builds.
Parameters:
dataset - The dataset to set


Copyright © 2001-2002 Ant-Contrib project. All Rights Reserved.