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.

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