From: Curt A. <ca...@us...> - 2004-09-25 06:10:43
|
Update of /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30012/src/net/sf/antcontrib/cpptasks/borland Modified Files: CBuilderXProjectWriter.java Log Message: Bug 980130: Improvements to Visual Studio 97/6 project generation Index: CBuilderXProjectWriter.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CBuilderXProjectWriter.java 29 Aug 2004 04:25:39 -0000 1.4 --- CBuilderXProjectWriter.java 25 Sep 2004 06:10:32 -0000 1.5 *************** *** 34,37 **** --- 34,38 ---- import net.sf.antcontrib.cpptasks.ide.ProjectWriter; + import org.apache.tools.ant.BuildException; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.Serializer; *************** *** 76,84 **** IOException, SAXException { ! OutputStream outStream = new FileOutputStream(fileName + ".cbx"); OutputFormat format = new OutputFormat("xml", "UTF-8", true); Serializer serializer = new XMLSerializer(outStream, format); ContentHandler content = serializer.asContentHandler(); - String basePath = fileName.getParentFile().getAbsolutePath(); content.startDocument(); AttributesImpl emptyAttrs = new AttributesImpl(); --- 77,104 ---- IOException, SAXException { ! ! String projectName = projectDef.getName(); ! if (projectName == null) { ! projectName = fileName.getName(); ! } ! final String basePath = fileName.getAbsoluteFile().getParent(); ! ! File projectFile = new File(fileName + ".cbx"); ! if (!projectDef.getOverwrite() && projectFile.exists()) { ! throw new BuildException("Not allowed to overwrite project file " ! + projectFile.toString()); ! } ! ! CommandLineCompilerConfiguration compilerConfig = ! getBaseCompilerConfiguration(targets); ! if (compilerConfig == null) { ! throw new BuildException( ! "Unable to generate C++ BuilderX project when gcc is not used."); ! } ! ! OutputStream outStream = new FileOutputStream(projectFile); OutputFormat format = new OutputFormat("xml", "UTF-8", true); Serializer serializer = new XMLSerializer(outStream, format); ContentHandler content = serializer.asContentHandler(); content.startDocument(); AttributesImpl emptyAttrs = new AttributesImpl(); *************** *** 133,138 **** // assume the first target is representative of all compilation tasks // ! CommandLineCompilerConfiguration compilerConfig = ! writeCompileOptions(basePath, propertyWriter, targets); writeLinkOptions(basePath, propertyWriter, linkTarget); propertyWriter.write("linux.gnuc++.Debug_Build", "saved", "1"); --- 153,157 ---- // assume the first target is representative of all compilation tasks // ! writeCompileOptions(basePath, propertyWriter, compilerConfig); writeLinkOptions(basePath, propertyWriter, linkTarget); propertyWriter.write("linux.gnuc++.Debug_Build", "saved", "1"); *************** *** 151,156 **** } else if ("exeproject".equals(buildType)) { propertyWriter.write("runtime.0", "BuildTargetOnRun", ! "com.borland.cbuilder.build." ! + "CBProjectBuilder$ProjectBuildAction;make"); propertyWriter.write("runtime.0", "ConfigurationName", projectDef.getName()); --- 170,175 ---- } else if ("exeproject".equals(buildType)) { propertyWriter.write("runtime.0", "BuildTargetOnRun", ! "com.borland.cbuilder.build." ! + "CBProjectBuilder$ProjectBuildAction;make"); propertyWriter.write("runtime.0", "ConfigurationName", projectDef.getName()); *************** *** 277,294 **** /** ! * Writes elements corresponding to compilation options. ! * ! * @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 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 --- 296,310 ---- /** ! * Gets the first recognized compiler from the ! * compilation targets. ! * @param targets compilation targets ! * @return representative (hopefully) compiler configuration */ private CommandLineCompilerConfiguration ! getBaseCompilerConfiguration(final Hashtable targets) { ! // ! // find first target with an DevStudio C compilation ! // CommandLineCompilerConfiguration compilerConfig = null; // // get the first target and assume that it is representative *************** *** 300,367 **** String identifier = config.getIdentifier(); // ! // if it even kind of looks like a gcc/g++ etc // if (config instanceof CommandLineCompilerConfiguration) { compilerConfig = (CommandLineCompilerConfiguration) config; if (compilerConfig.getCompiler() instanceof GccCCompiler) { ! File[] includePath = compilerConfig.getIncludePath(); ! int includeIndex = 1; ! writer.write(gnuCompile, ! "option.I.arg." + (includeIndex++), ! "/usr/include"); ! writer.write(gnuCompile, ! "option.I.arg." + (includeIndex++), ! "/usr/include/g++-3"); ! for (int i = 0; i < includePath.length; i++) { ! writer.write(gnuCompile, ! "option.I.arg." + (includeIndex++), ! CUtil.getRelativePath(baseDir, includePath[i])); ! } ! if (includePath.length > 0) { ! writer.write(gnuCompile, ! "option.I.enabled", ! "1"); ! } ! int defineIndex = 1; ! int undefineIndex = 1; ! String[] preArgs = compilerConfig.getPreArguments(); ! for (int i = 0; i < preArgs.length; i++) { ! if (preArgs[i].startsWith("-D")) { ! writer.write(gnuCompile, ! "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) { ! writer.write(gnuCompile, ! "option.D_MACRO_VALUE.enabled", ! "1"); ! } ! if (undefineIndex > 1) { ! writer.write(gnuCompile, ! "option.U.enabled", ! "1"); ! } ! break; ! } } } ! return compilerConfig; } --- 316,399 ---- String identifier = config.getIdentifier(); // ! // for the first cl compiler // if (config instanceof CommandLineCompilerConfiguration) { compilerConfig = (CommandLineCompilerConfiguration) config; if (compilerConfig.getCompiler() instanceof GccCCompiler) { ! return compilerConfig; ! } ! } ! } ! return null; ! } ! /** ! * Writes elements corresponding to compilation options. ! * ! * @param baseDir String base directory ! * @param writer PropertyWriter property writer ! * @param compilerConfig representative configuration ! * @throws SAXException if I/O error or illegal content ! */ ! private void writeCompileOptions(final String baseDir, ! final PropertyWriter writer, ! final CommandLineCompilerConfiguration ! compilerConfig) throws SAXException { ! String gnuCompile = "linux.Debug_Build.gnuc++.g++compile"; ! File[] includePath = compilerConfig.getIncludePath(); ! int includeIndex = 1; ! writer.write(gnuCompile, ! "option.I.arg." + (includeIndex++), ! "/usr/include"); ! writer.write(gnuCompile, ! "option.I.arg." + (includeIndex++), ! "/usr/include/g++-3"); ! for (int i = 0; i < includePath.length; i++) { ! writer.write(gnuCompile, ! "option.I.arg." + (includeIndex++), ! CUtil.getRelativePath(baseDir, includePath[i])); ! } ! if (includePath.length > 0) { ! writer.write(gnuCompile, ! "option.I.enabled", ! "1"); ! } ! ! int defineIndex = 1; ! int undefineIndex = 1; ! String[] preArgs = compilerConfig.getPreArguments(); ! for (int i = 0; i < preArgs.length; i++) { ! if (preArgs[i].startsWith("-D")) { ! writer.write(gnuCompile, ! "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) { ! writer.write(gnuCompile, ! "option.D_MACRO_VALUE.enabled", ! "1"); ! } ! if (undefineIndex > 1) { ! writer.write(gnuCompile, ! "option.U.enabled", ! "1"); ! } } *************** *** 378,392 **** final PropertyWriter writer, final TargetInfo linkTarget) throws SAXException { ! if (linkTarget != null) { ! ProcessorConfiguration config = linkTarget.getConfiguration(); ! if (config instanceof CommandLineLinkerConfiguration) { ! CommandLineLinkerConfiguration linkConfig = ! (CommandLineLinkerConfiguration) config; ! String gnuLink = "linux.Debug_Build.gnuc++.g++link"; ! writeLinkArgs(writer, gnuLink, linkConfig.getPreArguments()); ! writeLinkArgs(writer, gnuLink, linkConfig.getEndArguments()); ! } } } --- 410,424 ---- final PropertyWriter writer, final TargetInfo linkTarget) throws SAXException { ! if (linkTarget != null) { ! ProcessorConfiguration config = linkTarget.getConfiguration(); ! if (config instanceof CommandLineLinkerConfiguration) { ! CommandLineLinkerConfiguration linkConfig = ! (CommandLineLinkerConfiguration) config; ! String gnuLink = "linux.Debug_Build.gnuc++.g++link"; ! writeLinkArgs(writer, gnuLink, linkConfig.getPreArguments()); ! writeLinkArgs(writer, gnuLink, linkConfig.getEndArguments()); ! } } } |