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.

1242 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. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  449. {
  450. StringArray searchPaths (extraSearchPaths);
  451. searchPaths.addArray (config.getHeaderSearchPaths());
  452. searchPaths.removeDuplicates (false);
  453. return searchPaths;
  454. }
  455. void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths) const
  456. {
  457. jassert (library.getFileNameWithoutExtension().substring (0, 3) == "lib");
  458. flags.add ("-l" + library.getFileNameWithoutExtension().substring (3));
  459. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  460. if (! library.isAbsolute())
  461. {
  462. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  463. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  464. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  465. searchPath = srcRoot + searchPath;
  466. }
  467. librarySearchPaths.add (sanitisePath (searchPath));
  468. }
  469. void getLinkerFlags (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  470. {
  471. if (xcodeIsBundle)
  472. flags.add ("-bundle");
  473. const Array<RelativePath>& extraLibs = config.isDebug() ? xcodeExtraLibrariesDebug
  474. : xcodeExtraLibrariesRelease;
  475. for (int i = 0; i < extraLibs.size(); ++i)
  476. getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
  477. flags.add (replacePreprocessorTokens (config, getExtraLinkerFlagsString()));
  478. flags.add (getExternalLibraryFlags (config));
  479. flags.removeEmptyStrings (true);
  480. }
  481. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  482. {
  483. StringArray s;
  484. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  485. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  486. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  487. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  488. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  489. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  490. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  491. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  492. s.add ("WARNING_CFLAGS = -Wreorder");
  493. s.add ("GCC_MODEL_TUNING = G5");
  494. if (projectType.isStaticLibrary())
  495. {
  496. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  497. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  498. }
  499. else
  500. {
  501. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  502. }
  503. if (iOS)
  504. {
  505. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  506. s.add ("SDKROOT = iphoneos");
  507. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  508. const String iosVersion (config.getiOSCompatibilityVersion());
  509. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  510. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  511. }
  512. s.add ("ZERO_LINK = NO");
  513. if (xcodeCanUseDwarf)
  514. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  515. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryNameString() + "\"");
  516. return s;
  517. }
  518. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  519. {
  520. StringArray s;
  521. const String arch (config.getMacArchitecture());
  522. if (arch == osxArch_Native) s.add ("ARCHS = \"$(ARCHS_NATIVE)\"");
  523. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  524. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  525. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  526. s.add ("HEADER_SEARCH_PATHS = \"" + replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" ")) + " $(inherited)\"");
  527. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  528. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  529. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  530. if (extraFlags.isNotEmpty())
  531. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  532. if (xcodeProductInstallPath.isNotEmpty())
  533. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  534. if (xcodeIsBundle)
  535. {
  536. s.add ("LIBRARY_STYLE = Bundle");
  537. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  538. s.add ("GENERATE_PKGINFO_FILE = YES");
  539. }
  540. if (xcodeOtherRezFlags.isNotEmpty())
  541. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  542. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  543. {
  544. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  545. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  546. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  547. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  548. }
  549. else
  550. {
  551. s.add ("CONFIGURATION_BUILD_DIR = \"$(PROJECT_DIR)/build/$(CONFIGURATION)\"");
  552. }
  553. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  554. if (! iOS)
  555. {
  556. const String sdk (config.getMacSDKVersion());
  557. const String sdkCompat (config.getMacCompatibilityVersion());
  558. for (int ver = oldestSDKVersion; ver <= currentSDKVersion; ++ver)
  559. {
  560. if (sdk == getSDKName (ver)) s.add ("SDKROOT = macosx10." + String (ver));
  561. if (sdkCompat == getSDKName (ver)) s.add ("MACOSX_DEPLOYMENT_TARGET = 10." + String (ver));
  562. }
  563. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  564. s.add ("SDKROOT_ppc = macosx10.5");
  565. if (xcodeExcludedFiles64Bit.isNotEmpty())
  566. {
  567. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  568. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  569. }
  570. }
  571. s.add ("GCC_VERSION = " + gccVersion);
  572. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  573. s.add ("CLANG_LINK_OBJC_RUNTIME = NO");
  574. if (config.getCppLibType().isNotEmpty())
  575. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  576. s.add ("COMBINE_HIDPI_IMAGES = YES");
  577. {
  578. StringArray linkerFlags, librarySearchPaths;
  579. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  580. if (linkerFlags.size() > 0)
  581. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  582. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  583. librarySearchPaths.removeDuplicates (false);
  584. if (librarySearchPaths.size() > 0)
  585. {
  586. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  587. for (int i = 0; i < librarySearchPaths.size(); ++i)
  588. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  589. s.add (libPaths + ")");
  590. }
  591. }
  592. StringPairArray defines;
  593. if (config.isDebug())
  594. {
  595. defines.set ("_DEBUG", "1");
  596. defines.set ("DEBUG", "1");
  597. if (config.getMacArchitecture() == osxArch_Default
  598. || config.getMacArchitecture().isEmpty())
  599. s.add ("ONLY_ACTIVE_ARCH = YES");
  600. s.add ("COPY_PHASE_STRIP = NO");
  601. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  602. }
  603. else
  604. {
  605. defines.set ("_NDEBUG", "1");
  606. defines.set ("NDEBUG", "1");
  607. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  608. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  609. s.add ("DEAD_CODE_STRIPPING = YES");
  610. }
  611. {
  612. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  613. StringArray defsList;
  614. for (int i = 0; i < defines.size(); ++i)
  615. {
  616. String def (defines.getAllKeys()[i]);
  617. const String value (defines.getAllValues()[i]);
  618. if (value.isNotEmpty())
  619. def << "=" << value.replace ("\"", "\\\"");
  620. defsList.add ("\"" + def + "\"");
  621. }
  622. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  623. }
  624. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  625. s.trim();
  626. s.removeEmptyStrings();
  627. s.removeDuplicates (false);
  628. return s;
  629. }
  630. void addFrameworks() const
  631. {
  632. if (! projectType.isStaticLibrary())
  633. {
  634. StringArray s (xcodeFrameworks);
  635. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  636. s.trim();
  637. s.removeDuplicates (true);
  638. s.sort (true);
  639. for (int i = 0; i < s.size(); ++i)
  640. addFramework (s[i]);
  641. }
  642. }
  643. //==============================================================================
  644. void writeProjectFile (OutputStream& output) const
  645. {
  646. output << "// !$*UTF8*$!\n{\n"
  647. "\tarchiveVersion = 1;\n"
  648. "\tclasses = {\n\t};\n"
  649. "\tobjectVersion = 46;\n"
  650. "\tobjects = {\n\n";
  651. Array <ValueTree*> objects;
  652. objects.addArray (pbxBuildFiles);
  653. objects.addArray (pbxFileReferences);
  654. objects.addArray (pbxGroups);
  655. objects.addArray (targetConfigs);
  656. objects.addArray (projectConfigs);
  657. objects.addArray (misc);
  658. for (int i = 0; i < objects.size(); ++i)
  659. {
  660. ValueTree& o = *objects.getUnchecked(i);
  661. output << "\t\t" << o.getType().toString() << " = { ";
  662. for (int j = 0; j < o.getNumProperties(); ++j)
  663. {
  664. const Identifier propertyName (o.getPropertyName(j));
  665. String val (o.getProperty (propertyName).toString());
  666. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n")
  667. && ! (val.trimStart().startsWithChar ('(')
  668. || val.trimStart().startsWithChar ('{'))))
  669. val = "\"" + val + "\"";
  670. output << propertyName.toString() << " = " << val << "; ";
  671. }
  672. output << "};\n";
  673. }
  674. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  675. }
  676. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  677. {
  678. forEachXmlChildElementWithTagName (*xml, e, "key")
  679. {
  680. if (e->getAllSubText().trim().equalsIgnoreCase (key))
  681. {
  682. if (e->getNextElement() != nullptr && e->getNextElement()->hasTagName ("key"))
  683. {
  684. // try to fix broken plist format..
  685. xml->removeChildElement (e, true);
  686. break;
  687. }
  688. else
  689. {
  690. return; // (value already exists)
  691. }
  692. }
  693. }
  694. xml->createNewChildElement ("key") ->addTextElement (key);
  695. xml->createNewChildElement ("string")->addTextElement (value);
  696. }
  697. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  698. {
  699. xml->createNewChildElement ("key")->addTextElement (key);
  700. xml->createNewChildElement (value ? "true" : "false");
  701. }
  702. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  703. {
  704. String fileID (createID (path + "buildref"));
  705. if (addToSourceBuildPhase)
  706. sourceIDs.add (fileID);
  707. ValueTree* v = new ValueTree (fileID);
  708. v->setProperty ("isa", "PBXBuildFile", nullptr);
  709. v->setProperty ("fileRef", fileRefID, nullptr);
  710. if (inhibitWarnings)
  711. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  712. pbxBuildFiles.add (v);
  713. return fileID;
  714. }
  715. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  716. {
  717. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  718. }
  719. String addFileReference (String pathString) const
  720. {
  721. String sourceTree ("SOURCE_ROOT");
  722. RelativePath path (pathString, RelativePath::unknown);
  723. if (pathString.startsWith ("${"))
  724. {
  725. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  726. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  727. }
  728. else if (path.isAbsolute())
  729. {
  730. sourceTree = "<absolute>";
  731. }
  732. const String fileRefID (createFileRefID (pathString));
  733. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  734. v->setProperty ("isa", "PBXFileReference", nullptr);
  735. v->setProperty ("lastKnownFileType", getFileType (path), nullptr);
  736. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  737. v->setProperty ("path", sanitisePath (pathString), nullptr);
  738. v->setProperty ("sourceTree", sourceTree, nullptr);
  739. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  740. if (existing >= 0)
  741. {
  742. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  743. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  744. }
  745. else
  746. {
  747. pbxFileReferences.addSorted (*this, v.release());
  748. }
  749. return fileRefID;
  750. }
  751. public:
  752. static int compareElements (const ValueTree* first, const ValueTree* second)
  753. {
  754. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  755. }
  756. private:
  757. static String getFileType (const RelativePath& file)
  758. {
  759. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  760. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  761. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  762. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  763. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  764. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  765. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  766. if (file.hasFileExtension ("html;htm")) return "text.html";
  767. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  768. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  769. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  770. if (file.hasFileExtension ("app")) return "wrapper.application";
  771. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  772. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  773. if (file.hasFileExtension ("a")) return "archive.ar";
  774. return "file" + file.getFileExtension();
  775. }
  776. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources, bool inhibitWarnings) const
  777. {
  778. const String pathAsString (path.toUnixStyle());
  779. const String refID (addFileReference (path.toUnixStyle()));
  780. if (shouldBeCompiled)
  781. {
  782. if (path.hasFileExtension (".r"))
  783. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  784. else
  785. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  786. }
  787. else if (! shouldBeAddedToBinaryResources)
  788. {
  789. const String fileType (getFileType (path));
  790. if (fileType.startsWith ("image.") || fileType.startsWith ("text.") || fileType.startsWith ("file."))
  791. {
  792. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  793. resourceFileRefs.add (refID);
  794. }
  795. }
  796. return refID;
  797. }
  798. String addProjectItem (const Project::Item& projectItem) const
  799. {
  800. if (projectItem.isGroup())
  801. {
  802. StringArray childIDs;
  803. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  804. {
  805. const String childID (addProjectItem (projectItem.getChild(i)));
  806. if (childID.isNotEmpty())
  807. childIDs.add (childID);
  808. }
  809. return addGroup (projectItem, childIDs);
  810. }
  811. if (projectItem.shouldBeAddedToTargetProject())
  812. {
  813. const String itemPath (projectItem.getFilePath());
  814. RelativePath path;
  815. if (itemPath.startsWith ("${"))
  816. path = RelativePath (itemPath, RelativePath::unknown);
  817. else
  818. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  819. return addFile (path, projectItem.shouldBeCompiled(),
  820. projectItem.shouldBeAddedToBinaryResources(),
  821. projectItem.shouldInhibitWarnings());
  822. }
  823. return String::empty;
  824. }
  825. void addFramework (const String& frameworkName) const
  826. {
  827. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  828. const String fileRefID (createFileRefID (path));
  829. addFileReference ("${SDKROOT}/" + path);
  830. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  831. frameworkFileIDs.add (fileRefID);
  832. }
  833. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  834. {
  835. ValueTree* v = new ValueTree (groupID);
  836. v->setProperty ("isa", "PBXGroup", nullptr);
  837. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", nullptr);
  838. v->setProperty (Ids::name, groupName, nullptr);
  839. v->setProperty ("sourceTree", "<group>", nullptr);
  840. pbxGroups.add (v);
  841. }
  842. String addGroup (const Project::Item& item, StringArray& childIDs) const
  843. {
  844. const String groupName (item.getName());
  845. const String groupID (getIDForGroup (item));
  846. addGroup (groupID, groupName, childIDs);
  847. return groupID;
  848. }
  849. void addMainBuildProduct() const
  850. {
  851. jassert (xcodeFileType.isNotEmpty());
  852. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  853. String productName (getConfiguration(0)->getTargetBinaryName().toString());
  854. if (xcodeFileType == "archive.ar")
  855. productName = getLibbedFilename (productName);
  856. else
  857. productName += xcodeBundleExtension;
  858. addBuildProduct (xcodeFileType, productName);
  859. }
  860. void addBuildProduct (const String& fileType, const String& binaryName) const
  861. {
  862. ValueTree* v = new ValueTree (createID ("__productFileID"));
  863. v->setProperty ("isa", "PBXFileReference", nullptr);
  864. v->setProperty ("explicitFileType", fileType, nullptr);
  865. v->setProperty ("includeInIndex", (int) 0, nullptr);
  866. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  867. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  868. pbxFileReferences.add (v);
  869. }
  870. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  871. {
  872. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  873. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  874. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  875. v->setProperty (Ids::name, configName, nullptr);
  876. targetConfigs.add (v);
  877. }
  878. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  879. {
  880. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  881. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  882. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  883. v->setProperty (Ids::name, configName, nullptr);
  884. projectConfigs.add (v);
  885. }
  886. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  887. {
  888. StringArray configIDs;
  889. for (int i = 0; i < configsToUse.size(); ++i)
  890. configIDs.add (configsToUse[i]->getType().toString());
  891. ValueTree* v = new ValueTree (listID);
  892. v->setProperty ("isa", "XCConfigurationList", nullptr);
  893. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", nullptr);
  894. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  895. if (configsToUse[0] != nullptr)
  896. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), nullptr);
  897. misc.add (v);
  898. }
  899. ValueTree& addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  900. {
  901. String phaseId (createID (phaseType + "resbuildphase"));
  902. int n = 0;
  903. while (buildPhaseIDs.contains (phaseId))
  904. phaseId = createID (phaseType + "resbuildphase" + String (++n));
  905. buildPhaseIDs.add (phaseId);
  906. ValueTree* v = new ValueTree (phaseId);
  907. v->setProperty ("isa", phaseType, nullptr);
  908. v->setProperty ("buildActionMask", "2147483647", nullptr);
  909. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", nullptr);
  910. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  911. misc.add (v);
  912. return *v;
  913. }
  914. void addTargetObject() const
  915. {
  916. ValueTree* const v = new ValueTree (createID ("__target"));
  917. v->setProperty ("isa", "PBXNativeTarget", nullptr);
  918. v->setProperty ("buildConfigurationList", createID ("__configList"), nullptr);
  919. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", nullptr);
  920. v->setProperty ("buildRules", "( )", nullptr);
  921. v->setProperty ("dependencies", "( )", nullptr);
  922. v->setProperty (Ids::name, projectName, nullptr);
  923. v->setProperty ("productName", projectName, nullptr);
  924. v->setProperty ("productReference", createID ("__productFileID"), nullptr);
  925. if (xcodeProductInstallPath.isNotEmpty())
  926. v->setProperty ("productInstallPath", xcodeProductInstallPath, nullptr);
  927. jassert (xcodeProductType.isNotEmpty());
  928. v->setProperty ("productType", xcodeProductType, nullptr);
  929. misc.add (v);
  930. }
  931. void addProjectObject() const
  932. {
  933. ValueTree* const v = new ValueTree (createID ("__root"));
  934. v->setProperty ("isa", "PBXProject", nullptr);
  935. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  936. v->setProperty ("attributes", "{ LastUpgradeCheck = 0440; }", nullptr);
  937. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  938. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  939. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  940. v->setProperty ("projectDirPath", "\"\"", nullptr);
  941. v->setProperty ("projectRoot", "\"\"", nullptr);
  942. v->setProperty ("targets", "( " + createID ("__target") + " )", nullptr);
  943. misc.add (v);
  944. }
  945. void addShellScriptBuildPhase (const String& phaseName, const String& script) const
  946. {
  947. if (script.trim().isNotEmpty())
  948. {
  949. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  950. v.setProperty (Ids::name, phaseName, nullptr);
  951. v.setProperty ("shellPath", "/bin/sh", nullptr);
  952. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  953. .replace ("\"", "\\\"")
  954. .replace ("\r\n", "\\n")
  955. .replace ("\n", "\\n"), nullptr);
  956. }
  957. }
  958. //==============================================================================
  959. static String indentList (const StringArray& list, const String& separator)
  960. {
  961. if (list.size() == 0)
  962. return " ";
  963. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  964. + (separator == ";" ? separator : String::empty);
  965. }
  966. String createID (String rootString) const
  967. {
  968. if (rootString.startsWith ("${"))
  969. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  970. rootString += project.getProjectUID();
  971. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  972. }
  973. String createFileRefID (const RelativePath& path) const
  974. {
  975. return createFileRefID (path.toUnixStyle());
  976. }
  977. String createFileRefID (const String& path) const
  978. {
  979. return createID ("__fileref_" + path);
  980. }
  981. String getIDForGroup (const Project::Item& item) const
  982. {
  983. return createID (item.getID());
  984. }
  985. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  986. {
  987. return file.hasFileExtension (sourceFileExtensions);
  988. }
  989. static String getSDKName (int version)
  990. {
  991. jassert (version >= 4);
  992. return "10." + String (version) + " SDK";
  993. }
  994. };