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.

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