Index: samples/cppunit.ant =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/samples/cppunit.ant,v retrieving revision 1.7 diff -u -r1.7 cppunit.ant --- samples/cppunit.ant 8 Jul 2004 22:27:30 -0000 1.7 +++ samples/cppunit.ant 13 Jul 2004 03:54:01 -0000 @@ -175,7 +175,7 @@ - + @@ -200,6 +200,8 @@ + + @@ -224,6 +226,7 @@ + Index: src/net/sf/antcontrib/cpptasks/CCTask.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/CCTask.java,v retrieving revision 1.58 diff -u -r1.58 CCTask.java --- src/net/sf/antcontrib/cpptasks/CCTask.java 8 Jul 2004 22:30:53 -0000 1.58 +++ src/net/sf/antcontrib/cpptasks/CCTask.java 13 Jul 2004 03:54:01 -0000 @@ -958,8 +958,17 @@ */ public void setDebug(boolean debug) { compilerDef.setDebug(debug); - linkerDef.setDebug(debug); + linkerDef.setDebug(debug); } + + /** + * Gets debug state. + * @return true if building for debugging + */ + public boolean getDebug() { + return compilerDef.getDebug(null, 0); + } + /** * Deprecated. * @@ -1204,6 +1213,15 @@ public void setOuttype(OutputTypeEnum outputType) { linkType.setOutputType(outputType); } + + /** + * Gets output type. + * @return output type + */ + public String getOuttype() { + return linkType.getOutputType(); + } + /** * Sets the project. */ @@ -1269,6 +1287,15 @@ } linkType.setSubsystem(subsystem); } + + /** + * Gets subsystem name. + * @return Subsystem name + */ + public String getSubsystem() { + return linkType.getSubsystem(); + } + /** * Enumerated attribute with the values "none", "severe", "default", * "production", "diagnostic", and "failtask". Index: src/net/sf/antcontrib/cpptasks/compiler/LinkType.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/compiler/LinkType.java,v retrieving revision 1.15 diff -u -r1.15 LinkType.java --- src/net/sf/antcontrib/cpptasks/compiler/LinkType.java 28 Feb 2004 20:00:40 -0000 1.15 +++ src/net/sf/antcontrib/cpptasks/compiler/LinkType.java 13 Jul 2004 03:54:01 -0000 @@ -110,6 +110,15 @@ } this.outputType = outputType; } + + /** + * Gets the output type. + * @return output type + */ + public String getOutputType() { + return outputType.getValue(); + } + /** * Requests use of a static runtime library. * @@ -131,4 +140,12 @@ } this.subsystem = subsystem; } + + /** + * Get subsystem name. + * @return subsystem name + */ + public String getSubsystem() { + return subsystem.getValue(); + } } 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.2 diff -u -r1.2 DevStudioProjectWriter.java --- src/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java 8 Jul 2004 22:28:14 -0000 1.2 +++ src/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java 13 Jul 2004 03:54:01 -0000 @@ -57,14 +57,6 @@ } /** - * Gets configuration name. - * @return String configuration name - */ - private String getConfiguration() { - return "testdllproj - Win32 Debug"; - } - - /** * Writes a project definition file. * @param fileName File name base, writer may append appropriate extension * @param task cc task for which to write project @@ -91,40 +83,39 @@ writer.write(this.version); writer.write("\r\n"); writer.write("# ** DO NOT EDIT **\r\n\r\n"); - writer.write( - "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n\r\n"); - writer.write("CFG="); - writer.write(getConfiguration()); - writer.write("\r\n"); - writer.write( - "!MESSAGE This is not a valid makefile. "); - writer.write("To build this project using NMAKE,\r\n"); - writer.write("!MESSAGE use the Export Makefile command and run\r\n"); - writer.write("!MESSAGE \r\n"); - writer.write("!MESSAGE NMAKE /f \""); - writer.write(projectName); - writer.write(".mak\".\r\n"); - writer.write("!MESSAGE \r\n"); - writer.write( - "!MESSAGE You can specify a configuration when running NMAKE\r\n"); - writer.write( - "!MESSAGE by defining the macro CFG on the command line. "); - writer.write("For example:\r\n"); - writer.write("!MESSAGE \r\n"); - writer.write("!MESSAGE NMAKE /f \""); - writer.write(projectName); - writer.write(".mak\" CFG=\""); - writer.write(getConfiguration()); - writer.write("\"\r\n"); - writer.write("!MESSAGE \r\n"); - writer.write("!MESSAGE Possible choices for configuration are:\r\n"); - writer.write("!MESSAGE \r\n"); - writer.write("!MESSAGE \""); - writer.write(getConfiguration()); - writer.write("\" (based on\\\r\n"); - writer.write(" \"Win32 (x86) Dynamic-Link Library\")\r\n"); - writer.write("!MESSAGE \r\n"); + String outputType = task.getOuttype(); + String subsystem = task.getSubsystem(); + String configName = projectName; + final boolean isDebug = task.getDebug(); + if (isDebug) { + configName += " - Win32 Debug"; + } else { + configName += " - Win32 Release"; + } + String targtype = "Win32 (x86) Dynamic-Link Library"; + String targid = "0x0102"; + if ("executable".equals(outputType)) { + if ("console".equals(subsystem)) { + targtype = "Win32 (x86) Console Application"; + targid = "0x0103"; + } else { + targtype = "Win32 (x86) Application"; + targid = "0x0101"; + } + } else if ("static".equals(outputType)) { + targtype = "Win32 (x86) Static Library"; + targid = "0x0104"; + } + writer.write("# TARGTYPE \""); + writer.write(targtype); + writer.write("\" "); + writer.write(targid); + writer.write("\r\n\r\nCFG="); + writer.write(configName); writer.write("\r\n"); + + writeMessage(writer, projectName, configName, targtype); + writer.write("# Begin Project\r\n"); writer.write("# PROP Scc_ProjName \"\"\r\n"); writer.write("# PROP Scc_LocalPath \"\"\r\n"); @@ -132,14 +123,46 @@ writer.write("MTL=midl.exe\r\n"); writer.write("RSC=rc.exe\r\n"); writer.write("# PROP BASE Use_MFC 0\r\n"); - writer.write("# PROP BASE Use_Debug_Libraries 1\r\n"); - writer.write("# PROP BASE Output_Dir \"Debug\"\r\n"); - writer.write("# PROP BASE Intermediate_Dir \"Debug\"\r\n"); + + writer.write("# PROP BASE Use_Debug_Libraries "); + if (isDebug) { + writer.write("1"); + } else { + writer.write("0"); + } + + File objDir = task.getObjdir(); + String objDirPath = CUtil.getRelativePath(basePath, objDir); + if (!objDirPath.endsWith("\\")) { + objDirPath += "\\"; + } + File outFile = task.getOutfile(); + File buildDir = outFile.getParentFile(); + String buildDirPath = CUtil.getRelativePath(basePath, buildDir); + if (!buildDirPath.endsWith("\\")) { + buildDirPath += "\\"; + } + + writer.write("# PROP BASE Output_Dir \""); + writer.write(buildDirPath); + writer.write("\"\r\n"); + writer.write("# PROP BASE Intermediate_Dir \""); + writer.write(objDirPath); + writer.write("\"\r\n"); writer.write("# PROP BASE Target_Dir \"\"\r\n"); writer.write("# PROP Use_MFC 0\r\n"); - writer.write("# PROP Use_Debug_Libraries 1\r\n"); - writer.write("# PROP Output_Dir \"Debug\"\r\n"); - writer.write("# PROP Intermediate_Dir \"Debug\"\r\n"); + writer.write("# PROP Use_Debug_Libraries "); + if (isDebug) { + writer.write("1"); + } else { + writer.write("0"); + } + writer.write("# PROP Output_Dir \""); + writer.write(buildDirPath); + writer.write("\"\r\n"); + writer.write("# PROP Intermediate_Dir \""); + 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"; @@ -156,20 +179,39 @@ 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"); + + "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"); + + "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("# Begin Target\r\n\r\n"); writer.write("# Name \""); - writer.write(getConfiguration()); + writer.write(configName); writer.write("\"\r\n"); + File[] sortedSources = getSources(targets); + for (int i = 0; i < sortedSources.length; i++) { + writer.write("# Begin Source File\r\n\r\nSOURCE="); + String relativePath = CUtil.getRelativePath(basePath, + (File) sortedSources[i]); + writer.write(relativePath); + writer.write("\r\n# End Source File\r\n"); + } + writer.write("# End Target\r\n"); + writer.write("# End Project\r\n"); + writer.close(); + } + + /** + * Get alphabetized array of source files. + * @param targets Hashtable compilation targets + * @return File[] source files + */ + private File[] getSources(final Hashtable targets) { Vector sourceList = new Vector(targets.size()); Iterator targetIter = targets.values().iterator(); while (targetIter.hasNext()) { @@ -179,24 +221,61 @@ sourceList.addElement(sources[i]); } } - Object[] sortedSources = new File[sourceList.size()]; + File[] sortedSources = new File[sourceList.size()]; sourceList.copyInto(sortedSources); Arrays.sort(sortedSources, new Comparator() { public int compare(final Object o1, final Object o2) { return ((File) o1).getName().compareTo(((File) o2).getName()); } }); - - for (int i = 0; i < sortedSources.length; i++) { - writer.write("# Begin Source File\r\n\r\nSOURCE="); - String relativePath = CUtil.getRelativePath(basePath, - (File) sortedSources[i]); - writer.write(relativePath); - writer.write("\r\n# End Source File\r\n"); - } - writer.write("# End Target\r\n"); - writer.write("# End Project\r\n"); - writer.close(); + return sortedSources; } + /** + * Writes "This is not a makefile" warning. + * @param writer Writer writer + * @param projectName String project name + * @param configName String configuration name + * @param targtype String target type + * @throws IOException if error writing project + */ + + private void writeMessage(final Writer writer, + final String projectName, + final String configName, + final String targtype) + throws IOException { + writer.write( + "!MESSAGE This is not a valid makefile. "); + writer.write("To build this project using NMAKE,\r\n"); + writer.write("!MESSAGE use the Export Makefile command and run\r\n"); + writer.write("!MESSAGE \r\n"); + writer.write("!MESSAGE NMAKE /f \""); + writer.write(projectName); + writer.write(".mak\".\r\n"); + writer.write("!MESSAGE \r\n"); + writer.write( + "!MESSAGE You can specify a configuration when running NMAKE\r\n"); + writer.write( + "!MESSAGE by defining the macro CFG on the command line. "); + writer.write("For example:\r\n"); + writer.write("!MESSAGE \r\n"); + writer.write("!MESSAGE NMAKE /f \""); + writer.write(projectName); + writer.write(".mak\" CFG=\""); + writer.write(configName); + writer.write("\"\r\n"); + writer.write("!MESSAGE \r\n"); + writer.write("!MESSAGE Possible choices for configuration are:\r\n"); + writer.write("!MESSAGE \r\n"); + writer.write("!MESSAGE \""); + writer.write(configName); + writer.write("\" (based on\\\r\n"); + writer.write(" \""); + writer.write(targtype); + writer.write("\")\r\n"); + writer.write("!MESSAGE \r\n"); + writer.write("\r\n"); + + } }