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.

1260 lines
52KB

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