3 * Copyright 2002-2004 The Ant-Contrib project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package net
.sf
.antcontrib
.cpptasks
.devstudio
;
19 import java
.util
.Vector
;
20 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
21 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineCompilerConfiguration
;
22 import net
.sf
.antcontrib
.cpptasks
.compiler
.CompilerConfiguration
;
23 import net
.sf
.antcontrib
.cpptasks
.compiler
.LinkType
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.PrecompilingCommandLineCCompiler
;
25 import org
.apache
.tools
.ant
.BuildException
;
26 import org
.apache
.tools
.ant
.types
.Environment
;
27 import net
.sf
.antcontrib
.cpptasks
.OptimizationEnum
;
30 * An abstract base class for compilers that are basically command line
31 * compatible with Microsoft(r) C/C++ Optimizing Compiler
35 public abstract class DevStudioCompatibleCCompiler
37 PrecompilingCommandLineCCompiler
{
38 private static String
[] mflags
= new String
[]{
40 // first four are single-threaded
41 // (runtime=static,debug=false), (..,debug=true),
42 // (runtime=dynamic,debug=true), (..,debug=false), (not supported)
43 // next four are multi-threaded, same sequence
44 "/ML", "/MLd", null, null, "/MT", "/MTd", "/MD", "/MDd"};
45 private static String
[] defaultflags
= new String
[]{"/nologo", "/c"};
46 protected DevStudioCompatibleCCompiler(String command
,
47 String identifierArg
, boolean newEnvironment
, Environment env
) {
48 super(command
, identifierArg
, new String
[]{".c", ".cc", ".cpp", ".cxx",
49 ".c++"}, new String
[]{".h", ".hpp", ".inl"}, ".obj", false,
50 null, newEnvironment
, env
);
52 protected void addImpliedArgs(final Vector args
,
54 final boolean multithreaded
,
55 final boolean exceptions
,
56 final LinkType linkType
,
58 final OptimizationEnum optimization
,
59 final Boolean defaultflag
) {
60 if (defaultflag
!= null && defaultflag
.booleanValue()) {
61 for (int i
= 0; i
< defaultflags
.length
; i
++) {
62 args
.addElement(defaultflags
[i
]);
66 args
.addElement("/GX");
72 boolean staticRuntime
= linkType
.isStaticRuntime();
78 args
.addElement("/Zi");
79 args
.addElement("/Od");
80 args
.addElement("/GZ");
81 args
.addElement("/D_DEBUG");
83 if (optimization
!= null) {
84 if (optimization
.isSize()) {
85 args
.addElement("/O1");
87 if (optimization
.isSpeed()) {
88 args
.addElement("/O2");
91 args
.addElement("/DNDEBUG");
93 String mflag
= mflags
[mindex
];
95 throw new BuildException(
96 "multithread='false' and runtime='dynamic' not supported");
98 args
.addElement(mflag
);
99 if (rtti
!= null && rtti
.booleanValue()) {
100 args
.addElement("/GR");
103 protected void addWarningSwitch(Vector args
, int level
) {
104 DevStudioProcessor
.addWarningSwitch(args
, level
);
106 protected CompilerConfiguration
createPrecompileGeneratingConfig(
107 CommandLineCompilerConfiguration baseConfig
, File prototype
,
108 String lastInclude
) {
109 String
[] additionalArgs
= new String
[]{
110 "/Fp" + CUtil
.getBasename(prototype
) + ".pch", "/Yc"};
111 return new CommandLineCompilerConfiguration(baseConfig
, additionalArgs
,
114 protected CompilerConfiguration
createPrecompileUsingConfig(
115 CommandLineCompilerConfiguration baseConfig
, File prototype
,
116 String lastInclude
, String
[] exceptFiles
) {
117 String
[] additionalArgs
= new String
[]{
118 "/Fp" + CUtil
.getBasename(prototype
) + ".pch",
119 "/Yu" + lastInclude
};
120 return new CommandLineCompilerConfiguration(baseConfig
, additionalArgs
,
123 protected void getDefineSwitch(StringBuffer buffer
, String define
,
125 DevStudioProcessor
.getDefineSwitch(buffer
, define
, value
);
127 protected File
[] getEnvironmentIncludePath() {
128 return CUtil
.getPathFromEnvironment("INCLUDE", ";");
130 protected String
getIncludeDirSwitch(String includeDir
) {
131 return DevStudioProcessor
.getIncludeDirSwitch(includeDir
);
133 protected void getUndefineSwitch(StringBuffer buffer
, String define
) {
134 DevStudioProcessor
.getUndefineSwitch(buffer
, define
);