SF.net SVN: ant-contrib: [136] cpptasks/trunk/src/main/java/net/sf/ antcontrib/cpptasks/apple/XcodeProjectWriter.java
[email protected] Fri, 03 Aug 2007 00:28:02 -0700
| Newsgroups | gmane.comp.java.ant-contrib.devel |
|---|---|
| Message-ID | <[email protected]> |
Revision: 136
http://ant-contrib.svn.sourceforge.net/ant-contrib/?rev=136&view=rev
Author: carnold
Date: 2007-08-03 00:28:01 -0700 (Fri, 03 Aug 2007)
Log Message:
-----------
Bug 980130: Continue XCode project now static libs working, defines, etc
Modified Paths:
--------------
cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java
Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java 2007-08-02 22:46:45 UTC (rev 135)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java 2007-08-03 07:28:01 UTC (rev 136)
@@ -21,6 +21,7 @@
import net.sf.antcontrib.cpptasks.CUtil;
import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration;
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;
import net.sf.antcontrib.cpptasks.gcc.GccCCompiler;
import net.sf.antcontrib.cpptasks.ide.ProjectDef;
import net.sf.antcontrib.cpptasks.ide.ProjectWriter;
@@ -147,7 +148,12 @@
//
// add project configurations
//
- PBXObjectRef projectConfigurations = addProjectConfigurationList(objects);
+ PBXObjectRef compilerConfigurations =
+ addProjectConfigurationList(objects,
+ basePath,
+ compilerConfig,
+ (CommandLineLinkerConfiguration)
+ linkTarget.getConfiguration());
String projectDirPath = "";
List projectTargets = new ArrayList();
@@ -157,14 +163,15 @@
// shared library)
//
PBXObjectRef nativeTarget =
- addNativeTarget(objects, linkTarget, product, sourceGroupChildren);
+ addNativeTarget(objects, linkTarget, product,
+ projectName, sourceGroupChildren);
projectTargets.add(nativeTarget);
//
// add project to property list
//
- PBXObjectRef project = createPBXProject(projectConfigurations, mainGroup,
+ PBXObjectRef project = createPBXProject(compilerConfigurations, mainGroup,
projectDirPath, projectTargets);
objects.put(project.getID(), project.getProperties());
@@ -225,7 +232,12 @@
linkTarget.getOutput().getParent(),
linkTarget.getOutput());
Map executableProperties = executable.getProperties();
- executableProperties.put("explicitFileType", "compiled.mach-o.executable");
+
+ String fileType = "compiled.mach-o.executable";
+ if (isStaticLibrary(linkTarget)) {
+ fileType = "archive.ar";
+ }
+ executableProperties.put("explicitFileType", fileType);
executableProperties.put("includeInIndex", "0");
objects.put(executable.getID(), executableProperties);
@@ -322,9 +334,14 @@
/**
* Add project configuration list.
* @param objects map of objects.
+ * @param compilerConfig compiler configuration.
+ * @param linkerConfig linker configuration.
* @return project configuration object.
*/
- private PBXObjectRef addProjectConfigurationList(final Map objects) {
+ private PBXObjectRef addProjectConfigurationList(final Map objects,
+ final String baseDir,
+ final CommandLineCompilerConfiguration compilerConfig,
+ final CommandLineLinkerConfiguration linkerConfig) {
//
// Create a configuration list with
// two stock configurations: Debug and Release
@@ -353,6 +370,58 @@
projectConfigurationListProperties.put("defaultConfigurationIsVisible", "0");
projectConfigurationListProperties.put("defaultConfigurationName", "Release");
objects.put(configurationList.getID(), configurationList.getProperties());
+
+ //
+ // add include paths to both configurations
+ //
+ File[] includeDirs = compilerConfig.getIncludePath();
+ if (includeDirs.length > 0) {
+ ArrayList includePaths = new ArrayList();
+ for (int i = 0; i < includeDirs.length; i++) {
+ String relPath = CUtil.getRelativePath(baseDir, includeDirs[i]);
+ if (relPath.startsWith("..")) {
+ includePaths.add(includeDirs[i].getPath());
+ } else {
+ includePaths.add(relPath);
+ }
+ }
+ includePaths.add("${inherited)");
+ debugSettings.put("HEADER_SEARCH_PATHS", includePaths);
+ releaseSettings.put("HEADER_SEARCH_PATHS", includePaths);
+ }
+
+ //
+ // add preprocessor definitions to both configurations
+ //
+ //
+ String[] preArgs = compilerConfig.getPreArguments();
+ List defines = new ArrayList();
+ for (int i = 0; i < preArgs.length; i++) {
+ if (preArgs[i].startsWith("-D")) {
+ defines.add(preArgs[i].substring(2));
+ }
+ }
+ if (defines.size() > 0) {
+ defines.add("$(inherited)");
+ debugSettings.put("GCC_PREPROCESSOR_DEFINITIONS", defines);
+ releaseSettings.put("GCC_PREPROCESSOR_DEFINITIONS", defines);
+ }
+
+ String[] linkerArgs = linkerConfig.getPreArguments();
+ List librarySearchPaths = new ArrayList();
+ for (int i = 0; i < linkerArgs.length; i++) {
+ if (linkerArgs[i].startsWith("-L")) {
+ librarySearchPaths.add(linkerArgs[i].substring(2));
+ }
+ }
+ if (librarySearchPaths.size() > 0) {
+ librarySearchPaths.add("\"$(inherited)\"");
+ debugSettings.put("LIBRARY_SEARCH_PATHS", librarySearchPaths);
+ releaseSettings.put("LIBRARY_SEARCH_PATHS", librarySearchPaths);
+ }
+
+
+
return configurationList;
}
@@ -361,16 +430,18 @@
* @param objects map of objects.
* @param linkTarget description of executable or shared library.
* @param product product.
+ * @param projectName project name.
* @param sourceGroupChildren source files needed to build product.
* @return native target.
*/
private PBXObjectRef addNativeTarget(final Map objects,
final TargetInfo linkTarget,
final PBXObjectRef product,
+ final String projectName,
final List sourceGroupChildren) {
- PBXObjectRef buildConfigurations = this.addNativeTargetConfigurationList(objects,
- linkTarget.getOutput().getName());
+ PBXObjectRef buildConfigurations =
+ addNativeTargetConfigurationList(objects, projectName);
int buildActionMask = 2147483647;
List buildPhases = new ArrayList();
@@ -411,16 +482,29 @@
String productInstallPath = "$(HOME)/bin";
String productType = "com.apple.product-type.tool";
+ if (isStaticLibrary(linkTarget)) {
+ productType = "com.apple.product-type.library.static";
+ }
- PBXObjectRef nativeTarget = createPBXNativeTarget("hello",
+ PBXObjectRef nativeTarget = createPBXNativeTarget(projectName,
buildConfigurations, buildPhases, buildRules, dependencies,
- productInstallPath, "hello", product, productType);
+ productInstallPath, projectName, product, productType);
objects.put(nativeTarget.getID(), nativeTarget.getProperties());
return nativeTarget;
}
+ /**
+ * Determines if linked target is a static library.
+ * @param linkTarget link target
+ * @return true if a static library
+ */
+ private static boolean isStaticLibrary(final TargetInfo linkTarget) {
+ String outPath = linkTarget.getOutput().getPath();
+ return (outPath.lastIndexOf(".a") == outPath.length() - 2);
+ }
+
/**
* Create PBXFileReference.
* @param sourceTree source tree.
@@ -435,11 +519,6 @@
map.put("isa", "PBXFileReference");
String relPath = CUtil.getRelativePath(baseDir, file);
- String name = file.getName();
-
- if (!name.equals(relPath)) {
- map.put("name", name);
- }
map.put("path", relPath);
map.put("sourceTree", sourceTree);
return new PBXObjectRef(map);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/