Index: src/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java,v retrieving revision 1.3 diff -u -r1.3 DevStudioProjectWriter.java --- src/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java 13 Jul 2004 04:08:37 -0000 1.3 +++ src/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java 25 Aug 2004 21:20:30 -0000 @@ -30,6 +30,9 @@ import net.sf.antcontrib.cpptasks.CCTask; 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.ide.ProjectDef; import net.sf.antcontrib.cpptasks.ide.ProjectWriter; @@ -164,10 +167,7 @@ writer.write(objDirPath); writer.write("\"\r\n"); writer.write("# PROP Target_Dir \"\"\r\n"); - String cmd = "CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D \"WIN32\" " - + "/D \"_DEBUG\" /D \"_WINDOWS\" /YX /FD /c\r\n"; - writer.write("# ADD BASE " + cmd); - writer.write("# ADD " + cmd); + writeCompileOptions(writer, basePath, targets); writer.write( "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /o NUL /win32\r\n"); writer.write( @@ -178,16 +178,7 @@ writer.write("# ADD BASE BSC32 /nologo\r\n"); writer.write("# ADD BSC32 /nologo\r\n"); writer.write("LINK32=link.exe\r\n"); - writer.write("# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib " - + "winspool.lib comdlg32.lib advapi32.lib shell32.lib " - + "ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib " - + "/nologo /subsystem:windows /dll /debug " - + "/machine:I386 /pdbtype:sept\r\n"); - writer.write("# ADD LINK32 kernel32.lib user32.lib gdi32.lib " - + "winspool.lib comdlg32.lib advapi32.lib shell32.lib " - + "ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib " - + "/nologo /subsystem:windows /dll /debug " - + "/machine:I386 /pdbtype:sept\r\n"); + writeLinkOptions(writer, basePath, linkTarget, targets); writer.write("# Begin Target\r\n\r\n"); writer.write("# Name \""); writer.write(configName); @@ -243,8 +234,7 @@ private void writeMessage(final Writer writer, final String projectName, final String configName, - final String targtype) - throws IOException { + final String targtype) throws IOException { writer.write( "!MESSAGE This is not a valid makefile. "); writer.write("To build this project using NMAKE,\r\n"); @@ -278,4 +268,134 @@ writer.write("\r\n"); } + + /** + * Writes compiler options. + * @param writer Writer writer + * @param baseDir String base directory + * @param targets Hashtable compilation targets + * @throws IOException if error on writing project + * @return CommandLineCompilerConfiguration compiler configuration + */ + private CommandLineCompilerConfiguration + writeCompileOptions(final Writer writer, + final String baseDir, final Hashtable targets) + throws IOException { + // + // find first target with an DevStudio C compilation + // + CommandLineCompilerConfiguration compilerConfig = null; + // + // get the first target and assume that it is representative + // + Iterator targetIter = targets.values().iterator(); + while (targetIter.hasNext()) { + TargetInfo targetInfo = (TargetInfo) targetIter.next(); + ProcessorConfiguration config = targetInfo.getConfiguration(); + String identifier = config.getIdentifier(); + // + // for the first cl compiler + // + if (config instanceof CommandLineCompilerConfiguration) { + compilerConfig = (CommandLineCompilerConfiguration) config; + if (compilerConfig.getCompiler() instanceof DevStudioCCompiler) { + StringBuffer baseOptions = new StringBuffer(50); + baseOptions.append("# ADD BASE CPP"); + StringBuffer options = new StringBuffer(50); + options.append("# ADD CPP"); + File[] includePath = compilerConfig.getIncludePath(); + for (int i = 0; i < includePath.length; i++) { + options.append(" /I \""); + String relPath = CUtil.getRelativePath(baseDir, includePath[i]); + options.append(relPath); + options.append('"'); + } + + String[] preArgs = compilerConfig.getPreArguments(); + for (int i = 0; i < preArgs.length; i++) { + if (preArgs[i].startsWith("/D")) { + options.append(" /D "); + baseOptions.append(" /D "); + String body = preArgs[i].substring(2); + if (preArgs[i].indexOf('=') >= 0) { + options.append(body); + baseOptions.append(body); + } else { + options.append('"'); + options.append(body); + options.append('"'); + } + } else if (!preArgs[i].startsWith("/I")) { + options.append(" "); + options.append(preArgs[i]); + baseOptions.append(" "); + baseOptions.append(preArgs[i]); + } + } + baseOptions.append("\r\n"); + options.append("\r\n"); + writer.write(baseOptions.toString()); + writer.write(options.toString()); + break; + } + } + } + return compilerConfig; + + } + + /** + * Writes link options. + * @param writer Writer writer + * @param basePath String base path + * @param linkTarget TargetInfo link target + * @param targets Hashtable all targets + * @throws IOException if unable to write to project file + */ + private void writeLinkOptions(final Writer writer, + final String basePath, + final TargetInfo linkTarget, + final Hashtable targets) + throws IOException { + + StringBuffer baseOptions = new StringBuffer(100); + StringBuffer options = new StringBuffer(100); + baseOptions.append("# ADD BASE LINK32"); + options.append("# ADD LINK32"); + + ProcessorConfiguration config = linkTarget.getConfiguration(); + if (config instanceof CommandLineLinkerConfiguration) { + CommandLineLinkerConfiguration linkConfig = + (CommandLineLinkerConfiguration) config; + + File[] linkSources = linkTarget.getAllSources(); + for (int i = 0; i < linkSources.length; i++) { + // + // if file was not compiled or otherwise generated + // + if (targets.get(linkSources[i].getName()) == null) { + options.append(' '); + options.append(CUtil.getRelativePath(basePath, linkSources[i])); + } + } + String[] preArgs = linkConfig.getPreArguments(); + for (int i = 0; i < preArgs.length; i++) { + options.append(' '); + options.append(preArgs[i]); + baseOptions.append(' '); + baseOptions.append(preArgs[i]); + } + String[] endArgs = linkConfig.getEndArguments(); + for (int i = 0; i < endArgs.length; i++) { + options.append(' '); + options.append(endArgs[i]); + baseOptions.append(' '); + baseOptions.append(endArgs[i]); + } + } + baseOptions.append("\r\n"); + options.append("\r\n"); + writer.write(baseOptions.toString()); + writer.write(options.toString()); + } }