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.

1282 lines
53KB

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