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.

1233 lines
51KB

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