Index: samples/cppunit.ant =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/samples/cppunit.ant,v retrieving revision 1.9 diff -u -r1.9 cppunit.ant --- samples/cppunit.ant 13 Jul 2004 04:30:31 -0000 1.9 +++ samples/cppunit.ant 24 Aug 2004 23:39:26 -0000 @@ -50,19 +50,19 @@ - - + - + @@ -70,9 +70,9 @@ - - @@ -95,8 +95,8 @@ - @@ -104,8 +104,8 @@ - @@ -150,10 +150,10 @@ - - @@ -172,8 +172,8 @@ - - + + @@ -185,10 +185,10 @@ - - + + - + outputfileproperty="test-static.exe"> + - - + + + + + + + + + + + + + + + + + + - - + - - + + + + + - - + - - @@ -335,16 +373,16 @@ - - @@ -363,19 +401,19 @@ - - + - @@ -387,24 +425,24 @@ - - - + - @@ -417,29 +455,29 @@ - - - - + - - - @@ -470,10 +508,10 @@ name="midl"> - - @@ -513,9 +551,9 @@ - + - - \ No newline at end of file + + Index: src/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java,v retrieving revision 1.2 diff -u -r1.2 CBuilderXProjectWriter.java --- src/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java 8 Jul 2004 22:27:51 -0000 1.2 +++ src/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java 24 Aug 2004 23:39:26 -0000 @@ -27,6 +27,7 @@ import net.sf.antcontrib.cpptasks.CUtil; import net.sf.antcontrib.cpptasks.TargetInfo; import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration; +import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration; import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration; import net.sf.antcontrib.cpptasks.gcc.GccCCompiler; import net.sf.antcontrib.cpptasks.ide.ProjectDef; @@ -100,7 +101,8 @@ "default;debug"); propertyWriter.write("build.config.0", "type", "Toolset"); propertyWriter.write("build.node", "name", projectDef.getName()); - propertyWriter.write("build.node", "type", getBuildType(linkTarget)); + final String buildType = getBuildType(task); + propertyWriter.write("build.node", "type", buildType); propertyWriter.write("build.platform", "active", getActivePlatform(task)); propertyWriter.write("build.platform", "linux.Debug_Build.toolset", @@ -109,41 +111,72 @@ "gnuc++"); propertyWriter.write("build.platform", "linux.default", "gnuc++"); propertyWriter.write("build.platform", "linux.gnuc++.enabled", "1"); - propertyWriter.write("build.platform", "linux.mswin32.enabled", "0"); - propertyWriter.write("build.platform", "linux.win32b.enabled", "0"); + propertyWriter.write("build.platform", "linux.mswin32.enabled", "1"); + propertyWriter.write("build.platform", "linux.win32b.enabled", "1"); propertyWriter.write("build.platform", "solaris.default", "gnuc++"); propertyWriter.write("build.platform", "solaris.enabled", "1"); propertyWriter.write("build.platform", "win32.default", "MinGW"); propertyWriter.write("build.platform", "win32.enabled", "1"); //propertyWriter.write("cbproject", "lastnodeid", "852"); + propertyWriter.write("cbproject", "version", "X.1.0"); - propertyWriter.write("gnuc++.g++compile", - "option.fpic_using_GOT.enabled", "1"); - propertyWriter.write("gnuc++.g++link", "option.shared.enabled", "1"); - propertyWriter.write("intellinia32.icc", "option.minus_Kpic.enabled", - "1"); - propertyWriter.write("intellinia32.icclink", - "option.minus_shared.enabled", "1"); + if ("dllproject".equals(buildType)) { + propertyWriter.write("gnuc++.g++compile", + "option.fpic_using_GOT.enabled", "1"); + propertyWriter.write("gnuc++.g++link", "option.shared.enabled", "1"); + propertyWriter.write("intellinia32.icc", "option.minus_Kpic.enabled", + "1"); + propertyWriter.write("intellinia32.icclink", + "option.minus_shared.enabled", "1"); + } // // assume the first target is representative of all compilation tasks // - writeCompileOptions(basePath, propertyWriter, targets); - propertyWriter.write("linux.Debug_Build.gnuc++.g++link", - "option.o.enabled", "1"); + CommandLineCompilerConfiguration compilerConfig = + writeCompileOptions(basePath, propertyWriter, targets); + writeLinkOptions(basePath, propertyWriter, linkTarget); propertyWriter.write("linux.gnuc++.Debug_Build", "saved", "1"); - propertyWriter.write("runtime", "ExcludeDefaultForZero", "1"); - //propertyWriter.write("unique", "id", "852"); - propertyWriter.write("win32b.bcc32", "option.tWD.enabled", "1"); - propertyWriter.write("win32b.bcc32", "option.tWM.enabled", "1"); - propertyWriter.write("win32b.bcc32", "option.tWR.enabled", "1"); - propertyWriter.write("win32b.ilink32", "option.Gi.enabled", "1"); - propertyWriter.write("win32b.ilink32", "option.Tpd.enabled", "1"); - propertyWriter.write("win32b.ilink32", "option.Tpe.enabled", "0"); - propertyWriter.write("win32b.ilink32", "option.aa.enabled", "1"); - propertyWriter.write("win32b.ilink32", "param.objfiles.1", "c0d32.obj"); - propertyWriter.write("win32b.implib", "enabled", "0"); + if ("dllproject".equals(buildType)) { + propertyWriter.write("runtime", "ExcludeDefaultForZero", "1"); + //propertyWriter.write("unique", "id", "852"); + propertyWriter.write("win32b.bcc32", "option.tWD.enabled", "1"); + propertyWriter.write("win32b.bcc32", "option.tWM.enabled", "1"); + propertyWriter.write("win32b.bcc32", "option.tWR.enabled", "1"); + propertyWriter.write("win32b.ilink32", "option.Gi.enabled", "1"); + propertyWriter.write("win32b.ilink32", "option.Tpd.enabled", "1"); + propertyWriter.write("win32b.ilink32", "option.Tpe.enabled", "0"); + propertyWriter.write("win32b.ilink32", "option.aa.enabled", "1"); + propertyWriter.write("win32b.ilink32", "param.objfiles.1", "c0d32.obj"); + propertyWriter.write("win32b.implib", "enabled", "0"); + } else if ("exeproject".equals(buildType)) { + propertyWriter.write("runtime.0", "BuildTargetOnRun", + "com.borland.cbuilder.build." + + "CBProjectBuilder$ProjectBuildAction;make"); + propertyWriter.write("runtime.0", "ConfigurationName", + projectDef.getName()); + propertyWriter.write("runtime.0", "RunnableType", + "com.borland.cbuilder.runtime.ExecutableRunner"); + propertyWriter.write("win32b.bcc32", "option.tWC.enabled", "1"); + propertyWriter.write("win32b.ilink32", "option.Tpd.enabled", "0"); + propertyWriter.write("win32b.ilink32", "option.Tpe.enabled", "1"); + propertyWriter.write("win32b.ilink32", "option.aa.enabled", "0"); + propertyWriter.write("win32b.ilink32", "option.ap.enabled", "1"); + propertyWriter.write("win32b.ilink32", "param.objfiles.1", "c0x32.obj"); + propertyWriter.write("win32b.implib", "enabled", "0"); + } AttributesImpl fileAttributes = new AttributesImpl(); fileAttributes.addAttribute(null, "path", "path", "#PCDATA", ""); + AttributesImpl gccAttributes = null; + if (!"g++".equals(compilerConfig.getCommand())) { + gccAttributes = new AttributesImpl(); + gccAttributes.addAttribute(null, "category", "category", "#PCDATA", + "build.basecmd"); + gccAttributes.addAttribute(null, "name", "name", "#PCDATA", + "linux.gnuc++.Debug_Build.g++_key"); + gccAttributes.addAttribute(null, "value", "value", "#PCDATA", + compilerConfig.getCommand()); + } + Iterator targetIter = targets.values().iterator(); while (targetIter.hasNext()) { TargetInfo info = (TargetInfo) targetIter.next(); @@ -153,6 +186,14 @@ sources[i]); fileAttributes.setValue(0, relativePath); content.startElement(null, "file", "file", fileAttributes); + + // + // if file ends with .c, use gcc instead of g++ + // + if (gccAttributes != null) { + content.startElement(null, "property", "property", gccAttributes); + content.endElement(null, "property", "property"); + } content.endElement(null, "file", "file"); } } @@ -162,10 +203,16 @@ /** * Gets build type from link target. - * @param linkTarget TargetInfo link target + * @param task CCTask current task * @return String build type */ - private String getBuildType(final TargetInfo linkTarget) { + private String getBuildType(final CCTask task) { + String outType = task.getOuttype(); + if ("executable".equals(outType)) { + return "exeproject"; + } else if ("static".equals(outType)) { + return "libraryproject"; + } return "dllproject"; } @@ -217,8 +264,8 @@ * @throws SAXException if I/O error or illegal content */ public final void write(final String category, - final String name, - final String value) throws SAXException { + final String name, + final String value) throws SAXException { propertyAttributes.setValue(0, category); propertyAttributes.setValue(1, name); propertyAttributes.setValue(2, value); @@ -234,12 +281,14 @@ * @param baseDir String base directory * @param writer PropertyWriter property writer * @param targets Hashtable compile targets + * @return representative configuration * @throws SAXException if I/O error or illegal content */ - private void writeCompileOptions(final String baseDir, - final PropertyWriter writer, - final Hashtable targets) - throws SAXException { + private CommandLineCompilerConfiguration + writeCompileOptions(final String baseDir, + final PropertyWriter writer, + final Hashtable targets) throws SAXException { + CommandLineCompilerConfiguration compilerConfig = null; String gnuCompile = "linux.Debug_Build.gnuc++.g++compile"; // // get the first target and assume that it is representative @@ -253,8 +302,7 @@ // if it even kind of looks like a gcc/g++ etc // if (config instanceof CommandLineCompilerConfiguration) { - CommandLineCompilerConfiguration compilerConfig = ( - CommandLineCompilerConfiguration) config; + compilerConfig = (CommandLineCompilerConfiguration) config; if (compilerConfig.getCompiler() instanceof GccCCompiler) { File[] includePath = compilerConfig.getIncludePath(); int includeIndex = 1; @@ -276,6 +324,7 @@ } int defineIndex = 1; + int undefineIndex = 1; String[] preArgs = compilerConfig.getPreArguments(); for (int i = 0; i < preArgs.length; i++) { if (preArgs[i].startsWith("-D")) { @@ -283,6 +332,20 @@ "option.D_MACRO_VALUE.arg." + (defineIndex++), preArgs[i] .substring(2)); + } else if (preArgs[i].startsWith("-U")) { + writer.write(gnuCompile, + "option.U.arg." + + (undefineIndex++), preArgs[i] + .substring(2)); + + } else if (!(preArgs[i].startsWith("-I") + || preArgs[i].startsWith("-o"))) { + // + // any others (-g, -fno-rtti, -w, -Wall, etc) + // + writer.write(gnuCompile, + "option." + preArgs[i].substring(1) + ".enabled", + "1"); } } if (defineIndex > 1) { @@ -290,10 +353,96 @@ "option.D_MACRO_VALUE.enabled", "1"); } + if (undefineIndex > 1) { + writer.write(gnuCompile, + "option.U.enabled", + "1"); + } break; } } } - writer.write(gnuCompile, "option.c.enabled", "1"); + return compilerConfig; + } + + /** + * Writes elements corresponding to link options. + * + * @param baseDir String base directory + * @param writer PropertyWriter property writer + * @param linkTarget TargetInfo link target + * @throws SAXException if I/O error or illegal content + */ + private void + writeLinkOptions(final String baseDir, + final PropertyWriter writer, + final TargetInfo linkTarget) throws SAXException { + ProcessorConfiguration config = linkTarget.getConfiguration(); + if (config instanceof CommandLineLinkerConfiguration) { + CommandLineLinkerConfiguration linkConfig = + (CommandLineLinkerConfiguration) config; + + String gnuLink = "linux.Debug_Build.gnuc++.g++link"; + String identifier = config.getIdentifier(); + + writeLinkArgs(writer, gnuLink, linkConfig.getPreArguments()); + writeLinkArgs(writer, gnuLink, linkConfig.getEndArguments()); + } + } + + /** + * Writes linker options to project file. + * + * @param writer PropertyWriter property writer + * @param gnuLink String linker identifier + * @param preArgs String[] linker arguments + * @throws SAXException thrown if unable to write option + */ + private void writeLinkArgs(final PropertyWriter writer, + final String gnuLink, + final String[] preArgs) throws SAXException { + int objnameIndex = 1; + int libnameIndex = 1; + int libpathIndex = 1; + for (int i = 0; i < preArgs.length; i++) { + if (preArgs[i].startsWith("-o")) { + writer.write(gnuLink, + "option.o.arg." + + (objnameIndex++), preArgs[i] + .substring(2)); + } else if (preArgs[i].startsWith("-l")) { + writer.write(gnuLink, + "option.l.arg." + + (libnameIndex++), preArgs[i] + .substring(2)); + } else if (preArgs[i].startsWith("-L")) { + writer.write(gnuLink, + "option.L.arg." + + (libpathIndex++), preArgs[i] + .substring(2)); + } else { + // + // any others + // + writer.write(gnuLink, "option." + preArgs[i].substring(1) + ".enabled", + "1"); + } + } + if (objnameIndex > 1) { + writer.write(gnuLink, + "option.o.enabled", + "1"); + } + if (libnameIndex > 1) { + writer.write(gnuLink, + "option.l.enabled", + "1"); + } + if (libpathIndex > 1) { + writer.write(gnuLink, + "option.L.enabled", + "1"); + } } + } Index: src/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java,v retrieving revision 1.19 diff -u -r1.19 CommandLineCompilerConfiguration.java --- src/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java 26 Jun 2004 03:45:18 -0000 1.19 +++ src/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java 24 Aug 2004 23:39:26 -0000 @@ -220,4 +220,7 @@ public Compiler getCompiler() { return compiler; } + public String getCommand() { + return compiler.getCommand(); + } }