Package net.sf.antcontrib.cpptasks
Class CCTask
- java.lang.Object
-
- org.apache.tools.ant.ProjectComponent
-
- org.apache.tools.ant.Task
-
- net.sf.antcontrib.cpptasks.CCTask
-
- All Implemented Interfaces:
java.lang.Cloneable
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-2008, The Ant-Contrib project.
Licensed under the Apache Software License 2.0, http://www.apache.org/licenses/LICENSE-2.0.
For use with Apache 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/licenses/LICENSE-2.0 for additional disclaimers.
To use:- Place cpptasks.jar into Ant's classpath by placing it in Ant's lib directory, adding it to the CLASSPATH environment variable or by using the -lib command line option.
-
Add type and task definitions to the build file:
-
Ant 1.6 or later:
- Add xmlns:cpptasks="antlib:net.sf.antcontrib.cpptasks" to <project> element.
- Add <cpptasks:cc/>, <cpptasks:compiler/> and <cpptasks:linker/> elements to the project.
-
Ant 1.5 or later:
- Add <taskdef resource="cpptasks.tasks"/> and <typedef resource="cpptasks.types"/> to body of <project> element.
- Add <cc/>, <compiler/> and <linker/> elements to the project.
-
Ant 1.6 or later:
- Set the path and environment variables to be able to run compiler from command line.
- Build the project.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CCTask.ProjectFileCollector
private static class
CCTask.SystemLibraryCollector
-
Field Summary
Fields Modifier and Type Field Description private java.util.Vector
_compilers
The compiler definitions.private java.util.Vector
_libsets
The library sets.private java.util.Vector
_linkers
The linker definitions.private java.io.File
_objDir
The object directory.private java.io.File
_outfile
The output file.private CompilerDef
compilerDef
Content that appears inand also in are maintained by a captive CompilerDef instance private java.lang.String
dataset
The OS390 dataset to build to object toprivate int
dependencyDepth
Depth of dependency checking Values < 0 indicate full dependency checking Values >= 0 indicate partial dependency checking and for superficial compilation checks.private java.util.Vector
distributers
The distributer definitions.private static ProcessorConfiguration[]
EMPTY_CONFIG_ARRAY
protected boolean
failOnError
If true, stop build on compile failure.private LinkerDef
linkerDef
Content that appears inand also in are maintained by a captive CompilerDef instance private LinkType
linkType
contains the subsystem, output type andprivate java.lang.String
outputFileProperty
The property name which will be set with the physical filename of the file that is generated by the linkerprivate java.util.Vector
projects
private boolean
projectsOnly
private boolean
relentless
if relentless = true, compilations should attempt to compile as many files as possible before throwing a BuildExceptionprivate java.util.Vector
targetPlatforms
The linker definitions.private java.util.Vector
versionInfos
-
Constructor Summary
Constructors Constructor Description CCTask()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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
addConfiguredDistributer(DistributerDef distributer)
Adds a distributer definition or reference (Non-functional prototype).void
addConfiguredLinker(LinkerDef linker)
Adds a linker definition.void
addConfiguredLinkerArg(LinkerArgument arg)
Adds a linker command-line arg.void
addConfiguredTarget(TargetDef target)
Adds a target definition or reference (Non-functional prototype).void
addConfiguredVersioninfo(VersionInfo newVersionInfo)
Adds desriptive version information to be included in the generated file.void
addEnv(org.apache.tools.ant.types.Environment.Variable var)
Add an environment variable to the launched process.void
addFileset(ConditionalFileSet srcSet)
Adds a source file set.void
addLibset(LibrarySet libset)
Adds a library set.void
addProject(ProjectDef projectDef)
Specifies the generation of IDE project file.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 filesprotected LinkerConfiguration
collectExplicitObjectFiles(java.util.Vector objectFiles, java.util.Vector sysObjectFiles, VersionInfo versionInfo)
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.boolean
getDebug()
Gets debug state.boolean
getFailonerror()
Gets the failonerror flag.protected TargetHistoryTable
getLinkHistory(TargetHistoryTable objHistory)
protected TargetInfo
getLinkTarget(LinkerConfiguration linkerConfig, java.util.Vector objectFiles, java.util.Vector sysObjectFiles, java.util.Hashtable compileTargets, VersionInfo versionInfo)
java.io.File
getObjdir()
java.io.File
getOutfile()
java.lang.String
getOuttype()
Gets output type.java.lang.String
getSubsystem()
Gets subsystem name.TargetDef
getTargetPlatform()
private java.util.Hashtable
getTargets(LinkerConfiguration linkerConfig, java.util.Vector objectFiles, VersionInfo versionInfo, java.io.File outputFile)
This method collects a Hashtable, keyed by output file name, of TargetInfo's for every source file that is specified in the filesets of theand nested elements. static java.util.Hashtable
getTargetsToBuildByConfiguration(java.util.Hashtable targets)
Builds a Hashtable to targets needing to be rebuilt keyed by compiler configurationvoid
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 codevoid
setFailonerror(boolean fail)
Indicates whether the build will continue even if there are compilation errors; defaults to true.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 codevoid
setName(CompilerEnum name)
Sets type of the default compiler and linker.void
setNewenvironment(boolean newenv)
Do not propagate old environment when new environment variables are specified.void
setObjdir(java.io.File dir)
Sets the destination directory for object files.void
setOptimize(OptimizationEnum optimization)
Sets optimization.void
setOutfile(java.io.File outfile)
Sets the output file name.void
setOutputFileProperty(java.lang.String outputFileProperty)
Specifies the name of a property to set with the physical filename that is produced by the linkervoid
setOuttype(OutputTypeEnum outputType)
Sets the output file type.void
setProject(org.apache.tools.ant.Project project)
Sets the project.void
setProjectsOnly(boolean value)
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
setRtti(boolean rtti)
Enables run-time type information.void
setRuntime(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(WarningLevelEnum level)
Enumerated attribute with the values "none", "severe", "default", "production", "diagnostic", and "aserror".-
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
-
-
-
-
Field Detail
-
EMPTY_CONFIG_ARRAY
private static final ProcessorConfiguration[] EMPTY_CONFIG_ARRAY
-
_compilers
private java.util.Vector _compilers
The compiler definitions.
-
_libsets
private java.util.Vector _libsets
The library sets.
-
_linkers
private java.util.Vector _linkers
The linker definitions.
-
_objDir
private java.io.File _objDir
The object directory.
-
_outfile
private java.io.File _outfile
The output file.
-
targetPlatforms
private final java.util.Vector targetPlatforms
The linker definitions.
-
distributers
private java.util.Vector distributers
The distributer definitions.
-
versionInfos
private final java.util.Vector versionInfos
-
projects
private final java.util.Vector projects
-
projectsOnly
private boolean projectsOnly
-
failOnError
protected boolean failOnError
If true, stop build on compile failure.
-
compilerDef
private final CompilerDef compilerDef
Content that appears inand also in are maintained by a captive CompilerDef instance
-
dataset
private java.lang.String dataset
The OS390 dataset to build to object to
-
dependencyDepth
private int dependencyDepth
Depth of dependency checking Values < 0 indicate full dependency checking Values >= 0 indicate partial dependency checking and for superficial compilation checks. Will throw BuildException before attempting link
-
linkerDef
private final LinkerDef linkerDef
Content that appears inand also in are maintained by a captive CompilerDef instance
-
linkType
private final LinkType linkType
contains the subsystem, output type and
-
outputFileProperty
private java.lang.String outputFileProperty
The property name which will be set with the physical filename of the file that is generated by the linker
-
relentless
private boolean relentless
if relentless = true, compilations should attempt to compile as many files as possible before throwing a BuildException
-
-
Method Detail
-
getTargetsToBuildByConfiguration
public static java.util.Hashtable getTargetsToBuildByConfiguration(java.util.Hashtable targets)
Builds a Hashtable to targets needing to be rebuilt keyed by compiler configuration
-
addConfiguredCompiler
public void addConfiguredCompiler(CompilerDef compiler)
Adds a compiler definition or reference.- Parameters:
compiler
- compiler- Throws:
java.lang.NullPointerException
- if compiler is null
-
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".
-
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
-
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
-
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".
-
addEnv
public void addEnv(org.apache.tools.ant.types.Environment.Variable var)
Add an environment variable to the launched process.
-
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.
-
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.
-
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.
-
addProject
public void addProject(ProjectDef projectDef)
Specifies the generation of IDE project file. Experimental.- Parameters:
projectDef
- project file generation specification
-
setProjectsOnly
public void setProjectsOnly(boolean value)
-
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- Returns:
- total number of targets to be rebuilt
-
collectExplicitObjectFiles
protected LinkerConfiguration collectExplicitObjectFiles(java.util.Vector objectFiles, java.util.Vector sysObjectFiles, VersionInfo versionInfo)
-
createIncludePath
public IncludePath createIncludePath()
Adds an include path. Include paths will be inherited by nested compiler elements that do not have inherit="false".
-
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".- Throws:
org.apache.tools.ant.BuildException
-
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".
-
execute
public void execute() throws org.apache.tools.ant.BuildException
Executes the task. Compiles the given files.- Overrides:
execute
in classorg.apache.tools.ant.Task
- Throws:
org.apache.tools.ant.BuildException
- if someting goes wrong with the build
-
getDataset
public java.lang.String getDataset()
Gets the dataset.- Returns:
- Returns a String
-
getLinkHistory
protected TargetHistoryTable getLinkHistory(TargetHistoryTable objHistory)
-
getLinkTarget
protected TargetInfo getLinkTarget(LinkerConfiguration linkerConfig, java.util.Vector objectFiles, java.util.Vector sysObjectFiles, java.util.Hashtable compileTargets, VersionInfo versionInfo)
-
getObjdir
public java.io.File getObjdir()
-
getOutfile
public java.io.File getOutfile()
-
getTargetPlatform
public TargetDef getTargetPlatform()
-
getTargets
private java.util.Hashtable getTargets(LinkerConfiguration linkerConfig, java.util.Vector objectFiles, VersionInfo versionInfo, java.io.File outputFile)
This method collects a Hashtable, keyed by output file name, of TargetInfo's for every source file that is specified in the filesets of theand nested elements. The TargetInfo's contain the appropriate compiler configurations for their possible compilation
-
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
-
setDataset
public void setDataset(java.lang.String dataset)
Sets the dataset for OS/390 builds.- Parameters:
dataset
- The dataset to set
-
setDebug
public void setDebug(boolean debug)
Enables or disables generation of debug info.
-
getDebug
public boolean getDebug()
Gets debug state.- Returns:
- true if building for debugging
-
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.
-
setExceptions
public void setExceptions(boolean exceptions)
Enables generation of exception handling code
-
setRtti
public void setRtti(boolean rtti)
Enables run-time type information.
-
setIncremental
public void setIncremental(boolean incremental)
Enables or disables incremental linking.- Parameters:
incremental
- new state
-
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.
-
setLink
public void setLink(OutputTypeEnum outputType)
Deprecated.Sets the output file type. Supported values "executable", "shared", and "static". Deprecated, specify outtype instead.
-
setMultithreaded
public void setMultithreaded(boolean multi)
Enables or disables generation of multithreaded code- Parameters:
multi
- If true, generated code may be multithreaded.
-
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 g77 GNU FORTRAN compiler msvc Microsoft Visual C++ bcc Borland C++ Compiler msrc Microsoft Resource Compiler brc Borland Resource Compiler df Compaq Visual Fortran Compiler midl Microsoft MIDL Compiler icl Intel C++ compiler for Windows (IA-32) ecl Intel C++ compiler for Windows (IA-64) icc Intel C++ compiler for Linux (IA-32) ecc Intel C++ compiler for Linux (IA-64) CC Sun ONE C++ compiler aCC HP aC++ C++ Compiler os390 OS390 C Compiler os400 Icc Compiler sunc89 Sun C89 C Compiler xlC VisualAge C Compiler uic Qt user interface compiler (creates .h, .cpp and moc_*.cpp files). moc Qt meta-object compiler xpidl Mozilla xpidl compiler (creates .h and .xpt files). wcl OpenWatcom C/C++ compiler wfl OpenWatcom FORTRAN compiler
-
setNewenvironment
public void setNewenvironment(boolean newenv)
Do not propagate old environment when new environment variables are specified.
-
setObjdir
public void setObjdir(java.io.File dir)
Sets the destination directory for object files. Generally this should be a property expression that evaluates to distinct debug and release object file directories.- Parameters:
dir
- object directory
-
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
-
setOutputFileProperty
public void setOutputFileProperty(java.lang.String outputFileProperty)
Specifies the name of a property to set with the physical filename that is produced by the linker
-
setOuttype
public void setOuttype(OutputTypeEnum outputType)
Sets the output file type. Supported values "executable", "shared", and "static".
-
getOuttype
public java.lang.String getOuttype()
Gets output type.- Returns:
- output type
-
setProject
public void setProject(org.apache.tools.ant.Project project)
Sets the project.- Overrides:
setProject
in classorg.apache.tools.ant.ProjectComponent
-
setRebuild
public void setRebuild(boolean rebuildAll)
If set to true, all files will be rebuilt.- Parameters:
rebuildAll
- If true, all files will be rebuilt. If false, up to date files will not be rebuilt.
-
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
-
setRuntime
public void setRuntime(RuntimeType rtlType)
Sets the type of runtime library, possible values "dynamic", "static".
-
setSubsystem
public void setSubsystem(SubsystemEnum subsystem)
Sets the nature of the subsystem under which that the program will execute.Supported subsystems
gui Graphical User Interface console Command Line Console other Other - Parameters:
subsystem
- subsystem- Throws:
java.lang.NullPointerException
- if subsystem is null
-
getSubsystem
public java.lang.String getSubsystem()
Gets subsystem name.- Returns:
- Subsystem name
-
setWarnings
public void setWarnings(WarningLevelEnum level)
Enumerated attribute with the values "none", "severe", "default", "production", "diagnostic", and "aserror".
-
setFailonerror
public void setFailonerror(boolean fail)
Indicates whether the build will continue even if there are compilation errors; defaults to true.- Parameters:
fail
- if true halt the build on failure
-
getFailonerror
public boolean getFailonerror()
Gets the failonerror flag.- Returns:
- the failonerror flag
-
addConfiguredTarget
public void addConfiguredTarget(TargetDef target)
Adds a target definition or reference (Non-functional prototype).- Parameters:
target
- target- Throws:
java.lang.NullPointerException
- if compiler is null
-
addConfiguredDistributer
public void addConfiguredDistributer(DistributerDef distributer)
Adds a distributer definition or reference (Non-functional prototype).- Parameters:
distributer
- distributer- Throws:
java.lang.NullPointerException
- if compiler is null
-
setOptimize
public void setOptimize(OptimizationEnum optimization)
Sets optimization.- Parameters:
optimization
-
-
addConfiguredVersioninfo
public void addConfiguredVersioninfo(VersionInfo newVersionInfo)
Adds desriptive version information to be included in the generated file. The first active version info block will be used.
-
-