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.

1196 lines
49KB

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