The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1222 lines
50KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__
  20. #include "jucer_ProjectExporter.h"
  21. namespace
  22. {
  23. const char* const osxVersionDefault = "default";
  24. const char* const osxVersion10_4 = "10.4 SDK";
  25. const char* const osxVersion10_5 = "10.5 SDK";
  26. const char* const osxVersion10_6 = "10.6 SDK";
  27. const char* const osxVersion10_7 = "10.7 SDK";
  28. const char* const osxArch_Default = "default";
  29. const char* const osxArch_Native = "Native";
  30. const char* const osxArch_32BitUniversal = "32BitUniversal";
  31. const char* const osxArch_64BitUniversal = "64BitUniversal";
  32. const char* const osxArch_64Bit = "64BitIntel";
  33. }
  34. //==============================================================================
  35. class XCodeProjectExporter : public ProjectExporter
  36. {
  37. public:
  38. //==============================================================================
  39. static const char* getNameMac() { return "XCode (MacOSX)"; }
  40. static const char* getNameiOS() { return "XCode (iOS)"; }
  41. static const char* getValueTreeTypeName (bool iOS) { return iOS ? "XCODE_IPHONE" : "XCODE_MAC"; }
  42. //==============================================================================
  43. XCodeProjectExporter (Project& project_, const ValueTree& settings_, const bool iOS_)
  44. : ProjectExporter (project_, settings_),
  45. iOS (iOS_)
  46. {
  47. name = iOS ? getNameiOS() : getNameMac();
  48. if (getTargetLocationString().isEmpty())
  49. getTargetLocationValue() = getDefaultBuildsRootFolder() + (iOS ? "iOS" : "MacOSX");
  50. }
  51. static XCodeProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  52. {
  53. if (settings.hasType (getValueTreeTypeName (false)))
  54. return new XCodeProjectExporter (project, settings, false);
  55. else if (settings.hasType (getValueTreeTypeName (true)))
  56. return new XCodeProjectExporter (project, settings, true);
  57. return nullptr;
  58. }
  59. //==============================================================================
  60. Value getPListToMergeValue() { return getSetting ("customPList"); }
  61. String getPListToMergeString() const { return settings ["customPList"]; }
  62. Value getExtraFrameworksValue() { return getSetting (Ids::extraFrameworks); }
  63. String getExtraFrameworksString() const { return settings [Ids::extraFrameworks]; }
  64. Value getPostBuildScriptValue() { return getSetting (Ids::postbuildCommand); }
  65. String getPostBuildScript() const { return settings [Ids::postbuildCommand]; }
  66. int getLaunchPreferenceOrderForCurrentOS()
  67. {
  68. #if JUCE_MAC
  69. return iOS ? 1 : 2;
  70. #else
  71. return 0;
  72. #endif
  73. }
  74. bool isAvailableOnCurrentOS()
  75. {
  76. #if JUCE_MAC
  77. return true;
  78. #else
  79. return false;
  80. #endif
  81. }
  82. bool isPossibleForCurrentProject() { return projectType.isGUIApplication() || ! iOS; }
  83. bool usesMMFiles() const { return true; }
  84. bool isXcode() const { return true; }
  85. bool isOSX() const { return ! iOS; }
  86. bool canCopeWithDuplicateFiles() { return true; }
  87. void createPropertyEditors (PropertyListBuilder& props)
  88. {
  89. ProjectExporter::createPropertyEditors (props);
  90. if (projectType.isGUIApplication() && ! iOS)
  91. {
  92. props.add (new TextPropertyComponent (getSetting ("documentExtensions"), "Document file extensions", 128, false),
  93. "A comma-separated list of file extensions for documents that your app can open.");
  94. }
  95. else if (iOS)
  96. {
  97. props.add (new BooleanPropertyComponent (getSetting ("UIFileSharingEnabled"), "File Sharing Enabled", "Enabled"),
  98. "Enable this to expose your app's files to iTunes.");
  99. props.add (new BooleanPropertyComponent (getSetting ("UIStatusBarHidden"), "Status Bar Hidden", "Enabled"),
  100. "Enable this to disable the status bar in your app.");
  101. }
  102. props.add (new TextPropertyComponent (getPListToMergeValue(), "Custom PList", 8192, true),
  103. "You can paste the contents of an XML PList file in here, and the settings that it contains will override any "
  104. "settings that the Introjucer creates. BEWARE! When doing this, be careful to remove from the XML any "
  105. "values that you DO want the introjucer to change!");
  106. props.add (new TextPropertyComponent (getExtraFrameworksValue(), "Extra Frameworks", 2048, false),
  107. "A comma-separated list of extra frameworks that should be added to the build. "
  108. "(Don't include the .framework extension in the name)");
  109. if (projectType.isLibrary())
  110. {
  111. const char* const libTypes[] = { "Static Library (.a)", "Dynamic Library (.dylib)", 0 };
  112. const int libTypeValues[] = { 1, 2, 0 };
  113. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type",
  114. StringArray (libTypes), Array<var> (libTypeValues)));
  115. }
  116. props.add (new TextPropertyComponent (getPostBuildScriptValue(), "Post-build shell script", 32768, true),
  117. "Some shell-script that will be run after a build completes.");
  118. }
  119. void launchProject()
  120. {
  121. getProjectBundle().startAsProcess();
  122. }
  123. //==============================================================================
  124. void create (const OwnedArray<LibraryModule>&) const
  125. {
  126. infoPlistFile = getTargetFolder().getChildFile ("Info.plist");
  127. createIconFile();
  128. File projectBundle (getProjectBundle());
  129. createDirectoryOrThrow (projectBundle);
  130. createObjects();
  131. File projectFile (projectBundle.getChildFile ("project.pbxproj"));
  132. {
  133. MemoryOutputStream mo;
  134. writeProjectFile (mo);
  135. overwriteFileIfDifferentOrThrow (projectFile, mo);
  136. }
  137. writeInfoPlistFile();
  138. }
  139. protected:
  140. Value getLibraryType() { return getSetting (Ids::libraryType); }
  141. bool isStaticLibrary() const { return projectType.isLibrary() && (int) settings [Ids::libraryType] == 1; }
  142. //==============================================================================
  143. class XcodeBuildConfiguration : public BuildConfiguration
  144. {
  145. public:
  146. XcodeBuildConfiguration (Project& project, const ValueTree& settings, const bool iOS_)
  147. : BuildConfiguration (project, settings), iOS (iOS_)
  148. {
  149. if (iOS)
  150. {
  151. if (getiOSCompatibilityVersion().isEmpty())
  152. getiOSCompatibilityVersionValue() = osxVersionDefault;
  153. }
  154. else
  155. {
  156. if (getMacSDKVersion().isEmpty())
  157. getMacSDKVersionValue() = osxVersionDefault;
  158. if (getMacCompatibilityVersion().isEmpty())
  159. getMacCompatibilityVersionValue() = osxVersionDefault;
  160. if (getMacArchitecture().isEmpty())
  161. getMacArchitectureValue() = osxArch_Default;
  162. }
  163. }
  164. Value getMacSDKVersionValue() { return getValue (Ids::osxSDK); }
  165. String getMacSDKVersion() const { return config [Ids::osxSDK]; }
  166. Value getMacCompatibilityVersionValue() { return getValue (Ids::osxCompatibility); }
  167. String getMacCompatibilityVersion() const { return config [Ids::osxCompatibility]; }
  168. Value getiOSCompatibilityVersionValue() { return getValue (Ids::iosCompatibility); }
  169. String getiOSCompatibilityVersion() const { return config [Ids::iosCompatibility]; }
  170. Value getMacArchitectureValue() { return getValue (Ids::osxArchitecture); }
  171. String getMacArchitecture() const { return config [Ids::osxArchitecture]; }
  172. Value getCustomXcodeFlagsValue() { return getValue (Ids::customXcodeFlags); }
  173. String getCustomXcodeFlags() const { return config [Ids::customXcodeFlags]; }
  174. Value getCppLibTypeValue() { return getValue (Ids::cppLibType); }
  175. String getCppLibType() const { return config [Ids::cppLibType]; }
  176. void createPropertyEditors (PropertyListBuilder& props)
  177. {
  178. createBasicPropertyEditors (props);
  179. if (iOS)
  180. {
  181. const char* iosVersions[] = { "Use Default", "3.2", "4.0", "4.1", "4.2", "4.3", "5.0", "5.1", 0 };
  182. const char* iosVersionValues[] = { osxVersionDefault, "3.2", "4.0", "4.1", "4.2", "4.3", "5.0", "5.1", 0 };
  183. props.add (new ChoicePropertyComponent (getiOSCompatibilityVersionValue(), "iOS Deployment Target",
  184. StringArray (iosVersions), Array<var> (iosVersionValues)),
  185. "The minimum version of iOS that the target binary will run on.");
  186. }
  187. else
  188. {
  189. const char* osxVersions[] = { "Use Default", osxVersion10_5, osxVersion10_6, osxVersion10_7, 0 };
  190. const char* osxVersionValues[] = { osxVersionDefault, osxVersion10_5, osxVersion10_6, osxVersion10_7, 0 };
  191. props.add (new ChoicePropertyComponent (getMacSDKVersionValue(), "OSX Base SDK Version",
  192. StringArray (osxVersions), Array<var> (osxVersionValues)),
  193. "The version of OSX to link against in the XCode build.");
  194. props.add (new ChoicePropertyComponent (getMacCompatibilityVersionValue(), "OSX Compatibility Version",
  195. StringArray (osxVersions), Array<var> (osxVersionValues)),
  196. "The minimum version of OSX that the target binary will be compatible with.");
  197. const char* osxArch[] = { "Use Default", "Native architecture of build machine",
  198. "Universal Binary (32-bit)", "Universal Binary (64-bit)", "64-bit Intel", 0 };
  199. const char* osxArchValues[] = { osxArch_Default, osxArch_Native, osxArch_32BitUniversal,
  200. osxArch_64BitUniversal, osxArch_64Bit, 0 };
  201. props.add (new ChoicePropertyComponent (getMacArchitectureValue(), "OSX Architecture",
  202. StringArray (osxArch), Array<var> (osxArchValues)),
  203. "The type of OSX binary that will be produced.");
  204. }
  205. props.add (new TextPropertyComponent (getCustomXcodeFlagsValue(), "Custom Xcode flags", 8192, false),
  206. "A comma-separated list of custom Xcode setting flags which will be appended to the list of generated flags, "
  207. "e.g. MACOSX_DEPLOYMENT_TARGET_i386 = 10.5, VALID_ARCHS = \"ppc i386 x86_64\"");
  208. const char* cppLibNames[] = { "Use Default", "Use LLVM libc++", 0 };
  209. Array<var> cppLibValues;
  210. cppLibValues.add (var::null);
  211. cppLibValues.add ("libc++");
  212. props.add (new ChoicePropertyComponent (getCppLibTypeValue(), "C++ Library", StringArray (cppLibNames), cppLibValues),
  213. "The type of C++ std lib that will be linked.");
  214. }
  215. bool iOS;
  216. };
  217. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  218. {
  219. return new XcodeBuildConfiguration (project, settings, iOS);
  220. }
  221. private:
  222. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  223. mutable StringArray buildPhaseIDs, resourceIDs, sourceIDs, frameworkIDs;
  224. mutable StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  225. mutable File infoPlistFile, iconFile;
  226. const bool iOS;
  227. static String sanitisePath (const String& path)
  228. {
  229. if (path.startsWithChar ('~'))
  230. return "$(HOME)" + path.substring (1);
  231. return path;
  232. }
  233. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  234. //==============================================================================
  235. void createObjects() const
  236. {
  237. addFrameworks();
  238. addMainBuildProduct();
  239. if (xcodeCreatePList)
  240. {
  241. RelativePath plistPath (infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  242. addFileReference (plistPath.toUnixStyle());
  243. resourceFileRefs.add (createFileRefID (plistPath));
  244. }
  245. if (iconFile.exists())
  246. {
  247. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  248. addFileReference (iconPath.toUnixStyle());
  249. resourceIDs.add (addBuildFile (iconPath, false, false));
  250. resourceFileRefs.add (createFileRefID (iconPath));
  251. }
  252. {
  253. StringArray topLevelGroupIDs;
  254. for (int i = 0; i < getAllGroups().size(); ++i)
  255. {
  256. const Project::Item& group = getAllGroups().getReference(i);
  257. if (group.getNumChildren() > 0)
  258. topLevelGroupIDs.add (addProjectItem (group));
  259. }
  260. { // Add 'resources' group
  261. String resourcesGroupID (createID ("__resources"));
  262. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  263. topLevelGroupIDs.add (resourcesGroupID);
  264. }
  265. { // Add 'frameworks' group
  266. String frameworksGroupID (createID ("__frameworks"));
  267. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  268. topLevelGroupIDs.add (frameworksGroupID);
  269. }
  270. { // Add 'products' group
  271. String productsGroupID (createID ("__products"));
  272. StringArray products;
  273. products.add (createID ("__productFileID"));
  274. addGroup (productsGroupID, "Products", products);
  275. topLevelGroupIDs.add (productsGroupID);
  276. }
  277. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  278. }
  279. for (ConstConfigIterator config (*this); config.next();)
  280. {
  281. const XcodeBuildConfiguration& xcodeConfig = dynamic_cast <const XcodeBuildConfiguration&> (*config);
  282. addProjectConfig (config->getName(), getProjectSettings (xcodeConfig));
  283. addTargetConfig (config->getName(), getTargetSettings (xcodeConfig));
  284. }
  285. addConfigList (projectConfigs, createID ("__projList"));
  286. addConfigList (targetConfigs, createID ("__configList"));
  287. if (! isStaticLibrary())
  288. addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  289. if (rezFileIDs.size() > 0)
  290. addBuildPhase ("PBXRezBuildPhase", rezFileIDs);
  291. addBuildPhase ("PBXSourcesBuildPhase", sourceIDs);
  292. if (! isStaticLibrary())
  293. addBuildPhase ("PBXFrameworksBuildPhase", frameworkIDs);
  294. addShellScriptPhase();
  295. addTargetObject();
  296. addProjectObject();
  297. }
  298. static Image fixMacIconImageSize (Image& image)
  299. {
  300. const int validSizes[] = { 16, 32, 48, 128, 256, 512, 1024 };
  301. const int w = image.getWidth();
  302. const int h = image.getHeight();
  303. int bestSize = 16;
  304. for (int i = 0; i < numElementsInArray (validSizes); ++i)
  305. {
  306. if (w == h && w == validSizes[i])
  307. return image;
  308. if (jmax (w, h) > validSizes[i])
  309. bestSize = validSizes[i];
  310. }
  311. return rescaleImageForIcon (image, bestSize);
  312. }
  313. static void writeOldIconFormat (MemoryOutputStream& out, const Image& image, const char* type, const char* maskType)
  314. {
  315. const int w = image.getWidth();
  316. const int h = image.getHeight();
  317. out.write (type, 4);
  318. out.writeIntBigEndian (8 + 4 * w * h);
  319. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  320. for (int y = 0; y < h; ++y)
  321. {
  322. for (int x = 0; x < w; ++x)
  323. {
  324. const Colour pixel (bitmap.getPixelColour (x, y));
  325. out.writeByte ((char) pixel.getAlpha());
  326. out.writeByte ((char) pixel.getRed());
  327. out.writeByte ((char) pixel.getGreen());
  328. out.writeByte ((char) pixel.getBlue());
  329. }
  330. }
  331. out.write (maskType, 4);
  332. out.writeIntBigEndian (8 + w * h);
  333. for (int y = 0; y < h; ++y)
  334. {
  335. for (int x = 0; x < w; ++x)
  336. {
  337. const Colour pixel (bitmap.getPixelColour (x, y));
  338. out.writeByte ((char) pixel.getAlpha());
  339. }
  340. }
  341. }
  342. static void writeNewIconFormat (MemoryOutputStream& out, const Image& image, const char* type)
  343. {
  344. MemoryOutputStream pngData;
  345. PNGImageFormat pngFormat;
  346. pngFormat.writeImageToStream (image, pngData);
  347. out.write (type, 4);
  348. out.writeIntBigEndian (8 + pngData.getDataSize());
  349. out << pngData;
  350. }
  351. void writeIcnsFile (const Array<Image>& images, OutputStream& out) const
  352. {
  353. MemoryOutputStream data;
  354. for (int i = 0; i < images.size(); ++i)
  355. {
  356. const Image image (fixMacIconImageSize (images.getReference (i)));
  357. jassert (image.getWidth() == image.getHeight());
  358. switch (image.getWidth())
  359. {
  360. case 16: writeOldIconFormat (data, image, "is32", "s8mk"); break;
  361. case 32: writeOldIconFormat (data, image, "il32", "l8mk"); break;
  362. case 48: writeOldIconFormat (data, image, "ih32", "h8mk"); break;
  363. case 128: writeOldIconFormat (data, image, "it32", "t8mk"); break;
  364. case 256: writeNewIconFormat (data, image, "ic08"); break;
  365. case 512: writeNewIconFormat (data, image, "ic09"); break;
  366. case 1024: writeNewIconFormat (data, image, "ic10"); break;
  367. default: break;
  368. }
  369. }
  370. jassert (data.getDataSize() > 0); // no suitable sized images?
  371. out.write ("icns", 4);
  372. out.writeIntBigEndian (data.getDataSize() + 8);
  373. out << data;
  374. }
  375. void createIconFile() const
  376. {
  377. Array<Image> images;
  378. Image bigIcon (getBigIcon());
  379. if (bigIcon.isValid())
  380. images.add (bigIcon);
  381. Image smallIcon (getSmallIcon());
  382. if (smallIcon.isValid())
  383. images.add (smallIcon);
  384. if (images.size() > 0)
  385. {
  386. MemoryOutputStream mo;
  387. writeIcnsFile (images, mo);
  388. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  389. overwriteFileIfDifferentOrThrow (iconFile, mo);
  390. }
  391. }
  392. void writeInfoPlistFile() const
  393. {
  394. if (! xcodeCreatePList)
  395. return;
  396. ScopedPointer<XmlElement> plist (XmlDocument::parse (getPListToMergeString()));
  397. if (plist == nullptr || ! plist->hasTagName ("plist"))
  398. plist = new XmlElement ("plist");
  399. XmlElement* dict = plist->getChildByName ("dict");
  400. if (dict == nullptr)
  401. dict = plist->createNewChildElement ("dict");
  402. if (iOS)
  403. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  404. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  405. addPlistDictionaryKey (dict, "CFBundleIconFile", iconFile.exists() ? iconFile.getFileName() : String::empty);
  406. addPlistDictionaryKey (dict, "CFBundleIdentifier", project.getBundleIdentifier().toString());
  407. addPlistDictionaryKey (dict, "CFBundleName", projectName);
  408. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  409. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  410. addPlistDictionaryKey (dict, "CFBundleShortVersionString", project.getVersionString());
  411. addPlistDictionaryKey (dict, "CFBundleVersion", project.getVersionString());
  412. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", project.getCompanyName().toString());
  413. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  414. StringArray documentExtensions;
  415. documentExtensions.addTokens (replacePreprocessorDefs (getAllPreprocessorDefs(), settings ["documentExtensions"]),
  416. ",", String::empty);
  417. documentExtensions.trim();
  418. documentExtensions.removeEmptyStrings (true);
  419. if (documentExtensions.size() > 0)
  420. {
  421. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  422. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  423. for (int i = 0; i < documentExtensions.size(); ++i)
  424. {
  425. String ex (documentExtensions[i]);
  426. if (ex.startsWithChar ('.'))
  427. ex = ex.substring (1);
  428. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  429. dict2->createNewChildElement ("array")->createNewChildElement ("string")->addTextElement (ex);
  430. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  431. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  432. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  433. }
  434. }
  435. if (settings ["UIFileSharingEnabled"])
  436. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  437. if (settings ["UIStatusBarHidden"])
  438. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  439. for (int i = 0; i < xcodeExtraPListEntries.size(); ++i)
  440. dict->addChildElement (new XmlElement (xcodeExtraPListEntries.getReference(i)));
  441. MemoryOutputStream mo;
  442. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  443. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  444. }
  445. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  446. {
  447. StringArray searchPaths (extraSearchPaths);
  448. searchPaths.addArray (config.getHeaderSearchPaths());
  449. searchPaths.removeDuplicates (false);
  450. return searchPaths;
  451. }
  452. void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths) const
  453. {
  454. jassert (library.getFileNameWithoutExtension().substring (0, 3) == "lib");
  455. flags.add ("-l" + library.getFileNameWithoutExtension().substring (3));
  456. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  457. if (! library.isAbsolute())
  458. {
  459. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  460. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  461. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  462. searchPath = srcRoot + searchPath;
  463. }
  464. librarySearchPaths.add (sanitisePath (searchPath));
  465. }
  466. void getLinkerFlags (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  467. {
  468. if (xcodeIsBundle)
  469. flags.add ("-bundle");
  470. const Array<RelativePath>& extraLibs = config.isDebug() ? xcodeExtraLibrariesDebug
  471. : xcodeExtraLibrariesRelease;
  472. for (int i = 0; i < extraLibs.size(); ++i)
  473. getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
  474. flags.add (replacePreprocessorTokens (config, getExtraLinkerFlagsString()));
  475. flags.removeEmptyStrings (true);
  476. }
  477. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  478. {
  479. StringArray s;
  480. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  481. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  482. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  483. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  484. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  485. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  486. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  487. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  488. s.add ("WARNING_CFLAGS = -Wreorder");
  489. s.add ("GCC_MODEL_TUNING = G5");
  490. if (projectType.isLibrary())
  491. {
  492. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  493. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  494. }
  495. else
  496. {
  497. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  498. }
  499. if (iOS)
  500. {
  501. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  502. s.add ("SDKROOT = iphoneos");
  503. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  504. const String iosVersion (config.getiOSCompatibilityVersion());
  505. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  506. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  507. }
  508. s.add ("ZERO_LINK = NO");
  509. if (xcodeCanUseDwarf)
  510. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  511. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryNameString() + "\"");
  512. return s;
  513. }
  514. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  515. {
  516. StringArray s;
  517. const String arch (config.getMacArchitecture());
  518. if (arch == osxArch_Native) s.add ("ARCHS = \"$(ARCHS_NATIVE)\"");
  519. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  520. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  521. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  522. s.add ("HEADER_SEARCH_PATHS = \"" + replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" ")) + " $(inherited)\"");
  523. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  524. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  525. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  526. if (extraFlags.isNotEmpty())
  527. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  528. if (xcodeProductInstallPath.isNotEmpty())
  529. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  530. if (xcodeIsBundle)
  531. {
  532. s.add ("LIBRARY_STYLE = Bundle");
  533. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  534. s.add ("GENERATE_PKGINFO_FILE = YES");
  535. }
  536. if (xcodeOtherRezFlags.isNotEmpty())
  537. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  538. if (projectType.isLibrary())
  539. {
  540. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  541. {
  542. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  543. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  544. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  545. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  546. }
  547. s.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  548. s.add ("DEPLOYMENT_LOCATION = YES");
  549. }
  550. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  551. if (! iOS)
  552. {
  553. const String sdk (config.getMacSDKVersion());
  554. const String sdkCompat (config.getMacCompatibilityVersion());
  555. if (sdk == osxVersion10_5) s.add ("SDKROOT = macosx10.5");
  556. else if (sdk == osxVersion10_6) s.add ("SDKROOT = macosx10.6");
  557. else if (sdk == osxVersion10_7) s.add ("SDKROOT = macosx10.7");
  558. if (sdkCompat == osxVersion10_4) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.4");
  559. else if (sdkCompat == osxVersion10_5) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.5");
  560. else if (sdkCompat == osxVersion10_6) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.6");
  561. else if (sdkCompat == osxVersion10_7) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.7");
  562. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  563. s.add ("SDKROOT_ppc = macosx10.5");
  564. if (xcodeExcludedFiles64Bit.isNotEmpty())
  565. {
  566. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  567. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  568. }
  569. }
  570. s.add ("GCC_VERSION = " + gccVersion);
  571. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  572. if (config.getCppLibType().isNotEmpty())
  573. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  574. {
  575. StringArray linkerFlags, librarySearchPaths;
  576. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  577. if (linkerFlags.size() > 0)
  578. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  579. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  580. librarySearchPaths.removeDuplicates (false);
  581. if (librarySearchPaths.size() > 0)
  582. {
  583. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  584. for (int i = 0; i < librarySearchPaths.size(); ++i)
  585. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  586. s.add (libPaths + ")");
  587. }
  588. }
  589. StringPairArray defines;
  590. if (config.isDebug())
  591. {
  592. defines.set ("_DEBUG", "1");
  593. defines.set ("DEBUG", "1");
  594. if (config.getMacArchitecture() == osxArch_Default
  595. || config.getMacArchitecture().isEmpty())
  596. s.add ("ONLY_ACTIVE_ARCH = YES");
  597. s.add ("COPY_PHASE_STRIP = NO");
  598. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  599. }
  600. else
  601. {
  602. defines.set ("_NDEBUG", "1");
  603. defines.set ("NDEBUG", "1");
  604. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  605. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  606. }
  607. {
  608. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  609. StringArray defsList;
  610. for (int i = 0; i < defines.size(); ++i)
  611. {
  612. String def (defines.getAllKeys()[i]);
  613. const String value (defines.getAllValues()[i]);
  614. if (value.isNotEmpty())
  615. def << "=" << value;
  616. defsList.add (def.quoted());
  617. }
  618. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  619. }
  620. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  621. s.trim();
  622. s.removeEmptyStrings();
  623. s.removeDuplicates (false);
  624. return s;
  625. }
  626. void addFrameworks() const
  627. {
  628. if (! isStaticLibrary())
  629. {
  630. StringArray s (xcodeFrameworks);
  631. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  632. s.trim();
  633. s.removeDuplicates (true);
  634. s.sort (true);
  635. for (int i = 0; i < s.size(); ++i)
  636. addFramework (s[i]);
  637. }
  638. }
  639. //==============================================================================
  640. void writeProjectFile (OutputStream& output) const
  641. {
  642. output << "// !$*UTF8*$!\n{\n"
  643. "\tarchiveVersion = 1;\n"
  644. "\tclasses = {\n\t};\n"
  645. "\tobjectVersion = 46;\n"
  646. "\tobjects = {\n\n";
  647. Array <ValueTree*> objects;
  648. objects.addArray (pbxBuildFiles);
  649. objects.addArray (pbxFileReferences);
  650. objects.addArray (pbxGroups);
  651. objects.addArray (targetConfigs);
  652. objects.addArray (projectConfigs);
  653. objects.addArray (misc);
  654. for (int i = 0; i < objects.size(); ++i)
  655. {
  656. ValueTree& o = *objects.getUnchecked(i);
  657. output << "\t\t" << o.getType().toString() << " = { ";
  658. for (int j = 0; j < o.getNumProperties(); ++j)
  659. {
  660. const Identifier propertyName (o.getPropertyName(j));
  661. String val (o.getProperty (propertyName).toString());
  662. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_\r\n")
  663. && ! (val.trimStart().startsWithChar ('(')
  664. || val.trimStart().startsWithChar ('{'))))
  665. val = val.quoted();
  666. output << propertyName.toString() << " = " << val << "; ";
  667. }
  668. output << "};\n";
  669. }
  670. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  671. }
  672. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  673. {
  674. forEachXmlChildElementWithTagName (*xml, e, "key")
  675. {
  676. if (e->getAllSubText().trim().equalsIgnoreCase (key))
  677. {
  678. if (e->getNextElement() != nullptr && e->getNextElement()->hasTagName ("key"))
  679. {
  680. // try to fix broken plist format..
  681. xml->removeChildElement (e, true);
  682. break;
  683. }
  684. else
  685. {
  686. return; // (value already exists)
  687. }
  688. }
  689. }
  690. xml->createNewChildElement ("key") ->addTextElement (key);
  691. xml->createNewChildElement ("string")->addTextElement (value);
  692. }
  693. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  694. {
  695. xml->createNewChildElement ("key")->addTextElement (key);
  696. xml->createNewChildElement (value ? "true" : "false");
  697. }
  698. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  699. {
  700. String fileID (createID (path + "buildref"));
  701. if (addToSourceBuildPhase)
  702. sourceIDs.add (fileID);
  703. ValueTree* v = new ValueTree (fileID);
  704. v->setProperty ("isa", "PBXBuildFile", 0);
  705. v->setProperty ("fileRef", fileRefID, 0);
  706. if (inhibitWarnings)
  707. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", 0);
  708. pbxBuildFiles.add (v);
  709. return fileID;
  710. }
  711. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  712. {
  713. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  714. }
  715. String addFileReference (String pathString) const
  716. {
  717. String sourceTree ("SOURCE_ROOT");
  718. RelativePath path (pathString, RelativePath::unknown);
  719. if (pathString.startsWith ("${"))
  720. {
  721. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  722. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  723. }
  724. else if (path.isAbsolute())
  725. {
  726. sourceTree = "<absolute>";
  727. }
  728. const String fileRefID (createFileRefID (pathString));
  729. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  730. v->setProperty ("isa", "PBXFileReference", 0);
  731. v->setProperty ("lastKnownFileType", getFileType (path), 0);
  732. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), 0);
  733. v->setProperty ("path", sanitisePath (pathString), 0);
  734. v->setProperty ("sourceTree", sourceTree, 0);
  735. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  736. if (existing >= 0)
  737. {
  738. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  739. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  740. }
  741. else
  742. {
  743. pbxFileReferences.addSorted (*this, v.release());
  744. }
  745. return fileRefID;
  746. }
  747. public:
  748. static int compareElements (const ValueTree* first, const ValueTree* second)
  749. {
  750. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  751. }
  752. private:
  753. static String getFileType (const RelativePath& file)
  754. {
  755. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  756. else if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  757. else if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  758. else if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  759. else if (file.hasFileExtension (".framework")) return "wrapper.framework";
  760. else if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  761. else if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  762. else if (file.hasFileExtension ("html;htm")) return "text.html";
  763. else if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  764. else if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  765. else if (file.hasFileExtension ("plist")) return "text.plist.xml";
  766. else if (file.hasFileExtension ("app")) return "wrapper.application";
  767. else if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  768. else if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  769. else if (file.hasFileExtension ("a")) return "archive.ar";
  770. return "file" + file.getFileExtension();
  771. }
  772. String addFile (const RelativePath& path, bool shouldBeCompiled, bool inhibitWarnings) const
  773. {
  774. const String pathAsString (path.toUnixStyle());
  775. const String refID (addFileReference (path.toUnixStyle()));
  776. if (shouldBeCompiled)
  777. {
  778. if (path.hasFileExtension (".r"))
  779. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  780. else
  781. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  782. }
  783. return refID;
  784. }
  785. String addProjectItem (const Project::Item& projectItem) const
  786. {
  787. if (projectItem.isGroup())
  788. {
  789. StringArray childIDs;
  790. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  791. {
  792. const String childID (addProjectItem (projectItem.getChild(i)));
  793. if (childID.isNotEmpty())
  794. childIDs.add (childID);
  795. }
  796. return addGroup (projectItem, childIDs);
  797. }
  798. else
  799. {
  800. if (projectItem.shouldBeAddedToTargetProject())
  801. {
  802. String itemPath (projectItem.getFilePath());
  803. bool inhibitWarnings = projectItem.shouldInhibitWarnings();
  804. if (itemPath.startsWith ("${"))
  805. {
  806. const RelativePath path (itemPath, RelativePath::unknown);
  807. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  808. }
  809. else
  810. {
  811. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  812. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  813. }
  814. }
  815. }
  816. return String::empty;
  817. }
  818. void addFramework (const String& frameworkName) const
  819. {
  820. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  821. const String fileRefID (createFileRefID (path));
  822. addFileReference ("${SDKROOT}/" + path);
  823. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  824. frameworkFileIDs.add (fileRefID);
  825. }
  826. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  827. {
  828. ValueTree* v = new ValueTree (groupID);
  829. v->setProperty ("isa", "PBXGroup", 0);
  830. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", 0);
  831. v->setProperty (Ids::name, groupName, 0);
  832. v->setProperty ("sourceTree", "<group>", 0);
  833. pbxGroups.add (v);
  834. }
  835. String addGroup (const Project::Item& item, StringArray& childIDs) const
  836. {
  837. const String groupName (item.getName());
  838. const String groupID (getIDForGroup (item));
  839. addGroup (groupID, groupName, childIDs);
  840. return groupID;
  841. }
  842. void addMainBuildProduct() const
  843. {
  844. jassert (xcodeFileType.isNotEmpty());
  845. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  846. String productName (getConfiguration(0)->getTargetBinaryName().toString());
  847. if (xcodeFileType == "archive.ar")
  848. productName = getLibbedFilename (productName);
  849. else
  850. productName += xcodeBundleExtension;
  851. addBuildProduct (xcodeFileType, productName);
  852. }
  853. void addBuildProduct (const String& fileType, const String& binaryName) const
  854. {
  855. ValueTree* v = new ValueTree (createID ("__productFileID"));
  856. v->setProperty ("isa", "PBXFileReference", 0);
  857. v->setProperty ("explicitFileType", fileType, 0);
  858. v->setProperty ("includeInIndex", (int) 0, 0);
  859. v->setProperty ("path", sanitisePath (binaryName), 0);
  860. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", 0);
  861. pbxFileReferences.add (v);
  862. }
  863. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  864. {
  865. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  866. v->setProperty ("isa", "XCBuildConfiguration", 0);
  867. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  868. v->setProperty (Ids::name, configName, 0);
  869. targetConfigs.add (v);
  870. }
  871. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  872. {
  873. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  874. v->setProperty ("isa", "XCBuildConfiguration", 0);
  875. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  876. v->setProperty (Ids::name, configName, 0);
  877. projectConfigs.add (v);
  878. }
  879. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  880. {
  881. StringArray configIDs;
  882. for (int i = 0; i < configsToUse.size(); ++i)
  883. configIDs.add (configsToUse[i]->getType().toString());
  884. ValueTree* v = new ValueTree (listID);
  885. v->setProperty ("isa", "XCConfigurationList", 0);
  886. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", 0);
  887. v->setProperty ("defaultConfigurationIsVisible", (int) 0, 0);
  888. if (configsToUse[0] != nullptr)
  889. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), 0);
  890. misc.add (v);
  891. }
  892. ValueTree* addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  893. {
  894. String phaseId (createID (phaseType + "resbuildphase"));
  895. buildPhaseIDs.add (phaseId);
  896. ValueTree* v = new ValueTree (phaseId);
  897. v->setProperty ("isa", phaseType, 0);
  898. v->setProperty ("buildActionMask", "2147483647", 0);
  899. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", 0);
  900. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, 0);
  901. misc.add (v);
  902. return v;
  903. }
  904. void addTargetObject() const
  905. {
  906. ValueTree* const v = new ValueTree (createID ("__target"));
  907. v->setProperty ("isa", "PBXNativeTarget", 0);
  908. v->setProperty ("buildConfigurationList", createID ("__configList"), 0);
  909. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", 0);
  910. v->setProperty ("buildRules", "( )", 0);
  911. v->setProperty ("dependencies", "( )", 0);
  912. v->setProperty (Ids::name, projectName, 0);
  913. v->setProperty ("productName", projectName, 0);
  914. v->setProperty ("productReference", createID ("__productFileID"), 0);
  915. if (xcodeProductInstallPath.isNotEmpty())
  916. v->setProperty ("productInstallPath", xcodeProductInstallPath, 0);
  917. jassert (xcodeProductType.isNotEmpty());
  918. v->setProperty ("productType", xcodeProductType, 0);
  919. misc.add (v);
  920. }
  921. void addProjectObject() const
  922. {
  923. ValueTree* const v = new ValueTree (createID ("__root"));
  924. v->setProperty ("isa", "PBXProject", 0);
  925. v->setProperty ("buildConfigurationList", createID ("__projList"), 0);
  926. v->setProperty ("compatibilityVersion", "Xcode 3.2", 0);
  927. v->setProperty ("hasScannedForEncodings", (int) 0, 0);
  928. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), 0);
  929. v->setProperty ("projectDirPath", "\"\"", 0);
  930. v->setProperty ("projectRoot", "\"\"", 0);
  931. v->setProperty ("targets", "( " + createID ("__target") + " )", 0);
  932. misc.add (v);
  933. }
  934. void addShellScriptPhase() const
  935. {
  936. if (getPostBuildScript().isNotEmpty())
  937. {
  938. ValueTree* const v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  939. v->setProperty (Ids::name, "Post-build script", 0);
  940. v->setProperty ("shellPath", "/bin/sh", 0);
  941. v->setProperty ("shellScript", getPostBuildScript().replace ("\\", "\\\\")
  942. .replace ("\"", "\\\"")
  943. .replace ("\r\n", "\\n")
  944. .replace ("\n", "\\n"), 0);
  945. }
  946. }
  947. //==============================================================================
  948. static String indentList (const StringArray& list, const String& separator)
  949. {
  950. if (list.size() == 0)
  951. return " ";
  952. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  953. + (separator == ";" ? separator : String::empty);
  954. }
  955. String createID (String rootString) const
  956. {
  957. if (rootString.startsWith ("${"))
  958. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  959. rootString += project.getProjectUID();
  960. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  961. }
  962. String createFileRefID (const RelativePath& path) const
  963. {
  964. return createFileRefID (path.toUnixStyle());
  965. }
  966. String createFileRefID (const String& path) const
  967. {
  968. return createID ("__fileref_" + path);
  969. }
  970. String getIDForGroup (const Project::Item& item) const
  971. {
  972. return createID (item.getID());
  973. }
  974. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  975. {
  976. return file.hasFileExtension (sourceFileExtensions);
  977. }
  978. };
  979. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__