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.

1577 lines
65KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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 = 5;
  21. const int currentSDKVersion = 11;
  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. initialiseDependencyPathValues();
  45. }
  46. static XCodeProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  47. {
  48. if (settings.hasType (getValueTreeTypeName (false))) return new XCodeProjectExporter (project, settings, false);
  49. if (settings.hasType (getValueTreeTypeName (true))) return new XCodeProjectExporter (project, settings, true);
  50. return nullptr;
  51. }
  52. //==============================================================================
  53. Value getPListToMergeValue() { return getSetting ("customPList"); }
  54. String getPListToMergeString() const { return settings ["customPList"]; }
  55. Value getExtraFrameworksValue() { return getSetting (Ids::extraFrameworks); }
  56. String getExtraFrameworksString() const { return settings [Ids::extraFrameworks]; }
  57. Value getPostBuildScriptValue() { return getSetting (Ids::postbuildCommand); }
  58. String getPostBuildScript() const { return settings [Ids::postbuildCommand]; }
  59. Value getPreBuildScriptValue() { return getSetting (Ids::prebuildCommand); }
  60. String getPreBuildScript() const { return settings [Ids::prebuildCommand]; }
  61. bool usesMMFiles() const override { return true; }
  62. bool isXcode() const override { return true; }
  63. bool isOSX() const override { return ! iOS; }
  64. bool canCopeWithDuplicateFiles() override { return true; }
  65. void createExporterProperties (PropertyListBuilder& props) override
  66. {
  67. if (projectType.isGUIApplication() && ! iOS)
  68. {
  69. props.add (new TextPropertyComponent (getSetting ("documentExtensions"), "Document file extensions", 128, false),
  70. "A comma-separated list of file extensions for documents that your app can open. "
  71. "Using a leading '.' is optional, and the extensions are not case-sensitive.");
  72. }
  73. else if (iOS)
  74. {
  75. props.add (new BooleanPropertyComponent (getSetting ("UIFileSharingEnabled"), "File Sharing Enabled", "Enabled"),
  76. "Enable this to expose your app's files to iTunes.");
  77. props.add (new BooleanPropertyComponent (getSetting ("UIStatusBarHidden"), "Status Bar Hidden", "Enabled"),
  78. "Enable this to disable the status bar in your app.");
  79. }
  80. props.add (new TextPropertyComponent (getPListToMergeValue(), "Custom PList", 8192, true),
  81. "You can paste the contents of an XML PList file in here, and the settings that it contains will override any "
  82. "settings that the Introjucer creates. BEWARE! When doing this, be careful to remove from the XML any "
  83. "values that you DO want the introjucer to change!");
  84. props.add (new TextPropertyComponent (getExtraFrameworksValue(), "Extra Frameworks", 2048, false),
  85. "A comma-separated list of extra frameworks that should be added to the build. "
  86. "(Don't include the .framework extension in the name)");
  87. props.add (new TextPropertyComponent (getPreBuildScriptValue(), "Pre-build shell script", 32768, true),
  88. "Some shell-script that will be run before a build starts.");
  89. props.add (new TextPropertyComponent (getPostBuildScriptValue(), "Post-build shell script", 32768, true),
  90. "Some shell-script that will be run after a build completes.");
  91. }
  92. bool launchProject() override
  93. {
  94. #if JUCE_MAC
  95. return getProjectBundle().startAsProcess();
  96. #else
  97. return false;
  98. #endif
  99. }
  100. bool canLaunchProject() override
  101. {
  102. #if JUCE_MAC
  103. return true;
  104. #else
  105. return false;
  106. #endif
  107. }
  108. //==============================================================================
  109. void create (const OwnedArray<LibraryModule>&) const override
  110. {
  111. infoPlistFile = getTargetFolder().getChildFile ("Info.plist");
  112. menuNibFile = getTargetFolder().getChildFile ("RecentFilesMenuTemplate.nib");
  113. createIconFile();
  114. File projectBundle (getProjectBundle());
  115. createDirectoryOrThrow (projectBundle);
  116. createObjects();
  117. File projectFile (projectBundle.getChildFile ("project.pbxproj"));
  118. {
  119. MemoryOutputStream mo;
  120. writeProjectFile (mo);
  121. overwriteFileIfDifferentOrThrow (projectFile, mo);
  122. }
  123. writeInfoPlistFile();
  124. // Deleting the .rsrc files can be needed to force Xcode to update the version number.
  125. deleteRsrcFiles();
  126. }
  127. protected:
  128. //==============================================================================
  129. class XcodeBuildConfiguration : public BuildConfiguration
  130. {
  131. public:
  132. XcodeBuildConfiguration (Project& p, const ValueTree& t, const bool isIOS, const ProjectExporter& e)
  133. : BuildConfiguration (p, t, e), iOS (isIOS)
  134. {
  135. if (iOS)
  136. {
  137. if (getiOSCompatibilityVersion().isEmpty())
  138. getiOSCompatibilityVersionValue() = osxVersionDefault;
  139. }
  140. else
  141. {
  142. if (getMacSDKVersion().isEmpty())
  143. getMacSDKVersionValue() = osxVersionDefault;
  144. if (getMacCompatibilityVersion().isEmpty())
  145. getMacCompatibilityVersionValue() = osxVersionDefault;
  146. if (getMacArchitecture().isEmpty())
  147. getMacArchitectureValue() = osxArch_Default;
  148. }
  149. }
  150. Value getMacSDKVersionValue() { return getValue (Ids::osxSDK); }
  151. String getMacSDKVersion() const { return config [Ids::osxSDK]; }
  152. Value getMacCompatibilityVersionValue() { return getValue (Ids::osxCompatibility); }
  153. String getMacCompatibilityVersion() const { return config [Ids::osxCompatibility]; }
  154. Value getiOSCompatibilityVersionValue() { return getValue (Ids::iosCompatibility); }
  155. String getiOSCompatibilityVersion() const { return config [Ids::iosCompatibility]; }
  156. Value getMacArchitectureValue() { return getValue (Ids::osxArchitecture); }
  157. String getMacArchitecture() const { return config [Ids::osxArchitecture]; }
  158. Value getCustomXcodeFlagsValue() { return getValue (Ids::customXcodeFlags); }
  159. String getCustomXcodeFlags() const { return config [Ids::customXcodeFlags]; }
  160. Value getCppLanguageStandardValue() { return getValue (Ids::cppLanguageStandard); }
  161. String getCppLanguageStandard() const { return config [Ids::cppLanguageStandard]; }
  162. Value getCppLibTypeValue() { return getValue (Ids::cppLibType); }
  163. String getCppLibType() const { return config [Ids::cppLibType]; }
  164. Value getCodeSignIdentityValue() { return getValue (Ids::codeSigningIdentity); }
  165. String getCodeSignIdentity() const { return config [Ids::codeSigningIdentity]; }
  166. Value getFastMathValue() { return getValue (Ids::fastMath); }
  167. bool isFastMathEnabled() const { return config [Ids::fastMath]; }
  168. Value getLinkTimeOptimisationValue() { return getValue (Ids::linkTimeOptimisation); }
  169. bool isLinkTimeOptimisationEnabled() const { return config [Ids::linkTimeOptimisation]; }
  170. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? gccO0 : gccO3)); }
  171. void createConfigProperties (PropertyListBuilder& props) override
  172. {
  173. addGCCOptimisationProperty (props);
  174. if (iOS)
  175. {
  176. const char* iosVersions[] = { "Use Default", "7.0", "7.1", "8.0", "8.1", "8.2", "8.3", "8.4", "9.0", "9.1", "9.2", 0 };
  177. const char* iosVersionValues[] = { osxVersionDefault, "7.0", "7.1", "8.0", "8.1", "8.2", "8.3", "8.4", "9.0", "9.1", "9.2", 0 };
  178. props.add (new ChoicePropertyComponent (getiOSCompatibilityVersionValue(), "iOS Deployment Target",
  179. StringArray (iosVersions), Array<var> (iosVersionValues)),
  180. "The minimum version of iOS that the target binary will run on.");
  181. }
  182. else
  183. {
  184. StringArray sdkVersionNames, osxVersionNames;
  185. Array<var> versionValues;
  186. sdkVersionNames.add ("Use Default");
  187. osxVersionNames.add ("Use Default");
  188. versionValues.add (osxVersionDefault);
  189. for (int ver = oldestSDKVersion; ver <= currentSDKVersion; ++ver)
  190. {
  191. sdkVersionNames.add (getSDKName (ver));
  192. osxVersionNames.add (getOSXVersionName (ver));
  193. versionValues.add (getSDKName (ver));
  194. }
  195. props.add (new ChoicePropertyComponent (getMacSDKVersionValue(), "OSX Base SDK Version", sdkVersionNames, versionValues),
  196. "The version of OSX to link against in the XCode build.");
  197. props.add (new ChoicePropertyComponent (getMacCompatibilityVersionValue(), "OSX Deployment Target", osxVersionNames, versionValues),
  198. "The minimum version of OSX that the target binary will be compatible with.");
  199. const char* osxArch[] = { "Use Default", "Native architecture of build machine",
  200. "Universal Binary (32-bit)", "Universal Binary (32/64-bit)", "64-bit Intel", 0 };
  201. const char* osxArchValues[] = { osxArch_Default, osxArch_Native, osxArch_32BitUniversal,
  202. osxArch_64BitUniversal, osxArch_64Bit, 0 };
  203. props.add (new ChoicePropertyComponent (getMacArchitectureValue(), "OSX Architecture",
  204. StringArray (osxArch), Array<var> (osxArchValues)),
  205. "The type of OSX binary that will be produced.");
  206. }
  207. props.add (new TextPropertyComponent (getCustomXcodeFlagsValue(), "Custom Xcode flags", 8192, false),
  208. "A comma-separated list of custom Xcode setting flags which will be appended to the list of generated flags, "
  209. "e.g. MACOSX_DEPLOYMENT_TARGET_i386 = 10.5, VALID_ARCHS = \"ppc i386 x86_64\"");
  210. const char* cppLanguageStandardNames[] = { "Use Default", "C++98", "GNU++98", "C++11", "GNU++11", "C++14", "GNU++14", nullptr };
  211. Array<var> cppLanguageStandardValues;
  212. cppLanguageStandardValues.add (var::null);
  213. cppLanguageStandardValues.add ("c++98");
  214. cppLanguageStandardValues.add ("gnu++98");
  215. cppLanguageStandardValues.add ("c++11");
  216. cppLanguageStandardValues.add ("gnu++11");
  217. cppLanguageStandardValues.add ("c++14");
  218. cppLanguageStandardValues.add ("gnu++14");
  219. props.add (new ChoicePropertyComponent (getCppLanguageStandardValue(), "C++ Language Standard", StringArray (cppLanguageStandardNames), cppLanguageStandardValues),
  220. "The standard of the C++ language that will be used for compilation.");
  221. const char* cppLibNames[] = { "Use Default", "LLVM libc++", "GNU libstdc++", nullptr };
  222. Array<var> cppLibValues;
  223. cppLibValues.add (var::null);
  224. cppLibValues.add ("libc++");
  225. cppLibValues.add ("libstdc++");
  226. props.add (new ChoicePropertyComponent (getCppLibTypeValue(), "C++ Library", StringArray (cppLibNames), cppLibValues),
  227. "The type of C++ std lib that will be linked.");
  228. props.add (new TextPropertyComponent (getCodeSignIdentityValue(), "Code-signing Identity", 8192, false),
  229. "The name of a code-signing identity for Xcode to apply.");
  230. props.add (new BooleanPropertyComponent (getFastMathValue(), "Relax IEEE compliance", "Enabled"),
  231. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  232. props.add (new BooleanPropertyComponent (getLinkTimeOptimisationValue(), "Link-Time Optimisation", "Enabled"),
  233. "Enable this to perform link-time code generation. This is recommended for release builds.");
  234. }
  235. bool iOS;
  236. };
  237. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  238. {
  239. return new XcodeBuildConfiguration (project, v, iOS, *this);
  240. }
  241. private:
  242. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  243. mutable StringArray buildPhaseIDs, resourceIDs, sourceIDs, frameworkIDs;
  244. mutable StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  245. mutable File infoPlistFile, menuNibFile, iconFile;
  246. const bool iOS;
  247. static String sanitisePath (const String& path)
  248. {
  249. if (path.startsWithChar ('~'))
  250. return "$(HOME)" + path.substring (1);
  251. return path;
  252. }
  253. static String addQuotesIfContainsSpace (const String& s)
  254. {
  255. return s.containsChar (' ') ? s.quoted() : s;
  256. }
  257. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  258. //==============================================================================
  259. void createObjects() const
  260. {
  261. addFrameworks();
  262. addMainBuildProduct();
  263. if (xcodeCreatePList)
  264. {
  265. RelativePath plistPath (infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  266. addFileReference (plistPath.toUnixStyle());
  267. resourceFileRefs.add (createFileRefID (plistPath));
  268. }
  269. if (iOS)
  270. {
  271. if (! projectType.isStaticLibrary())
  272. createiOSAssetsFolder();
  273. }
  274. else
  275. {
  276. MemoryOutputStream nib;
  277. nib.write (BinaryData::RecentFilesMenuTemplate_nib, BinaryData::RecentFilesMenuTemplate_nibSize);
  278. overwriteFileIfDifferentOrThrow (menuNibFile, nib);
  279. RelativePath menuNibPath (menuNibFile, getTargetFolder(), RelativePath::buildTargetFolder);
  280. addFileReference (menuNibPath.toUnixStyle());
  281. resourceIDs.add (addBuildFile (menuNibPath, false, false));
  282. resourceFileRefs.add (createFileRefID (menuNibPath));
  283. }
  284. if (iconFile.exists())
  285. {
  286. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  287. addFileReference (iconPath.toUnixStyle());
  288. resourceIDs.add (addBuildFile (iconPath, false, false));
  289. resourceFileRefs.add (createFileRefID (iconPath));
  290. }
  291. {
  292. StringArray topLevelGroupIDs;
  293. for (int i = 0; i < getAllGroups().size(); ++i)
  294. {
  295. const Project::Item& group = getAllGroups().getReference(i);
  296. if (group.getNumChildren() > 0)
  297. topLevelGroupIDs.add (addProjectItem (group));
  298. }
  299. { // Add 'resources' group
  300. String resourcesGroupID (createID ("__resources"));
  301. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  302. topLevelGroupIDs.add (resourcesGroupID);
  303. }
  304. { // Add 'frameworks' group
  305. String frameworksGroupID (createID ("__frameworks"));
  306. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  307. topLevelGroupIDs.add (frameworksGroupID);
  308. }
  309. { // Add 'products' group
  310. String productsGroupID (createID ("__products"));
  311. StringArray products;
  312. products.add (createID ("__productFileID"));
  313. addGroup (productsGroupID, "Products", products);
  314. topLevelGroupIDs.add (productsGroupID);
  315. }
  316. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  317. }
  318. for (ConstConfigIterator config (*this); config.next();)
  319. {
  320. const XcodeBuildConfiguration& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  321. addProjectConfig (config->getName(), getProjectSettings (xcodeConfig));
  322. addTargetConfig (config->getName(), getTargetSettings (xcodeConfig));
  323. }
  324. addConfigList (projectConfigs, createID ("__projList"));
  325. addConfigList (targetConfigs, createID ("__configList"));
  326. addShellScriptBuildPhase ("Pre-build script", getPreBuildScript());
  327. if (! projectType.isStaticLibrary())
  328. addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  329. if (rezFileIDs.size() > 0)
  330. addBuildPhase ("PBXRezBuildPhase", rezFileIDs);
  331. addBuildPhase ("PBXSourcesBuildPhase", sourceIDs);
  332. if (! projectType.isStaticLibrary())
  333. addBuildPhase ("PBXFrameworksBuildPhase", frameworkIDs);
  334. addShellScriptBuildPhase ("Post-build script", getPostBuildScript());
  335. addTargetObject();
  336. addProjectObject();
  337. }
  338. static Image fixMacIconImageSize (Drawable& image)
  339. {
  340. const int validSizes[] = { 16, 32, 48, 128, 256, 512, 1024 };
  341. const int w = image.getWidth();
  342. const int h = image.getHeight();
  343. int bestSize = 16;
  344. for (int i = 0; i < numElementsInArray (validSizes); ++i)
  345. {
  346. if (w == h && w == validSizes[i])
  347. {
  348. bestSize = w;
  349. break;
  350. }
  351. if (jmax (w, h) > validSizes[i])
  352. bestSize = validSizes[i];
  353. }
  354. return rescaleImageForIcon (image, bestSize);
  355. }
  356. static void writeOldIconFormat (MemoryOutputStream& out, const Image& image, const char* type, const char* maskType)
  357. {
  358. const int w = image.getWidth();
  359. const int h = image.getHeight();
  360. out.write (type, 4);
  361. out.writeIntBigEndian (8 + 4 * w * h);
  362. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  363. for (int y = 0; y < h; ++y)
  364. {
  365. for (int x = 0; x < w; ++x)
  366. {
  367. const Colour pixel (bitmap.getPixelColour (x, y));
  368. out.writeByte ((char) pixel.getAlpha());
  369. out.writeByte ((char) pixel.getRed());
  370. out.writeByte ((char) pixel.getGreen());
  371. out.writeByte ((char) pixel.getBlue());
  372. }
  373. }
  374. out.write (maskType, 4);
  375. out.writeIntBigEndian (8 + w * h);
  376. for (int y = 0; y < h; ++y)
  377. {
  378. for (int x = 0; x < w; ++x)
  379. {
  380. const Colour pixel (bitmap.getPixelColour (x, y));
  381. out.writeByte ((char) pixel.getAlpha());
  382. }
  383. }
  384. }
  385. static void writeNewIconFormat (MemoryOutputStream& out, const Image& image, const char* type)
  386. {
  387. MemoryOutputStream pngData;
  388. PNGImageFormat pngFormat;
  389. pngFormat.writeImageToStream (image, pngData);
  390. out.write (type, 4);
  391. out.writeIntBigEndian (8 + (int) pngData.getDataSize());
  392. out << pngData;
  393. }
  394. void writeIcnsFile (const OwnedArray<Drawable>& images, OutputStream& out) const
  395. {
  396. MemoryOutputStream data;
  397. int smallest = 0x7fffffff;
  398. Drawable* smallestImage = nullptr;
  399. for (int i = 0; i < images.size(); ++i)
  400. {
  401. const Image image (fixMacIconImageSize (*images.getUnchecked(i)));
  402. jassert (image.getWidth() == image.getHeight());
  403. if (image.getWidth() < smallest)
  404. {
  405. smallest = image.getWidth();
  406. smallestImage = images.getUnchecked(i);
  407. }
  408. switch (image.getWidth())
  409. {
  410. case 16: writeOldIconFormat (data, image, "is32", "s8mk"); break;
  411. case 32: writeOldIconFormat (data, image, "il32", "l8mk"); break;
  412. case 48: writeOldIconFormat (data, image, "ih32", "h8mk"); break;
  413. case 128: writeOldIconFormat (data, image, "it32", "t8mk"); break;
  414. case 256: writeNewIconFormat (data, image, "ic08"); break;
  415. case 512: writeNewIconFormat (data, image, "ic09"); break;
  416. case 1024: writeNewIconFormat (data, image, "ic10"); break;
  417. default: break;
  418. }
  419. }
  420. jassert (data.getDataSize() > 0); // no suitable sized images?
  421. // If you only supply a 1024 image, the file doesn't work on 10.8, so we need
  422. // to force a smaller one in there too..
  423. if (smallest > 512 && smallestImage != nullptr)
  424. writeNewIconFormat (data, rescaleImageForIcon (*smallestImage, 512), "ic09");
  425. out.write ("icns", 4);
  426. out.writeIntBigEndian ((int) data.getDataSize() + 8);
  427. out << data;
  428. }
  429. void getIconImages (OwnedArray<Drawable>& images) const
  430. {
  431. ScopedPointer<Drawable> bigIcon (getBigIcon());
  432. if (bigIcon != nullptr)
  433. images.add (bigIcon.release());
  434. ScopedPointer<Drawable> smallIcon (getSmallIcon());
  435. if (smallIcon != nullptr)
  436. images.add (smallIcon.release());
  437. }
  438. void createiOSIconFiles (File appIconSet) const
  439. {
  440. const Array<AppIconType> types (getiOSAppIconTypes());
  441. OwnedArray<Drawable> images;
  442. getIconImages (images);
  443. if (images.size() > 0)
  444. {
  445. for (int i = 0; i < types.size(); ++i)
  446. {
  447. const AppIconType type = types.getUnchecked(i);
  448. const Image image (rescaleImageForIcon (*images.getFirst(), type.size));
  449. MemoryOutputStream pngData;
  450. PNGImageFormat pngFormat;
  451. pngFormat.writeImageToStream (image, pngData);
  452. overwriteFileIfDifferentOrThrow (appIconSet.getChildFile (type.filename), pngData);
  453. }
  454. }
  455. }
  456. void createIconFile() const
  457. {
  458. OwnedArray<Drawable> images;
  459. getIconImages (images);
  460. if (images.size() > 0)
  461. {
  462. MemoryOutputStream mo;
  463. writeIcnsFile (images, mo);
  464. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  465. overwriteFileIfDifferentOrThrow (iconFile, mo);
  466. }
  467. }
  468. void writeInfoPlistFile() const
  469. {
  470. if (! xcodeCreatePList)
  471. return;
  472. ScopedPointer<XmlElement> plist (XmlDocument::parse (getPListToMergeString()));
  473. if (plist == nullptr || ! plist->hasTagName ("plist"))
  474. plist = new XmlElement ("plist");
  475. XmlElement* dict = plist->getChildByName ("dict");
  476. if (dict == nullptr)
  477. dict = plist->createNewChildElement ("dict");
  478. if (iOS)
  479. {
  480. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  481. addPlistDictionaryKeyBool (dict, "UIViewControllerBasedStatusBarAppearance", false);
  482. }
  483. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  484. if (! iOS) // (NB: on iOS this causes error ITMS-90032 during publishing)
  485. addPlistDictionaryKey (dict, "CFBundleIconFile", iconFile.exists() ? iconFile.getFileName() : String());
  486. addPlistDictionaryKey (dict, "CFBundleIdentifier", project.getBundleIdentifier().toString());
  487. addPlistDictionaryKey (dict, "CFBundleName", projectName);
  488. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  489. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  490. addPlistDictionaryKey (dict, "CFBundleShortVersionString", project.getVersionString());
  491. addPlistDictionaryKey (dict, "CFBundleVersion", project.getVersionString());
  492. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", project.getCompanyName().toString());
  493. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  494. StringArray documentExtensions;
  495. documentExtensions.addTokens (replacePreprocessorDefs (getAllPreprocessorDefs(), settings ["documentExtensions"]),
  496. ",", StringRef());
  497. documentExtensions.trim();
  498. documentExtensions.removeEmptyStrings (true);
  499. if (documentExtensions.size() > 0)
  500. {
  501. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  502. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  503. XmlElement* arrayTag = nullptr;
  504. for (int i = 0; i < documentExtensions.size(); ++i)
  505. {
  506. String ex (documentExtensions[i]);
  507. if (ex.startsWithChar ('.'))
  508. ex = ex.substring (1);
  509. if (arrayTag == nullptr)
  510. {
  511. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  512. arrayTag = dict2->createNewChildElement ("array");
  513. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  514. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  515. addPlistDictionaryKey (dict2, "CFBundleTypeIconFile", "Icon");
  516. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  517. }
  518. arrayTag->createNewChildElement ("string")->addTextElement (ex);
  519. }
  520. }
  521. if (settings ["UIFileSharingEnabled"])
  522. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  523. if (settings ["UIStatusBarHidden"])
  524. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  525. if (iOS)
  526. {
  527. // Forcing full screen disables the split screen feature and prevents error ITMS-90475
  528. addPlistDictionaryKeyBool (dict, "UIRequiresFullScreen", true);
  529. static const char* kDefaultiOSOrientationStrings[] =
  530. {
  531. "UIInterfaceOrientationPortrait",
  532. "UIInterfaceOrientationPortraitUpsideDown",
  533. "UIInterfaceOrientationLandscapeLeft",
  534. "UIInterfaceOrientationLandscapeRight",
  535. nullptr
  536. };
  537. StringArray iOSOrientations (kDefaultiOSOrientationStrings);
  538. dict->createNewChildElement ("key")->addTextElement ("UISupportedInterfaceOrientations");
  539. XmlElement* plistStringArray = dict->createNewChildElement ("array");
  540. for (int i = 0; i < iOSOrientations.size(); ++i)
  541. plistStringArray->createNewChildElement ("string")->addTextElement (iOSOrientations[i]);
  542. }
  543. for (int i = 0; i < xcodeExtraPListEntries.size(); ++i)
  544. dict->addChildElement (new XmlElement (xcodeExtraPListEntries.getReference(i)));
  545. MemoryOutputStream mo;
  546. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  547. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  548. }
  549. void deleteRsrcFiles() const
  550. {
  551. for (DirectoryIterator di (getTargetFolder().getChildFile ("build"), true, "*.rsrc", File::findFiles); di.next();)
  552. di.getFile().deleteFile();
  553. }
  554. String getHeaderSearchPaths (const BuildConfiguration& config) const
  555. {
  556. StringArray paths (extraSearchPaths);
  557. paths.addArray (config.getHeaderSearchPaths());
  558. paths.add ("$(inherited)");
  559. paths = getCleanedStringArray (paths);
  560. for (int i = 0; i < paths.size(); ++i)
  561. {
  562. String& s = paths.getReference(i);
  563. s = replacePreprocessorTokens (config, s);
  564. if (s.containsChar (' '))
  565. s = "\"\\\"" + s + "\\\"\""; // crazy double quotes required when there are spaces..
  566. else
  567. s = "\"" + s + "\"";
  568. }
  569. return "(" + paths.joinIntoString (", ") + ")";
  570. }
  571. static String getLinkerFlagForLib (String library)
  572. {
  573. if (library.substring (0, 3) == "lib")
  574. library = library.substring (3);
  575. return "-l" + library.upToLastOccurrenceOf (".", false, false);
  576. }
  577. void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths) const
  578. {
  579. flags.add (getLinkerFlagForLib (library.getFileNameWithoutExtension()));
  580. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  581. if (! library.isAbsolute())
  582. {
  583. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  584. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  585. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  586. searchPath = srcRoot + searchPath;
  587. }
  588. librarySearchPaths.add (sanitisePath (searchPath));
  589. }
  590. void getLinkerFlags (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  591. {
  592. if (xcodeIsBundle)
  593. flags.add ("-bundle");
  594. const Array<RelativePath>& extraLibs = config.isDebug() ? xcodeExtraLibrariesDebug
  595. : xcodeExtraLibrariesRelease;
  596. for (int i = 0; i < extraLibs.size(); ++i)
  597. getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
  598. flags.add (replacePreprocessorTokens (config, getExtraLinkerFlagsString()));
  599. flags.add (getExternalLibraryFlags (config));
  600. for (int i = 0; i < xcodeLibs.size(); ++i)
  601. flags.add (getLinkerFlagForLib (xcodeLibs[i]));
  602. flags = getCleanedStringArray (flags);
  603. }
  604. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  605. {
  606. StringArray s;
  607. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  608. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  609. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  610. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  611. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  612. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  613. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  614. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  615. s.add ("WARNING_CFLAGS = -Wreorder");
  616. s.add ("GCC_MODEL_TUNING = G5");
  617. if (projectType.isStaticLibrary())
  618. {
  619. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  620. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  621. }
  622. else
  623. {
  624. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  625. }
  626. if (config.isDebug())
  627. if (config.getMacArchitecture() == osxArch_Default || config.getMacArchitecture().isEmpty())
  628. s.add ("ONLY_ACTIVE_ARCH = YES");
  629. if (iOS)
  630. {
  631. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  632. s.add ("SDKROOT = iphoneos");
  633. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  634. const String iosVersion (config.getiOSCompatibilityVersion());
  635. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  636. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  637. }
  638. s.add ("ZERO_LINK = NO");
  639. if (xcodeCanUseDwarf)
  640. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  641. s.add ("PRODUCT_NAME = \"" + replacePreprocessorTokens (config, config.getTargetBinaryNameString()) + "\"");
  642. return s;
  643. }
  644. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  645. {
  646. StringArray s;
  647. const String arch (config.getMacArchitecture());
  648. if (arch == osxArch_Native) s.add ("ARCHS = \"$(NATIVE_ARCH_ACTUAL)\"");
  649. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  650. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  651. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  652. s.add ("HEADER_SEARCH_PATHS = " + getHeaderSearchPaths (config));
  653. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  654. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  655. if (config.isLinkTimeOptimisationEnabled())
  656. s.add ("LLVM_LTO = YES");
  657. if (config.isFastMathEnabled())
  658. s.add ("GCC_FAST_MATH = YES");
  659. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  660. if (extraFlags.isNotEmpty())
  661. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  662. if (xcodeProductInstallPath.isNotEmpty())
  663. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  664. if (xcodeIsBundle)
  665. {
  666. s.add ("LIBRARY_STYLE = Bundle");
  667. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  668. s.add ("GENERATE_PKGINFO_FILE = YES");
  669. }
  670. if (xcodeOtherRezFlags.isNotEmpty())
  671. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  672. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  673. {
  674. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  675. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  676. s.add ("DSTROOT = " + addQuotesIfContainsSpace (sanitisePath (binaryPath.toUnixStyle())));
  677. s.add ("SYMROOT = " + addQuotesIfContainsSpace (sanitisePath (binaryPath.toUnixStyle())));
  678. }
  679. else
  680. {
  681. s.add ("CONFIGURATION_BUILD_DIR = \"$(PROJECT_DIR)/build/$(CONFIGURATION)\"");
  682. }
  683. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  684. if (iOS)
  685. {
  686. s.add ("ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon");
  687. s.add ("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage");
  688. }
  689. else
  690. {
  691. const String sdk (config.getMacSDKVersion());
  692. const String sdkCompat (config.getMacCompatibilityVersion());
  693. for (int ver = oldestSDKVersion; ver <= currentSDKVersion; ++ver)
  694. {
  695. if (sdk == getSDKName (ver)) s.add ("SDKROOT = macosx10." + String (ver));
  696. if (sdkCompat == getSDKName (ver)) s.add ("MACOSX_DEPLOYMENT_TARGET = 10." + String (ver));
  697. }
  698. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  699. s.add ("SDKROOT_ppc = macosx10.5");
  700. if (xcodeExcludedFiles64Bit.isNotEmpty())
  701. {
  702. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  703. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  704. }
  705. }
  706. s.add ("GCC_VERSION = " + gccVersion);
  707. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  708. s.add ("CLANG_LINK_OBJC_RUNTIME = NO");
  709. if (config.getCodeSignIdentity().isNotEmpty())
  710. s.add ("CODE_SIGN_IDENTITY = " + config.getCodeSignIdentity().quoted());
  711. if (config.getCppLanguageStandard().isNotEmpty())
  712. s.add ("CLANG_CXX_LANGUAGE_STANDARD = " + config.getCppLanguageStandard().quoted());
  713. if (config.getCppLibType().isNotEmpty())
  714. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  715. s.add ("COMBINE_HIDPI_IMAGES = YES");
  716. {
  717. StringArray linkerFlags, librarySearchPaths;
  718. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  719. if (linkerFlags.size() > 0)
  720. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  721. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  722. librarySearchPaths = getCleanedStringArray (librarySearchPaths);
  723. if (librarySearchPaths.size() > 0)
  724. {
  725. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  726. for (int i = 0; i < librarySearchPaths.size(); ++i)
  727. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  728. s.add (libPaths + ")");
  729. }
  730. }
  731. StringPairArray defines;
  732. if (config.isDebug())
  733. {
  734. defines.set ("_DEBUG", "1");
  735. defines.set ("DEBUG", "1");
  736. s.add ("COPY_PHASE_STRIP = NO");
  737. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  738. }
  739. else
  740. {
  741. defines.set ("_NDEBUG", "1");
  742. defines.set ("NDEBUG", "1");
  743. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  744. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  745. s.add ("DEAD_CODE_STRIPPING = YES");
  746. }
  747. {
  748. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  749. StringArray defsList;
  750. for (int i = 0; i < defines.size(); ++i)
  751. {
  752. String def (defines.getAllKeys()[i]);
  753. const String value (defines.getAllValues()[i]);
  754. if (value.isNotEmpty())
  755. def << "=" << value.replace ("\"", "\\\"");
  756. defsList.add ("\"" + def + "\"");
  757. }
  758. s.add ("GCC_PREPROCESSOR_DEFINITIONS = " + indentParenthesisedList (defsList));
  759. }
  760. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  761. return getCleanedStringArray (s);
  762. }
  763. void addFrameworks() const
  764. {
  765. if (! projectType.isStaticLibrary())
  766. {
  767. StringArray s (xcodeFrameworks);
  768. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  769. if (project.getConfigFlag ("JUCE_QUICKTIME") == Project::configFlagDisabled)
  770. s.removeString ("QuickTime");
  771. s.trim();
  772. s.removeDuplicates (true);
  773. s.sort (true);
  774. for (int i = 0; i < s.size(); ++i)
  775. addFramework (s[i]);
  776. }
  777. }
  778. //==============================================================================
  779. void writeProjectFile (OutputStream& output) const
  780. {
  781. output << "// !$*UTF8*$!\n{\n"
  782. "\tarchiveVersion = 1;\n"
  783. "\tclasses = {\n\t};\n"
  784. "\tobjectVersion = 46;\n"
  785. "\tobjects = {\n\n";
  786. Array <ValueTree*> objects;
  787. objects.addArray (pbxBuildFiles);
  788. objects.addArray (pbxFileReferences);
  789. objects.addArray (pbxGroups);
  790. objects.addArray (targetConfigs);
  791. objects.addArray (projectConfigs);
  792. objects.addArray (misc);
  793. for (int i = 0; i < objects.size(); ++i)
  794. {
  795. ValueTree& o = *objects.getUnchecked(i);
  796. output << "\t\t" << o.getType().toString() << " = {";
  797. for (int j = 0; j < o.getNumProperties(); ++j)
  798. {
  799. const Identifier propertyName (o.getPropertyName(j));
  800. String val (o.getProperty (propertyName).toString());
  801. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n\\#%^`*")
  802. && ! (val.trimStart().startsWithChar ('(')
  803. || val.trimStart().startsWithChar ('{'))))
  804. val = "\"" + val + "\"";
  805. output << propertyName.toString() << " = " << val << "; ";
  806. }
  807. output << "};\n";
  808. }
  809. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  810. }
  811. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  812. {
  813. String fileID (createID (path + "buildref"));
  814. if (addToSourceBuildPhase)
  815. sourceIDs.add (fileID);
  816. ValueTree* v = new ValueTree (fileID);
  817. v->setProperty ("isa", "PBXBuildFile", nullptr);
  818. v->setProperty ("fileRef", fileRefID, nullptr);
  819. if (inhibitWarnings)
  820. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  821. pbxBuildFiles.add (v);
  822. return fileID;
  823. }
  824. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  825. {
  826. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  827. }
  828. String addFileReference (String pathString) const
  829. {
  830. String sourceTree ("SOURCE_ROOT");
  831. RelativePath path (pathString, RelativePath::unknown);
  832. if (pathString.startsWith ("${"))
  833. {
  834. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  835. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  836. }
  837. else if (path.isAbsolute())
  838. {
  839. sourceTree = "<absolute>";
  840. }
  841. const String fileRefID (createFileRefID (pathString));
  842. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  843. v->setProperty ("isa", "PBXFileReference", nullptr);
  844. v->setProperty ("lastKnownFileType", getFileType (path), nullptr);
  845. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  846. v->setProperty ("path", sanitisePath (pathString), nullptr);
  847. v->setProperty ("sourceTree", sourceTree, nullptr);
  848. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  849. if (existing >= 0)
  850. {
  851. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  852. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  853. }
  854. else
  855. {
  856. pbxFileReferences.addSorted (*this, v.release());
  857. }
  858. return fileRefID;
  859. }
  860. public:
  861. static int compareElements (const ValueTree* first, const ValueTree* second)
  862. {
  863. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  864. }
  865. private:
  866. static String getFileType (const RelativePath& file)
  867. {
  868. if (file.hasFileExtension (cppFileExtensions)) return "sourcecode.cpp.cpp";
  869. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  870. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  871. if (file.hasFileExtension (".c")) return "sourcecode.c.c";
  872. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  873. if (file.hasFileExtension (asmFileExtensions)) return "sourcecode.c.asm";
  874. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  875. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  876. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  877. if (file.hasFileExtension ("html;htm")) return "text.html";
  878. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  879. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  880. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  881. if (file.hasFileExtension ("app")) return "wrapper.application";
  882. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  883. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  884. if (file.hasFileExtension ("a")) return "archive.ar";
  885. if (file.hasFileExtension ("xcassets")) return "folder.assetcatalog";
  886. return "file" + file.getFileExtension();
  887. }
  888. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources, bool shouldBeAddedToXcodeResources, bool inhibitWarnings) const
  889. {
  890. const String pathAsString (path.toUnixStyle());
  891. const String refID (addFileReference (path.toUnixStyle()));
  892. if (shouldBeCompiled)
  893. {
  894. if (path.hasFileExtension (".r"))
  895. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  896. else
  897. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  898. }
  899. else if (! shouldBeAddedToBinaryResources || shouldBeAddedToXcodeResources)
  900. {
  901. const String fileType (getFileType (path));
  902. if (shouldBeAddedToXcodeResources || fileType.startsWith ("image.") || fileType.startsWith ("text.") || fileType.startsWith ("file."))
  903. {
  904. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  905. resourceFileRefs.add (refID);
  906. }
  907. }
  908. return refID;
  909. }
  910. String addProjectItem (const Project::Item& projectItem) const
  911. {
  912. if (projectItem.isGroup())
  913. {
  914. StringArray childIDs;
  915. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  916. {
  917. const String childID (addProjectItem (projectItem.getChild(i)));
  918. if (childID.isNotEmpty())
  919. childIDs.add (childID);
  920. }
  921. return addGroup (projectItem, childIDs);
  922. }
  923. if (projectItem.shouldBeAddedToTargetProject())
  924. {
  925. const String itemPath (projectItem.getFilePath());
  926. RelativePath path;
  927. if (itemPath.startsWith ("${"))
  928. path = RelativePath (itemPath, RelativePath::unknown);
  929. else
  930. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  931. return addFile (path, projectItem.shouldBeCompiled(),
  932. projectItem.shouldBeAddedToBinaryResources(),
  933. projectItem.shouldBeAddedToXcodeResources(),
  934. projectItem.shouldInhibitWarnings());
  935. }
  936. return String();
  937. }
  938. void addFramework (const String& frameworkName) const
  939. {
  940. String path (frameworkName);
  941. if (! File::isAbsolutePath (path))
  942. path = "System/Library/Frameworks/" + path;
  943. if (! path.endsWithIgnoreCase (".framework"))
  944. path << ".framework";
  945. const String fileRefID (createFileRefID (path));
  946. addFileReference ((File::isAbsolutePath (frameworkName) ? "" : "${SDKROOT}/") + path);
  947. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  948. frameworkFileIDs.add (fileRefID);
  949. }
  950. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  951. {
  952. ValueTree* v = new ValueTree (groupID);
  953. v->setProperty ("isa", "PBXGroup", nullptr);
  954. v->setProperty ("children", indentParenthesisedList (childIDs), nullptr);
  955. v->setProperty (Ids::name, groupName, nullptr);
  956. v->setProperty ("sourceTree", "<group>", nullptr);
  957. pbxGroups.add (v);
  958. }
  959. String addGroup (const Project::Item& item, StringArray& childIDs) const
  960. {
  961. const String groupName (item.getName());
  962. const String groupID (getIDForGroup (item));
  963. addGroup (groupID, groupName, childIDs);
  964. return groupID;
  965. }
  966. void addMainBuildProduct() const
  967. {
  968. jassert (xcodeFileType.isNotEmpty());
  969. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar ('.'));
  970. if (ProjectExporter::BuildConfiguration::Ptr config = getConfiguration(0))
  971. {
  972. String productName (replacePreprocessorTokens (*config, config->getTargetBinaryNameString()));
  973. if (xcodeFileType == "archive.ar")
  974. productName = getLibbedFilename (productName);
  975. else
  976. productName += xcodeBundleExtension;
  977. addBuildProduct (xcodeFileType, productName);
  978. }
  979. }
  980. void addBuildProduct (const String& fileType, const String& binaryName) const
  981. {
  982. ValueTree* v = new ValueTree (createID ("__productFileID"));
  983. v->setProperty ("isa", "PBXFileReference", nullptr);
  984. v->setProperty ("explicitFileType", fileType, nullptr);
  985. v->setProperty ("includeInIndex", (int) 0, nullptr);
  986. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  987. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  988. pbxFileReferences.add (v);
  989. }
  990. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  991. {
  992. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  993. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  994. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  995. v->setProperty (Ids::name, configName, nullptr);
  996. targetConfigs.add (v);
  997. }
  998. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  999. {
  1000. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  1001. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  1002. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  1003. v->setProperty (Ids::name, configName, nullptr);
  1004. projectConfigs.add (v);
  1005. }
  1006. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  1007. {
  1008. StringArray configIDs;
  1009. for (int i = 0; i < configsToUse.size(); ++i)
  1010. configIDs.add (configsToUse[i]->getType().toString());
  1011. ValueTree* v = new ValueTree (listID);
  1012. v->setProperty ("isa", "XCConfigurationList", nullptr);
  1013. v->setProperty ("buildConfigurations", indentParenthesisedList (configIDs), nullptr);
  1014. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  1015. if (configsToUse[0] != nullptr)
  1016. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), nullptr);
  1017. misc.add (v);
  1018. }
  1019. ValueTree& addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  1020. {
  1021. String phaseId (createID (phaseType + "resbuildphase"));
  1022. int n = 0;
  1023. while (buildPhaseIDs.contains (phaseId))
  1024. phaseId = createID (phaseType + "resbuildphase" + String (++n));
  1025. buildPhaseIDs.add (phaseId);
  1026. ValueTree* v = new ValueTree (phaseId);
  1027. v->setProperty ("isa", phaseType, nullptr);
  1028. v->setProperty ("buildActionMask", "2147483647", nullptr);
  1029. v->setProperty ("files", indentParenthesisedList (fileIds), nullptr);
  1030. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  1031. misc.add (v);
  1032. return *v;
  1033. }
  1034. void addTargetObject() const
  1035. {
  1036. ValueTree* const v = new ValueTree (createID ("__target"));
  1037. v->setProperty ("isa", "PBXNativeTarget", nullptr);
  1038. v->setProperty ("buildConfigurationList", createID ("__configList"), nullptr);
  1039. v->setProperty ("buildPhases", indentParenthesisedList (buildPhaseIDs), nullptr);
  1040. v->setProperty ("buildRules", "( )", nullptr);
  1041. v->setProperty ("dependencies", "( )", nullptr);
  1042. v->setProperty (Ids::name, projectName, nullptr);
  1043. v->setProperty ("productName", projectName, nullptr);
  1044. v->setProperty ("productReference", createID ("__productFileID"), nullptr);
  1045. if (xcodeProductInstallPath.isNotEmpty())
  1046. v->setProperty ("productInstallPath", xcodeProductInstallPath, nullptr);
  1047. jassert (xcodeProductType.isNotEmpty());
  1048. v->setProperty ("productType", xcodeProductType, nullptr);
  1049. misc.add (v);
  1050. }
  1051. void addProjectObject() const
  1052. {
  1053. ValueTree* const v = new ValueTree (createID ("__root"));
  1054. v->setProperty ("isa", "PBXProject", nullptr);
  1055. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  1056. v->setProperty ("attributes", "{ LastUpgradeCheck = 0440; }", nullptr);
  1057. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  1058. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  1059. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  1060. v->setProperty ("projectDirPath", "\"\"", nullptr);
  1061. v->setProperty ("projectRoot", "\"\"", nullptr);
  1062. v->setProperty ("targets", "( " + createID ("__target") + " )", nullptr);
  1063. misc.add (v);
  1064. }
  1065. void addShellScriptBuildPhase (const String& phaseName, const String& script) const
  1066. {
  1067. if (script.trim().isNotEmpty())
  1068. {
  1069. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  1070. v.setProperty (Ids::name, phaseName, nullptr);
  1071. v.setProperty ("shellPath", "/bin/sh", nullptr);
  1072. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  1073. .replace ("\"", "\\\"")
  1074. .replace ("\r\n", "\\n")
  1075. .replace ("\n", "\\n"), nullptr);
  1076. }
  1077. }
  1078. //==============================================================================
  1079. struct AppIconType
  1080. {
  1081. const char* idiom;
  1082. const char* sizeString;
  1083. const char* filename;
  1084. const char* scale;
  1085. int size;
  1086. };
  1087. static Array<AppIconType> getiOSAppIconTypes()
  1088. {
  1089. AppIconType types[] =
  1090. {
  1091. { "iphone", "29x29", "Icon-Small.png", "1x", 29 },
  1092. { "iphone", "29x29", "Icon-Small@2x.png", "2x", 58 },
  1093. { "iphone", "29x29", "Icon-Small@3x.png", "3x", 87 },
  1094. { "iphone", "40x40", "Icon-Spotlight-40@2x.png", "2x", 80 },
  1095. { "iphone", "40x40", "Icon-Spotlight-40@3x.png", "3x", 120 },
  1096. { "iphone", "57x57", "Icon.png", "1x", 57 },
  1097. { "iphone", "57x57", "Icon@2x.png", "2x", 114 },
  1098. { "iphone", "60x60", "Icon-60@2x.png", "2x", 120 },
  1099. { "iphone", "60x60", "Icon-@3x.png", "3x", 180 },
  1100. { "ipad", "29x29", "Icon-Small-1.png", "1x", 29 },
  1101. { "ipad", "29x29", "Icon-Small@2x-1.png", "2x", 58 },
  1102. { "ipad", "40x40", "Icon-Spotlight-40.png", "1x", 40 },
  1103. { "ipad", "40x40", "Icon-Spotlight-40@2x-1.png", "2x", 80 },
  1104. { "ipad", "50x50", "Icon-Small-50.png", "1x", 50 },
  1105. { "ipad", "50x50", "Icon-Small-50@2x.png", "2x", 100 },
  1106. { "ipad", "72x72", "Icon-72.png", "1x", 72 },
  1107. { "ipad", "72x72", "Icon-72@2x.png", "2x", 144 },
  1108. { "ipad", "76x76", "Icon-76.png", "1x", 76 },
  1109. { "ipad", "76x76", "Icon-76@2x.png", "2x", 152 }
  1110. };
  1111. return Array<AppIconType> (types, numElementsInArray (types));
  1112. }
  1113. static String getiOSAppIconContents()
  1114. {
  1115. const Array<AppIconType> types (getiOSAppIconTypes());
  1116. var images;
  1117. for (int i = 0; i < types.size(); ++i)
  1118. {
  1119. AppIconType type = types.getUnchecked(i);
  1120. DynamicObject::Ptr d = new DynamicObject();
  1121. d->setProperty ("idiom", type.idiom);
  1122. d->setProperty ("size", type.sizeString);
  1123. d->setProperty ("filename", type.filename);
  1124. d->setProperty ("scale", type.scale);
  1125. images.append (var (d));
  1126. }
  1127. return getiOSAssetContents (images);
  1128. }
  1129. //==============================================================================
  1130. struct ImageType
  1131. {
  1132. const char* orientation;
  1133. const char* idiom;
  1134. const char* subtype;
  1135. const char* extent;
  1136. const char* scale;
  1137. const char* filename;
  1138. int width;
  1139. int height;
  1140. };
  1141. static Array<ImageType> getiOSLaunchImageTypes()
  1142. {
  1143. ImageType types[] =
  1144. {
  1145. { "portrait", "iphone", nullptr, "full-screen", "2x", "LaunchImage-iphone-2x.png", 640, 960 },
  1146. { "portrait", "iphone", "retina4", "full-screen", "2x", "LaunchImage-iphone-retina4.png", 640, 1136 },
  1147. { "portrait", "ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-portrait-1x.png", 768, 1024 },
  1148. { "landscape","ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-landscape-1x.png", 1024, 768 },
  1149. { "portrait", "ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-portrait-2x.png", 1536, 2048 },
  1150. { "landscape","ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-landscape-2x.png", 2048, 1536 }
  1151. };
  1152. return Array<ImageType> (types, numElementsInArray (types));
  1153. }
  1154. static String getiOSLaunchImageContents()
  1155. {
  1156. const Array<ImageType> types (getiOSLaunchImageTypes());
  1157. var images;
  1158. for (int i = 0; i < types.size(); ++i)
  1159. {
  1160. const ImageType& type = types.getReference(i);
  1161. DynamicObject::Ptr d = new DynamicObject();
  1162. d->setProperty ("orientation", type.orientation);
  1163. d->setProperty ("idiom", type.idiom);
  1164. d->setProperty ("extent", type.extent);
  1165. d->setProperty ("minimum-system-version", "7.0");
  1166. d->setProperty ("scale", type.scale);
  1167. d->setProperty ("filename", type.filename);
  1168. if (type.subtype != nullptr)
  1169. d->setProperty ("subtype", type.subtype);
  1170. images.append (var (d));
  1171. }
  1172. return getiOSAssetContents (images);
  1173. }
  1174. static void createiOSLaunchImageFiles (const File& launchImageSet)
  1175. {
  1176. const Array<ImageType> types (getiOSLaunchImageTypes());
  1177. for (int i = 0; i < types.size(); ++i)
  1178. {
  1179. const ImageType& type = types.getReference(i);
  1180. Image image (Image::ARGB, type.width, type.height, true); // (empty black image)
  1181. image.clear (image.getBounds(), Colours::black);
  1182. MemoryOutputStream pngData;
  1183. PNGImageFormat pngFormat;
  1184. pngFormat.writeImageToStream (image, pngData);
  1185. overwriteFileIfDifferentOrThrow (launchImageSet.getChildFile (type.filename), pngData);
  1186. }
  1187. }
  1188. //==============================================================================
  1189. static String getiOSAssetContents (var images)
  1190. {
  1191. DynamicObject::Ptr v (new DynamicObject());
  1192. var info (new DynamicObject());
  1193. info.getDynamicObject()->setProperty ("version", 1);
  1194. info.getDynamicObject()->setProperty ("author", "xcode");
  1195. v->setProperty ("images", images);
  1196. v->setProperty ("info", info);
  1197. return JSON::toString (var (v));
  1198. }
  1199. void createiOSAssetsFolder() const
  1200. {
  1201. const File assets (getTargetFolder().getChildFile (project.getProjectFilenameRoot())
  1202. .getChildFile ("Images.xcassets"));
  1203. const File iconSet (assets.getChildFile ("AppIcon.appiconset"));
  1204. const File launchImage (assets.getChildFile ("LaunchImage.launchimage"));
  1205. overwriteFileIfDifferentOrThrow (iconSet.getChildFile ("Contents.json"), getiOSAppIconContents());
  1206. createiOSIconFiles (iconSet);
  1207. overwriteFileIfDifferentOrThrow (launchImage.getChildFile ("Contents.json"), getiOSLaunchImageContents());
  1208. createiOSLaunchImageFiles (launchImage);
  1209. RelativePath assetsPath (assets, getTargetFolder(), RelativePath::buildTargetFolder);
  1210. addFileReference (assetsPath.toUnixStyle());
  1211. resourceIDs.add (addBuildFile (assetsPath, false, false));
  1212. resourceFileRefs.add (createFileRefID (assetsPath));
  1213. }
  1214. //==============================================================================
  1215. static String indentBracedList (const StringArray& list) { return "{" + indentList (list, ";", 0, true) + " }"; }
  1216. static String indentParenthesisedList (const StringArray& list) { return "(" + indentList (list, ",", 1, false) + " )"; }
  1217. static String indentList (const StringArray& list, const String& separator, int extraTabs, bool shouldSort)
  1218. {
  1219. if (list.size() == 0)
  1220. return " ";
  1221. const String tabs ("\n" + String::repeatedString ("\t", extraTabs + 4));
  1222. if (shouldSort)
  1223. {
  1224. StringArray sorted (list);
  1225. sorted.sort (true);
  1226. return tabs + sorted.joinIntoString (separator + tabs) + separator;
  1227. }
  1228. return tabs + list.joinIntoString (separator + tabs) + separator;
  1229. }
  1230. String createID (String rootString) const
  1231. {
  1232. if (rootString.startsWith ("${"))
  1233. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  1234. rootString += project.getProjectUID();
  1235. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  1236. }
  1237. String createFileRefID (const RelativePath& path) const { return createFileRefID (path.toUnixStyle()); }
  1238. String createFileRefID (const String& path) const { return createID ("__fileref_" + path); }
  1239. String getIDForGroup (const Project::Item& item) const { return createID (item.getID()); }
  1240. bool shouldFileBeCompiledByDefault (const RelativePath& file) const override
  1241. {
  1242. return file.hasFileExtension (sourceFileExtensions);
  1243. }
  1244. static String getOSXVersionName (int version)
  1245. {
  1246. jassert (version >= 4);
  1247. return "10." + String (version);
  1248. }
  1249. static String getSDKName (int version)
  1250. {
  1251. return getOSXVersionName (version) + " SDK";
  1252. }
  1253. void initialiseDependencyPathValues()
  1254. {
  1255. vst2Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vstFolder), Ids::vst2Path, TargetOS::osx)));
  1256. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder), Ids::vst3Path, TargetOS::osx)));
  1257. aaxPath. referTo (Value (new DependencyPathValueSource (getSetting (Ids::aaxFolder), Ids::aaxPath, TargetOS::osx)));
  1258. rtasPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::rtasFolder), Ids::rtasPath, TargetOS::osx)));
  1259. }
  1260. };