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.

1724 lines
73KB

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