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.

1236 lines
50KB

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