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.

1223 lines
50KB

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