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.

1384 lines
57KB

  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. createiOSAssetsFolder();
  247. }
  248. else
  249. {
  250. MemoryOutputStream nib;
  251. nib.write (BinaryData::RecentFilesMenuTemplate_nib, BinaryData::RecentFilesMenuTemplate_nibSize);
  252. overwriteFileIfDifferentOrThrow (menuNibFile, nib);
  253. RelativePath menuNibPath (menuNibFile, getTargetFolder(), RelativePath::buildTargetFolder);
  254. addFileReference (menuNibPath.toUnixStyle());
  255. resourceIDs.add (addBuildFile (menuNibPath, false, false));
  256. resourceFileRefs.add (createFileRefID (menuNibPath));
  257. }
  258. if (iconFile.exists())
  259. {
  260. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  261. addFileReference (iconPath.toUnixStyle());
  262. resourceIDs.add (addBuildFile (iconPath, false, false));
  263. resourceFileRefs.add (createFileRefID (iconPath));
  264. }
  265. {
  266. StringArray topLevelGroupIDs;
  267. for (int i = 0; i < getAllGroups().size(); ++i)
  268. {
  269. const Project::Item& group = getAllGroups().getReference(i);
  270. if (group.getNumChildren() > 0)
  271. topLevelGroupIDs.add (addProjectItem (group));
  272. }
  273. { // Add 'resources' group
  274. String resourcesGroupID (createID ("__resources"));
  275. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  276. topLevelGroupIDs.add (resourcesGroupID);
  277. }
  278. { // Add 'frameworks' group
  279. String frameworksGroupID (createID ("__frameworks"));
  280. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  281. topLevelGroupIDs.add (frameworksGroupID);
  282. }
  283. { // Add 'products' group
  284. String productsGroupID (createID ("__products"));
  285. StringArray products;
  286. products.add (createID ("__productFileID"));
  287. addGroup (productsGroupID, "Products", products);
  288. topLevelGroupIDs.add (productsGroupID);
  289. }
  290. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  291. }
  292. for (ConstConfigIterator config (*this); config.next();)
  293. {
  294. const XcodeBuildConfiguration& xcodeConfig = dynamic_cast <const XcodeBuildConfiguration&> (*config);
  295. addProjectConfig (config->getName(), getProjectSettings (xcodeConfig));
  296. addTargetConfig (config->getName(), getTargetSettings (xcodeConfig));
  297. }
  298. addConfigList (projectConfigs, createID ("__projList"));
  299. addConfigList (targetConfigs, createID ("__configList"));
  300. addShellScriptBuildPhase ("Pre-build script", getPreBuildScript());
  301. if (! projectType.isStaticLibrary())
  302. addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  303. if (rezFileIDs.size() > 0)
  304. addBuildPhase ("PBXRezBuildPhase", rezFileIDs);
  305. addBuildPhase ("PBXSourcesBuildPhase", sourceIDs);
  306. if (! projectType.isStaticLibrary())
  307. addBuildPhase ("PBXFrameworksBuildPhase", frameworkIDs);
  308. addShellScriptBuildPhase ("Post-build script", getPostBuildScript());
  309. addTargetObject();
  310. addProjectObject();
  311. }
  312. static Image fixMacIconImageSize (Drawable& image)
  313. {
  314. const int validSizes[] = { 16, 32, 48, 128, 256, 512, 1024 };
  315. const int w = image.getWidth();
  316. const int h = image.getHeight();
  317. int bestSize = 16;
  318. for (int i = 0; i < numElementsInArray (validSizes); ++i)
  319. {
  320. if (w == h && w == validSizes[i])
  321. {
  322. bestSize = w;
  323. break;
  324. }
  325. if (jmax (w, h) > validSizes[i])
  326. bestSize = validSizes[i];
  327. }
  328. return rescaleImageForIcon (image, bestSize);
  329. }
  330. static void writeOldIconFormat (MemoryOutputStream& out, const Image& image, const char* type, const char* maskType)
  331. {
  332. const int w = image.getWidth();
  333. const int h = image.getHeight();
  334. out.write (type, 4);
  335. out.writeIntBigEndian (8 + 4 * w * h);
  336. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  337. for (int y = 0; y < h; ++y)
  338. {
  339. for (int x = 0; x < w; ++x)
  340. {
  341. const Colour pixel (bitmap.getPixelColour (x, y));
  342. out.writeByte ((char) pixel.getAlpha());
  343. out.writeByte ((char) pixel.getRed());
  344. out.writeByte ((char) pixel.getGreen());
  345. out.writeByte ((char) pixel.getBlue());
  346. }
  347. }
  348. out.write (maskType, 4);
  349. out.writeIntBigEndian (8 + w * h);
  350. for (int y = 0; y < h; ++y)
  351. {
  352. for (int x = 0; x < w; ++x)
  353. {
  354. const Colour pixel (bitmap.getPixelColour (x, y));
  355. out.writeByte ((char) pixel.getAlpha());
  356. }
  357. }
  358. }
  359. static void writeNewIconFormat (MemoryOutputStream& out, const Image& image, const char* type)
  360. {
  361. MemoryOutputStream pngData;
  362. PNGImageFormat pngFormat;
  363. pngFormat.writeImageToStream (image, pngData);
  364. out.write (type, 4);
  365. out.writeIntBigEndian (8 + (int) pngData.getDataSize());
  366. out << pngData;
  367. }
  368. void writeIcnsFile (const OwnedArray<Drawable>& images, OutputStream& out) const
  369. {
  370. MemoryOutputStream data;
  371. int smallest = 0x7fffffff;
  372. Drawable* smallestImage = nullptr;
  373. for (int i = 0; i < images.size(); ++i)
  374. {
  375. const Image image (fixMacIconImageSize (*images.getUnchecked(i)));
  376. jassert (image.getWidth() == image.getHeight());
  377. if (image.getWidth() < smallest)
  378. {
  379. smallest = image.getWidth();
  380. smallestImage = images.getUnchecked(i);
  381. }
  382. switch (image.getWidth())
  383. {
  384. case 16: writeOldIconFormat (data, image, "is32", "s8mk"); break;
  385. case 32: writeOldIconFormat (data, image, "il32", "l8mk"); break;
  386. case 48: writeOldIconFormat (data, image, "ih32", "h8mk"); break;
  387. case 128: writeOldIconFormat (data, image, "it32", "t8mk"); break;
  388. case 256: writeNewIconFormat (data, image, "ic08"); break;
  389. case 512: writeNewIconFormat (data, image, "ic09"); break;
  390. case 1024: writeNewIconFormat (data, image, "ic10"); break;
  391. default: break;
  392. }
  393. }
  394. jassert (data.getDataSize() > 0); // no suitable sized images?
  395. // If you only supply a 1024 image, the file doesn't work on 10.8, so we need
  396. // to force a smaller one in there too..
  397. if (smallest > 512 && smallestImage != nullptr)
  398. writeNewIconFormat (data, rescaleImageForIcon (*smallestImage, 512), "ic09");
  399. out.write ("icns", 4);
  400. out.writeIntBigEndian ((int) data.getDataSize() + 8);
  401. out << data;
  402. }
  403. void createIconFile() const
  404. {
  405. OwnedArray<Drawable> images;
  406. ScopedPointer<Drawable> bigIcon (getBigIcon());
  407. if (bigIcon != nullptr)
  408. images.add (bigIcon.release());
  409. ScopedPointer<Drawable> smallIcon (getSmallIcon());
  410. if (smallIcon != nullptr)
  411. images.add (smallIcon.release());
  412. if (images.size() > 0)
  413. {
  414. MemoryOutputStream mo;
  415. writeIcnsFile (images, mo);
  416. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  417. overwriteFileIfDifferentOrThrow (iconFile, mo);
  418. }
  419. }
  420. void writeInfoPlistFile() const
  421. {
  422. if (! xcodeCreatePList)
  423. return;
  424. ScopedPointer<XmlElement> plist (XmlDocument::parse (getPListToMergeString()));
  425. if (plist == nullptr || ! plist->hasTagName ("plist"))
  426. plist = new XmlElement ("plist");
  427. XmlElement* dict = plist->getChildByName ("dict");
  428. if (dict == nullptr)
  429. dict = plist->createNewChildElement ("dict");
  430. if (iOS)
  431. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  432. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  433. addPlistDictionaryKey (dict, "CFBundleIconFile", iconFile.exists() ? iconFile.getFileName() : String::empty);
  434. addPlistDictionaryKey (dict, "CFBundleIdentifier", project.getBundleIdentifier().toString());
  435. addPlistDictionaryKey (dict, "CFBundleName", projectName);
  436. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  437. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  438. addPlistDictionaryKey (dict, "CFBundleShortVersionString", project.getVersionString());
  439. addPlistDictionaryKey (dict, "CFBundleVersion", project.getVersionString());
  440. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", project.getCompanyName().toString());
  441. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  442. StringArray documentExtensions;
  443. documentExtensions.addTokens (replacePreprocessorDefs (getAllPreprocessorDefs(), settings ["documentExtensions"]),
  444. ",", String::empty);
  445. documentExtensions.trim();
  446. documentExtensions.removeEmptyStrings (true);
  447. if (documentExtensions.size() > 0)
  448. {
  449. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  450. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  451. XmlElement* arrayTag = nullptr;
  452. for (int i = 0; i < documentExtensions.size(); ++i)
  453. {
  454. String ex (documentExtensions[i]);
  455. if (ex.startsWithChar ('.'))
  456. ex = ex.substring (1);
  457. if (arrayTag == nullptr)
  458. {
  459. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  460. arrayTag = dict2->createNewChildElement ("array");
  461. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  462. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  463. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  464. }
  465. arrayTag->createNewChildElement ("string")->addTextElement (ex);
  466. }
  467. }
  468. if (settings ["UIFileSharingEnabled"])
  469. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  470. if (settings ["UIStatusBarHidden"])
  471. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  472. for (int i = 0; i < xcodeExtraPListEntries.size(); ++i)
  473. dict->addChildElement (new XmlElement (xcodeExtraPListEntries.getReference(i)));
  474. MemoryOutputStream mo;
  475. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  476. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  477. }
  478. String getHeaderSearchPaths (const BuildConfiguration& config) const
  479. {
  480. StringArray paths (extraSearchPaths);
  481. paths.addArray (config.getHeaderSearchPaths());
  482. paths.add ("$(inherited)");
  483. paths.removeDuplicates (false);
  484. paths.removeEmptyStrings();
  485. for (int i = 0; i < paths.size(); ++i)
  486. {
  487. String& s = paths.getReference(i);
  488. s = replacePreprocessorTokens (config, s);
  489. if (s.containsChar (' '))
  490. s = "\"\\\"" + s + "\\\"\""; // crazy double quotes required when there are spaces..
  491. else
  492. s = "\"" + s + "\"";
  493. }
  494. return "(" + paths.joinIntoString (", ") + ")";
  495. }
  496. void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths) const
  497. {
  498. jassert (library.getFileNameWithoutExtension().substring (0, 3) == "lib");
  499. flags.add ("-l" + library.getFileNameWithoutExtension().substring (3));
  500. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  501. if (! library.isAbsolute())
  502. {
  503. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  504. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  505. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  506. searchPath = srcRoot + searchPath;
  507. }
  508. librarySearchPaths.add (sanitisePath (searchPath));
  509. }
  510. void getLinkerFlags (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  511. {
  512. if (xcodeIsBundle)
  513. flags.add ("-bundle");
  514. const Array<RelativePath>& extraLibs = config.isDebug() ? xcodeExtraLibrariesDebug
  515. : xcodeExtraLibrariesRelease;
  516. for (int i = 0; i < extraLibs.size(); ++i)
  517. getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
  518. flags.add (replacePreprocessorTokens (config, getExtraLinkerFlagsString()));
  519. flags.add (getExternalLibraryFlags (config));
  520. flags.removeEmptyStrings (true);
  521. }
  522. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  523. {
  524. StringArray s;
  525. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  526. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  527. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  528. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  529. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  530. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  531. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  532. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  533. s.add ("WARNING_CFLAGS = -Wreorder");
  534. s.add ("GCC_MODEL_TUNING = G5");
  535. if (projectType.isStaticLibrary())
  536. {
  537. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  538. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  539. }
  540. else
  541. {
  542. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  543. }
  544. if (config.isDebug())
  545. if (config.getMacArchitecture() == osxArch_Default || config.getMacArchitecture().isEmpty())
  546. s.add ("ONLY_ACTIVE_ARCH = YES");
  547. if (iOS)
  548. {
  549. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  550. s.add ("SDKROOT = iphoneos");
  551. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  552. const String iosVersion (config.getiOSCompatibilityVersion());
  553. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  554. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  555. }
  556. s.add ("ZERO_LINK = NO");
  557. if (xcodeCanUseDwarf)
  558. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  559. s.add ("PRODUCT_NAME = \"" + replacePreprocessorTokens (config, config.getTargetBinaryNameString()) + "\"");
  560. return s;
  561. }
  562. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  563. {
  564. StringArray s;
  565. const String arch (config.getMacArchitecture());
  566. if (arch == osxArch_Native) s.add ("ARCHS = \"$(NATIVE_ARCH_ACTUAL)\"");
  567. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  568. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  569. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  570. s.add ("HEADER_SEARCH_PATHS = " + getHeaderSearchPaths (config));
  571. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  572. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  573. if (config.isLinkTimeOptimisationEnabled())
  574. s.add ("LLVM_LTO = YES");
  575. if (config.isFastMathEnabled())
  576. s.add ("GCC_FAST_MATH = YES");
  577. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  578. if (extraFlags.isNotEmpty())
  579. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  580. if (xcodeProductInstallPath.isNotEmpty())
  581. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  582. if (xcodeIsBundle)
  583. {
  584. s.add ("LIBRARY_STYLE = Bundle");
  585. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  586. s.add ("GENERATE_PKGINFO_FILE = YES");
  587. }
  588. if (xcodeOtherRezFlags.isNotEmpty())
  589. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  590. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  591. {
  592. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  593. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  594. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  595. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  596. }
  597. else
  598. {
  599. s.add ("CONFIGURATION_BUILD_DIR = \"$(PROJECT_DIR)/build/$(CONFIGURATION)\"");
  600. }
  601. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  602. if (iOS)
  603. {
  604. s.add ("ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon");
  605. s.add ("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage");
  606. }
  607. else
  608. {
  609. const String sdk (config.getMacSDKVersion());
  610. const String sdkCompat (config.getMacCompatibilityVersion());
  611. for (int ver = oldestSDKVersion; ver <= currentSDKVersion; ++ver)
  612. {
  613. if (sdk == getSDKName (ver)) s.add ("SDKROOT = macosx10." + String (ver));
  614. if (sdkCompat == getSDKName (ver)) s.add ("MACOSX_DEPLOYMENT_TARGET = 10." + String (ver));
  615. }
  616. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  617. s.add ("SDKROOT_ppc = macosx10.5");
  618. if (xcodeExcludedFiles64Bit.isNotEmpty())
  619. {
  620. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  621. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  622. }
  623. }
  624. s.add ("GCC_VERSION = " + gccVersion);
  625. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  626. s.add ("CLANG_LINK_OBJC_RUNTIME = NO");
  627. if (config.getCodeSignIdentity().isNotEmpty())
  628. s.add ("CODE_SIGN_IDENTITY = " + config.getCodeSignIdentity().quoted());
  629. if (config.getCppLibType().isNotEmpty())
  630. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  631. s.add ("COMBINE_HIDPI_IMAGES = YES");
  632. {
  633. StringArray linkerFlags, librarySearchPaths;
  634. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  635. if (linkerFlags.size() > 0)
  636. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  637. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  638. librarySearchPaths.removeDuplicates (false);
  639. if (librarySearchPaths.size() > 0)
  640. {
  641. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  642. for (int i = 0; i < librarySearchPaths.size(); ++i)
  643. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  644. s.add (libPaths + ")");
  645. }
  646. }
  647. StringPairArray defines;
  648. if (config.isDebug())
  649. {
  650. defines.set ("_DEBUG", "1");
  651. defines.set ("DEBUG", "1");
  652. s.add ("COPY_PHASE_STRIP = NO");
  653. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  654. }
  655. else
  656. {
  657. defines.set ("_NDEBUG", "1");
  658. defines.set ("NDEBUG", "1");
  659. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  660. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  661. s.add ("DEAD_CODE_STRIPPING = YES");
  662. }
  663. {
  664. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  665. StringArray defsList;
  666. for (int i = 0; i < defines.size(); ++i)
  667. {
  668. String def (defines.getAllKeys()[i]);
  669. const String value (defines.getAllValues()[i]);
  670. if (value.isNotEmpty())
  671. def << "=" << value.replace ("\"", "\\\"");
  672. defsList.add ("\"" + def + "\"");
  673. }
  674. s.add ("GCC_PREPROCESSOR_DEFINITIONS = " + indentParenthesisedList (defsList));
  675. }
  676. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  677. s.trim();
  678. s.removeEmptyStrings();
  679. s.removeDuplicates (false);
  680. return s;
  681. }
  682. void addFrameworks() const
  683. {
  684. if (! projectType.isStaticLibrary())
  685. {
  686. StringArray s (xcodeFrameworks);
  687. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  688. if (project.getConfigFlag ("JUCE_QUICKTIME") == Project::configFlagDisabled)
  689. s.removeString ("QuickTime");
  690. s.trim();
  691. s.removeDuplicates (true);
  692. s.sort (true);
  693. for (int i = 0; i < s.size(); ++i)
  694. addFramework (s[i]);
  695. }
  696. }
  697. //==============================================================================
  698. void writeProjectFile (OutputStream& output) const
  699. {
  700. output << "// !$*UTF8*$!\n{\n"
  701. "\tarchiveVersion = 1;\n"
  702. "\tclasses = {\n\t};\n"
  703. "\tobjectVersion = 46;\n"
  704. "\tobjects = {\n\n";
  705. Array <ValueTree*> objects;
  706. objects.addArray (pbxBuildFiles);
  707. objects.addArray (pbxFileReferences);
  708. objects.addArray (pbxGroups);
  709. objects.addArray (targetConfigs);
  710. objects.addArray (projectConfigs);
  711. objects.addArray (misc);
  712. for (int i = 0; i < objects.size(); ++i)
  713. {
  714. ValueTree& o = *objects.getUnchecked(i);
  715. output << "\t\t" << o.getType().toString() << " = {";
  716. for (int j = 0; j < o.getNumProperties(); ++j)
  717. {
  718. const Identifier propertyName (o.getPropertyName(j));
  719. String val (o.getProperty (propertyName).toString());
  720. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n")
  721. && ! (val.trimStart().startsWithChar ('(')
  722. || val.trimStart().startsWithChar ('{'))))
  723. val = "\"" + val + "\"";
  724. output << propertyName.toString() << " = " << val << "; ";
  725. }
  726. output << "};\n";
  727. }
  728. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  729. }
  730. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  731. {
  732. String fileID (createID (path + "buildref"));
  733. if (addToSourceBuildPhase)
  734. sourceIDs.add (fileID);
  735. ValueTree* v = new ValueTree (fileID);
  736. v->setProperty ("isa", "PBXBuildFile", nullptr);
  737. v->setProperty ("fileRef", fileRefID, nullptr);
  738. if (inhibitWarnings)
  739. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  740. pbxBuildFiles.add (v);
  741. return fileID;
  742. }
  743. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  744. {
  745. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  746. }
  747. String addFileReference (String pathString) const
  748. {
  749. String sourceTree ("SOURCE_ROOT");
  750. RelativePath path (pathString, RelativePath::unknown);
  751. if (pathString.startsWith ("${"))
  752. {
  753. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  754. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  755. }
  756. else if (path.isAbsolute())
  757. {
  758. sourceTree = "<absolute>";
  759. }
  760. const String fileRefID (createFileRefID (pathString));
  761. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  762. v->setProperty ("isa", "PBXFileReference", nullptr);
  763. v->setProperty ("lastKnownFileType", getFileType (path), nullptr);
  764. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  765. v->setProperty ("path", sanitisePath (pathString), nullptr);
  766. v->setProperty ("sourceTree", sourceTree, nullptr);
  767. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  768. if (existing >= 0)
  769. {
  770. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  771. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  772. }
  773. else
  774. {
  775. pbxFileReferences.addSorted (*this, v.release());
  776. }
  777. return fileRefID;
  778. }
  779. public:
  780. static int compareElements (const ValueTree* first, const ValueTree* second)
  781. {
  782. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  783. }
  784. private:
  785. static String getFileType (const RelativePath& file)
  786. {
  787. if (file.hasFileExtension (cppFileExtensions)) return "sourcecode.cpp.cpp";
  788. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  789. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  790. if (file.hasFileExtension (".c")) return "sourcecode.c.c";
  791. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  792. if (file.hasFileExtension (asmFileExtensions)) return "sourcecode.c.asm";
  793. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  794. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  795. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  796. if (file.hasFileExtension ("html;htm")) return "text.html";
  797. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  798. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  799. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  800. if (file.hasFileExtension ("app")) return "wrapper.application";
  801. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  802. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  803. if (file.hasFileExtension ("a")) return "archive.ar";
  804. if (file.hasFileExtension ("xcassets")) return "folder.assetcatalog";
  805. return "file" + file.getFileExtension();
  806. }
  807. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources, bool inhibitWarnings) const
  808. {
  809. const String pathAsString (path.toUnixStyle());
  810. const String refID (addFileReference (path.toUnixStyle()));
  811. if (shouldBeCompiled)
  812. {
  813. if (path.hasFileExtension (".r"))
  814. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  815. else
  816. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  817. }
  818. else if (! shouldBeAddedToBinaryResources)
  819. {
  820. const String fileType (getFileType (path));
  821. if (fileType.startsWith ("image.") || fileType.startsWith ("text.") || fileType.startsWith ("file."))
  822. {
  823. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  824. resourceFileRefs.add (refID);
  825. }
  826. }
  827. return refID;
  828. }
  829. String addProjectItem (const Project::Item& projectItem) const
  830. {
  831. if (projectItem.isGroup())
  832. {
  833. StringArray childIDs;
  834. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  835. {
  836. const String childID (addProjectItem (projectItem.getChild(i)));
  837. if (childID.isNotEmpty())
  838. childIDs.add (childID);
  839. }
  840. return addGroup (projectItem, childIDs);
  841. }
  842. if (projectItem.shouldBeAddedToTargetProject())
  843. {
  844. const String itemPath (projectItem.getFilePath());
  845. RelativePath path;
  846. if (itemPath.startsWith ("${"))
  847. path = RelativePath (itemPath, RelativePath::unknown);
  848. else
  849. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  850. return addFile (path, projectItem.shouldBeCompiled(),
  851. projectItem.shouldBeAddedToBinaryResources(),
  852. projectItem.shouldInhibitWarnings());
  853. }
  854. return String::empty;
  855. }
  856. void addFramework (const String& frameworkName) const
  857. {
  858. String path (frameworkName);
  859. if (! File::isAbsolutePath (path))
  860. path = "System/Library/Frameworks/" + path;
  861. if (! path.endsWithIgnoreCase (".framework"))
  862. path << ".framework";
  863. const String fileRefID (createFileRefID (path));
  864. addFileReference ((File::isAbsolutePath (frameworkName) ? "" : "${SDKROOT}/") + path);
  865. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  866. frameworkFileIDs.add (fileRefID);
  867. }
  868. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  869. {
  870. ValueTree* v = new ValueTree (groupID);
  871. v->setProperty ("isa", "PBXGroup", nullptr);
  872. v->setProperty ("children", indentParenthesisedList (childIDs), nullptr);
  873. v->setProperty (Ids::name, groupName, nullptr);
  874. v->setProperty ("sourceTree", "<group>", nullptr);
  875. pbxGroups.add (v);
  876. }
  877. String addGroup (const Project::Item& item, StringArray& childIDs) const
  878. {
  879. const String groupName (item.getName());
  880. const String groupID (getIDForGroup (item));
  881. addGroup (groupID, groupName, childIDs);
  882. return groupID;
  883. }
  884. void addMainBuildProduct() const
  885. {
  886. jassert (xcodeFileType.isNotEmpty());
  887. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  888. ProjectExporter::BuildConfiguration::Ptr config = getConfiguration(0);
  889. jassert (config != nullptr);
  890. String productName (replacePreprocessorTokens (*config, config->getTargetBinaryNameString()));
  891. if (xcodeFileType == "archive.ar")
  892. productName = getLibbedFilename (productName);
  893. else
  894. productName += xcodeBundleExtension;
  895. addBuildProduct (xcodeFileType, productName);
  896. }
  897. void addBuildProduct (const String& fileType, const String& binaryName) const
  898. {
  899. ValueTree* v = new ValueTree (createID ("__productFileID"));
  900. v->setProperty ("isa", "PBXFileReference", nullptr);
  901. v->setProperty ("explicitFileType", fileType, nullptr);
  902. v->setProperty ("includeInIndex", (int) 0, nullptr);
  903. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  904. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  905. pbxFileReferences.add (v);
  906. }
  907. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  908. {
  909. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  910. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  911. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  912. v->setProperty (Ids::name, configName, nullptr);
  913. targetConfigs.add (v);
  914. }
  915. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  916. {
  917. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  918. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  919. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  920. v->setProperty (Ids::name, configName, nullptr);
  921. projectConfigs.add (v);
  922. }
  923. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  924. {
  925. StringArray configIDs;
  926. for (int i = 0; i < configsToUse.size(); ++i)
  927. configIDs.add (configsToUse[i]->getType().toString());
  928. ValueTree* v = new ValueTree (listID);
  929. v->setProperty ("isa", "XCConfigurationList", nullptr);
  930. v->setProperty ("buildConfigurations", indentParenthesisedList (configIDs), nullptr);
  931. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  932. if (configsToUse[0] != nullptr)
  933. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), nullptr);
  934. misc.add (v);
  935. }
  936. ValueTree& addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  937. {
  938. String phaseId (createID (phaseType + "resbuildphase"));
  939. int n = 0;
  940. while (buildPhaseIDs.contains (phaseId))
  941. phaseId = createID (phaseType + "resbuildphase" + String (++n));
  942. buildPhaseIDs.add (phaseId);
  943. ValueTree* v = new ValueTree (phaseId);
  944. v->setProperty ("isa", phaseType, nullptr);
  945. v->setProperty ("buildActionMask", "2147483647", nullptr);
  946. v->setProperty ("files", indentParenthesisedList (fileIds), nullptr);
  947. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  948. misc.add (v);
  949. return *v;
  950. }
  951. void addTargetObject() const
  952. {
  953. ValueTree* const v = new ValueTree (createID ("__target"));
  954. v->setProperty ("isa", "PBXNativeTarget", nullptr);
  955. v->setProperty ("buildConfigurationList", createID ("__configList"), nullptr);
  956. v->setProperty ("buildPhases", indentParenthesisedList (buildPhaseIDs), nullptr);
  957. v->setProperty ("buildRules", "( )", nullptr);
  958. v->setProperty ("dependencies", "( )", nullptr);
  959. v->setProperty (Ids::name, projectName, nullptr);
  960. v->setProperty ("productName", projectName, nullptr);
  961. v->setProperty ("productReference", createID ("__productFileID"), nullptr);
  962. if (xcodeProductInstallPath.isNotEmpty())
  963. v->setProperty ("productInstallPath", xcodeProductInstallPath, nullptr);
  964. jassert (xcodeProductType.isNotEmpty());
  965. v->setProperty ("productType", xcodeProductType, nullptr);
  966. misc.add (v);
  967. }
  968. void addProjectObject() const
  969. {
  970. ValueTree* const v = new ValueTree (createID ("__root"));
  971. v->setProperty ("isa", "PBXProject", nullptr);
  972. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  973. v->setProperty ("attributes", "{ LastUpgradeCheck = 0440; }", nullptr);
  974. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  975. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  976. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  977. v->setProperty ("projectDirPath", "\"\"", nullptr);
  978. v->setProperty ("projectRoot", "\"\"", nullptr);
  979. v->setProperty ("targets", "( " + createID ("__target") + " )", nullptr);
  980. misc.add (v);
  981. }
  982. void addShellScriptBuildPhase (const String& phaseName, const String& script) const
  983. {
  984. if (script.trim().isNotEmpty())
  985. {
  986. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  987. v.setProperty (Ids::name, phaseName, nullptr);
  988. v.setProperty ("shellPath", "/bin/sh", nullptr);
  989. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  990. .replace ("\"", "\\\"")
  991. .replace ("\r\n", "\\n")
  992. .replace ("\n", "\\n"), nullptr);
  993. }
  994. }
  995. String getiOSAssetContents (var images) const
  996. {
  997. DynamicObject::Ptr v (new DynamicObject());
  998. var info (new DynamicObject());
  999. info.getDynamicObject()->setProperty ("version", 1);
  1000. info.getDynamicObject()->setProperty ("author", "xcode");
  1001. v->setProperty ("images", images);
  1002. v->setProperty ("info", info);
  1003. return JSON::toString (var (v));
  1004. }
  1005. String getiOSAppIconContents() const
  1006. {
  1007. struct ImageType
  1008. {
  1009. const char* idiom;
  1010. const char* size;
  1011. const char* scale;
  1012. };
  1013. const ImageType types[] = { { "iphone", "29x29", "2x" },
  1014. { "iphone", "40x40", "2x" },
  1015. { "iphone", "60x60", "2x" },
  1016. { "iphone", "60x60", "3x" },
  1017. { "ipad", "29x29", "1x" },
  1018. { "ipad", "29x29", "2x" },
  1019. { "ipad", "40x40", "1x" },
  1020. { "ipad", "40x40", "2x" },
  1021. { "ipad", "76x76", "1x" },
  1022. { "ipad", "76x76", "2x" } };
  1023. var images;
  1024. for (int i = 0; i < numElementsInArray (types); ++i)
  1025. {
  1026. DynamicObject::Ptr d = new DynamicObject();
  1027. d->setProperty ("idiom", types[i].idiom);
  1028. d->setProperty ("size", types[i].size);
  1029. d->setProperty ("scale", types[i].scale);
  1030. images.append (var (d));
  1031. }
  1032. return getiOSAssetContents (images);
  1033. }
  1034. String getiOSLaunchImageContents() const
  1035. {
  1036. struct ImageType
  1037. {
  1038. const char* orientation;
  1039. const char* idiom;
  1040. const char* extent;
  1041. const char* scale;
  1042. };
  1043. const ImageType types[] = { { "portrait", "iphone", "full-screen", "2x" },
  1044. { "portrait", "iphone", "full-screen", "2x" },
  1045. { "portrait", "ipad", "full-screen", "1x" },
  1046. { "landscape", "ipad", "full-screen", "1x" },
  1047. { "portrait", "ipad", "full-screen", "2x" },
  1048. { "landscape", "ipad", "full-screen", "2x" } };
  1049. var images;
  1050. for (int i = 0; i < numElementsInArray (types); ++i)
  1051. {
  1052. DynamicObject::Ptr d = new DynamicObject();
  1053. d->setProperty ("orientation", types[i].orientation);
  1054. d->setProperty ("idiom", types[i].idiom);
  1055. d->setProperty ("extent", types[i].extent);
  1056. d->setProperty ("minimum-system-version", "7.0");
  1057. d->setProperty ("scale", types[i].scale);
  1058. images.append (var (d));
  1059. }
  1060. return getiOSAssetContents (images);
  1061. }
  1062. void createiOSAssetsFolder() const
  1063. {
  1064. File assets (getTargetFolder().getChildFile (project.getProjectFilenameRoot()).getChildFile ("Images.xcassets"));
  1065. overwriteFileIfDifferentOrThrow (assets.getChildFile ("AppIcon.appiconset") .getChildFile ("Contents.json"), getiOSAppIconContents());
  1066. overwriteFileIfDifferentOrThrow (assets.getChildFile ("LaunchImage.launchimage").getChildFile ("Contents.json"), getiOSLaunchImageContents());
  1067. RelativePath assetsPath (assets, getTargetFolder(), RelativePath::buildTargetFolder);
  1068. addFileReference (assetsPath.toUnixStyle());
  1069. resourceIDs.add (addBuildFile (assetsPath, false, false));
  1070. resourceFileRefs.add (createFileRefID (assetsPath));
  1071. }
  1072. //==============================================================================
  1073. static String indentBracedList (const StringArray& list) { return "{" + indentList (list, ";", 0, true) + " }"; }
  1074. static String indentParenthesisedList (const StringArray& list) { return "(" + indentList (list, ",", 1, false) + " )"; }
  1075. static String indentList (const StringArray& list, const String& separator, int extraTabs, bool shouldSort)
  1076. {
  1077. if (list.size() == 0)
  1078. return " ";
  1079. const String tabs ("\n" + String::repeatedString ("\t", extraTabs + 4));
  1080. if (shouldSort)
  1081. {
  1082. StringArray sorted (list);
  1083. sorted.sort (true);
  1084. return tabs + sorted.joinIntoString (separator + tabs) + separator;
  1085. }
  1086. return tabs + list.joinIntoString (separator + tabs) + separator;
  1087. }
  1088. String createID (String rootString) const
  1089. {
  1090. if (rootString.startsWith ("${"))
  1091. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  1092. rootString += project.getProjectUID();
  1093. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  1094. }
  1095. String createFileRefID (const RelativePath& path) const { return createFileRefID (path.toUnixStyle()); }
  1096. String createFileRefID (const String& path) const { return createID ("__fileref_" + path); }
  1097. String getIDForGroup (const Project::Item& item) const { return createID (item.getID()); }
  1098. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  1099. {
  1100. return file.hasFileExtension (sourceFileExtensions);
  1101. }
  1102. static String getSDKName (int version)
  1103. {
  1104. jassert (version >= 4);
  1105. return "10." + String (version) + " SDK";
  1106. }
  1107. };