summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcarnold <[email protected]>2008-02-05 07:39:54 +0000
committercarnold <[email protected]>2008-02-05 07:39:54 +0000
commitf3766103c1d4635d42f9947457f6cd4a6584d339 (patch)
tree25d6befc2aa84881e381aa172eb358af9b9d0494
parentca04487bffb385827349e5d4937937572826b8e8 (diff)
Bug 980130: Add VS 2008 project generation, fix VS 2005 issues
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/cpptasks/trunk@149 32d7a393-a5a9-423c-abd3-5d954feb1f2f
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/CUtil.java12
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java27
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java43
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java6
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java9
5 files changed, 68 insertions, 29 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java b/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java
index 2ac18e5..4681e95 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java
@@ -28,6 +28,8 @@ import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Environment;
+import org.apache.tools.ant.util.StringUtils;
+
/**
* Some utilities used by the CC and Link tasks.
*
@@ -484,4 +486,14 @@ public class CUtil {
public static boolean isSignificantlyAfter(long time1, long time2) {
return time1 > (time2 + FILETIME_EPSILON);
}
+
+
+ public static String toWindowsPath(final String path) {
+ if (File.separatorChar != '\\' && path.indexOf(File.separatorChar) != -1) {
+ return StringUtils.replace(path, File.separator, "\\");
+ }
+ return path;
+ }
+
+
}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
index 12d2fb9..d55e42f 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2004 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -199,10 +199,10 @@ public final class DevStudioProjectWriter
String buildDirPath = CUtil.getRelativePath(basePath, buildDir);
writer.write("# PROP BASE Output_Dir \"");
- writer.write(toWindowsPath(buildDirPath));
+ writer.write(CUtil.toWindowsPath(buildDirPath));
writer.write("\"\r\n");
writer.write("# PROP BASE Intermediate_Dir \"");
- writer.write(toWindowsPath(objDirPath));
+ writer.write(CUtil.toWindowsPath(objDirPath));
writer.write("\"\r\n");
writer.write("# PROP BASE Target_Dir \"\"\r\n");
writer.write("# PROP Use_MFC 0\r\n");
@@ -213,10 +213,10 @@ public final class DevStudioProjectWriter
writer.write("0\r\n");
}
writer.write("# PROP Output_Dir \"");
- writer.write(toWindowsPath(buildDirPath));
+ writer.write(CUtil.toWindowsPath(buildDirPath));
writer.write("\"\r\n");
writer.write("# PROP Intermediate_Dir \"");
- writer.write(toWindowsPath(objDirPath));
+ writer.write(CUtil.toWindowsPath(objDirPath));
writer.write("\"\r\n");
writer.write("# PROP Target_Dir \"\"\r\n");
writeCompileOptions(writer, basePath, compilerConfig);
@@ -338,7 +338,7 @@ public final class DevStudioProjectWriter
if (dep.getFile() != null) {
String projName = toProjectName(dep.getName());
projectDeps.add(projName);
- String depProject = toWindowsPath(
+ String depProject = CUtil.toWindowsPath(
CUtil.getRelativePath(basePath,
new File(dep.getFile() + ".dsp")));
writeWorkspaceProject(writer, projName, depProject, dep.getDependsList());
@@ -397,7 +397,7 @@ public final class DevStudioProjectWriter
&& !relativePath.startsWith("\\")) {
relativePath = ".\\" + relativePath;
}
- writer.write(toWindowsPath(relativePath));
+ writer.write(CUtil.toWindowsPath(relativePath));
writer.write("\r\n# End Source File\r\n");
}
@@ -515,7 +515,7 @@ public final class DevStudioProjectWriter
for (int i = 0; i < includePath.length; i++) {
options.append(" /I \"");
String relPath = CUtil.getRelativePath(baseDir, includePath[i]);
- options.append(toWindowsPath(relPath));
+ options.append(CUtil.toWindowsPath(relPath));
options.append('"');
}
@@ -563,13 +563,6 @@ public final class DevStudioProjectWriter
|| lcPath.indexOf("microsoft") != -1;
}
- private static String toWindowsPath(final String path) {
- if (File.separatorChar != '\\' && path.indexOf(File.separatorChar) != -1) {
- return StringUtils.replace(path, File.separator, "\\");
- }
- return path;
- }
-
/**
* Writes link options.
* @param writer Writer writer
@@ -613,11 +606,11 @@ public final class DevStudioProjectWriter
// must quote
if (relPath.indexOf(' ') > 0) {
options.append(" \"");
- options.append(toWindowsPath(relPath));
+ options.append(CUtil.toWindowsPath(relPath));
options.append("\"");
} else {
options.append(' ');
- options.append(toWindowsPath(relPath));
+ options.append(CUtil.toWindowsPath(relPath));
}
}
}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
index 898503e..868a0f9 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2004-2006 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -88,6 +88,19 @@ public final class VisualStudioNETProjectWriter
this.trueLiteral = trueArg;
this.falseLiteral = falseArg;
}
+
+ /**
+ * Determines if source file has a system path,
+ * that is part of the compiler or platform.
+ * @param source source, may not be null.
+ * @return true is source file appears to be system library
+ * and its path should be discarded.
+ */
+ private static boolean isSystemPath(final File source) {
+ String lcPath = source.toString().toLowerCase(java.util.Locale.US);
+ return lcPath.indexOf("platformsdk") != -1
+ || lcPath.indexOf("microsoft") != -1;
+ }
/**
* Get configuration name.
@@ -128,7 +141,7 @@ public final class VisualStudioNETProjectWriter
final CCTask task) {
File outFile = task.getOutfile();
File buildDir = outFile.getParentFile();
- return CUtil.getRelativePath(basePath, buildDir);
+ return CUtil.toWindowsPath(CUtil.getRelativePath(basePath, buildDir));
}
/**
@@ -140,7 +153,7 @@ public final class VisualStudioNETProjectWriter
private String getIntermediateDirectory(final String basePath,
final CCTask task) {
File objDir = task.getObjdir();
- return CUtil.getRelativePath(basePath, objDir);
+ return CUtil.toWindowsPath(CUtil.getRelativePath(basePath, objDir));
}
@@ -224,12 +237,15 @@ public final class VisualStudioNETProjectWriter
* @return value of AdditionalIncludeDirectories property.
*/
private String getAdditionalIncludeDirectories(
+ final String basePath,
final CommandLineCompilerConfiguration compilerConfig) {
StringBuffer includeDirs = new StringBuffer();
String[] args = compilerConfig.getPreArguments();
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("/I")) {
- includeDirs.append(args[i].substring(2));
+ includeDirs.append(CUtil.toWindowsPath(
+ CUtil.getRelativePath(basePath,
+ new File(args[i].substring(2)))));
includeDirs.append(';');
}
}
@@ -432,6 +448,7 @@ public final class VisualStudioNETProjectWriter
* @throws SAXException thrown if error during serialization.
*/
private void writeCompilerElement(final ContentHandler content,
+ final String basePath,
final CommandLineCompilerConfiguration compilerConfig)
throws SAXException {
AttributesImpl attributes = new AttributesImpl();
@@ -439,7 +456,7 @@ public final class VisualStudioNETProjectWriter
addAttribute(attributes, "Optimization",
getOptimization(compilerConfig));
addAttribute(attributes, "AdditionalIncludeDirectories",
- getAdditionalIncludeDirectories(compilerConfig));
+ getAdditionalIncludeDirectories(basePath, compilerConfig));
addAttribute(attributes, "PreprocessorDefinitions",
getPreprocessorDefinitions(compilerConfig));
addAttribute(attributes, "MinimalRebuild",
@@ -559,18 +576,26 @@ public final class VisualStudioNETProjectWriter
// if file was not compiled or otherwise generated
//
if (targets.get(linkSources[i].getName()) == null) {
- String relPath = CUtil.getRelativePath(basePath, linkSources[i]);
+ //
+ // if source appears to be a system library or object file
+ // just output the name of the file (advapi.lib for example)
+ // otherwise construct a relative path.
+ //
+ String relPath = linkSources[i].getName();
+ if (!isSystemPath(linkSources[i])) {
+ relPath = CUtil.getRelativePath(basePath, linkSources[i]);
+ }
//
// if path has an embedded space then
// must quote
if (relPath.indexOf(' ') > 0) {
buf.append('\"');
- buf.append(relPath);
+ buf.append(CUtil.toWindowsPath(relPath));
buf.append('\"');
} else {
buf.append(relPath);
}
- buf.append(';');
+ buf.append(' ');
}
}
if (buf.length() > 0) {
@@ -689,7 +714,7 @@ public final class VisualStudioNETProjectWriter
writeConfigurationStartTag(content, basePath, task, compilerConfig);
- writeCompilerElement(content, compilerConfig);
+ writeCompilerElement(content, basePath, compilerConfig);
writeLinkerElement(content, basePath, linkTarget, targets);
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
index 74cda8a..77c0cb3 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2004-2006 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -126,6 +126,10 @@ public final class ProjectDef
* <td>Microsoft Visual C++ 2005</td>
* </tr>
* <tr>
+ * <td>msvc9</td>
+ * <td>Microsoft Visual C++ 2008</td>
+ * </tr>
+ * <tr>
* <td>xcode</td>
* <td>Apple Xcode</td>
* </tr>
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java
index e100dbc..a50a7b2 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2004-2006 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -51,6 +51,10 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* <td>Microsoft Visual C++ 2005</td>
* </tr>
* <tr>
+ * <td>msvc9</td>
+ * <td>Microsoft Visual C++ 2008</td>
+ * </tr>
+ * <tr>
* <td>xcode</td>
* <td>Apple Xcode</td>
* </tr>
@@ -66,7 +70,7 @@ public final class ProjectWriterEnum
*/
private static String[] values = new String[] {
"cbuilderx", "msvc5",
- "msvc6", "msvc7", "msvc71", "msvc8", "xcode"};
+ "msvc6", "msvc7", "msvc71", "msvc8", "msvc9", "xcode"};
/**
* Project writers associated with enumeration values.
@@ -77,6 +81,7 @@ public final class ProjectWriterEnum
new VisualStudioNETProjectWriter("7.00", "TRUE", "FALSE"),
new VisualStudioNETProjectWriter("7.10", "TRUE", "FALSE"),
new VisualStudioNETProjectWriter("8.00", "true", "false"),
+ new VisualStudioNETProjectWriter("9.00", "true", "false"),
new XcodeProjectWriter()};
/**