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.

1214 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, 256, 512, 1024 };
  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. static void writeOldIconFormat (MemoryOutputStream& out, const Image& image, const char* type, const char* maskType)
  305. {
  306. const int w = image.getWidth();
  307. const int h = image.getHeight();
  308. out.write (type, 4);
  309. out.writeIntBigEndian (8 + 4 * w * h);
  310. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  311. for (int y = 0; y < h; ++y)
  312. {
  313. for (int x = 0; x < w; ++x)
  314. {
  315. const Colour pixel (bitmap.getPixelColour (x, y));
  316. out.writeByte ((char) pixel.getAlpha());
  317. out.writeByte ((char) pixel.getRed());
  318. out.writeByte ((char) pixel.getGreen());
  319. out.writeByte ((char) pixel.getBlue());
  320. }
  321. }
  322. out.write (maskType, 4);
  323. out.writeIntBigEndian (8 + w * h);
  324. for (int y = 0; y < h; ++y)
  325. {
  326. for (int x = 0; x < w; ++x)
  327. {
  328. const Colour pixel (bitmap.getPixelColour (x, y));
  329. out.writeByte ((char) pixel.getAlpha());
  330. }
  331. }
  332. }
  333. static void writeNewIconFormat (MemoryOutputStream& out, const Image& image, const char* type)
  334. {
  335. MemoryOutputStream pngData;
  336. PNGImageFormat pngFormat;
  337. pngFormat.writeImageToStream (image, pngData);
  338. out.write (type, 4);
  339. out.writeIntBigEndian (8 + pngData.getDataSize());
  340. out << pngData;
  341. }
  342. void writeIcnsFile (const Array<Image>& images, OutputStream& out) const
  343. {
  344. MemoryOutputStream data;
  345. for (int i = 0; i < images.size(); ++i)
  346. {
  347. const Image image (fixMacIconImageSize (images.getReference (i)));
  348. jassert (image.getWidth() == image.getHeight());
  349. switch (image.getWidth())
  350. {
  351. case 16: writeOldIconFormat (data, image, "is32", "s8mk"); break;
  352. case 32: writeOldIconFormat (data, image, "il32", "l8mk"); break;
  353. case 48: writeOldIconFormat (data, image, "ih32", "h8mk"); break;
  354. case 128: writeOldIconFormat (data, image, "it32", "t8mk"); break;
  355. case 256: writeNewIconFormat (data, image, "ic08"); break;
  356. case 512: writeNewIconFormat (data, image, "ic09"); break;
  357. case 1024: writeNewIconFormat (data, image, "ic10"); break;
  358. default: break;
  359. }
  360. }
  361. jassert (data.getDataSize() > 0); // no suitable sized images?
  362. out.write ("icns", 4);
  363. out.writeIntBigEndian (data.getDataSize() + 8);
  364. out << data;
  365. }
  366. void createIconFile() const
  367. {
  368. Array<Image> images;
  369. Image bigIcon (getBigIcon());
  370. if (bigIcon.isValid())
  371. images.add (bigIcon);
  372. Image smallIcon (getSmallIcon());
  373. if (smallIcon.isValid())
  374. images.add (smallIcon);
  375. if (images.size() > 0)
  376. {
  377. MemoryOutputStream mo;
  378. writeIcnsFile (images, mo);
  379. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  380. overwriteFileIfDifferentOrThrow (iconFile, mo);
  381. }
  382. }
  383. void writeInfoPlistFile() const
  384. {
  385. if (! xcodeCreatePList)
  386. return;
  387. ScopedPointer<XmlElement> plist (XmlDocument::parse (getPListToMergeString()));
  388. if (plist == nullptr || ! plist->hasTagName ("plist"))
  389. plist = new XmlElement ("plist");
  390. XmlElement* dict = plist->getChildByName ("dict");
  391. if (dict == nullptr)
  392. dict = plist->createNewChildElement ("dict");
  393. if (iOS)
  394. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  395. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  396. addPlistDictionaryKey (dict, "CFBundleIconFile", iconFile.exists() ? iconFile.getFileName() : String::empty);
  397. addPlistDictionaryKey (dict, "CFBundleIdentifier", project.getBundleIdentifier().toString());
  398. addPlistDictionaryKey (dict, "CFBundleName", projectName);
  399. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  400. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  401. addPlistDictionaryKey (dict, "CFBundleShortVersionString", project.getVersionString());
  402. addPlistDictionaryKey (dict, "CFBundleVersion", project.getVersionString());
  403. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", project.getCompanyName().toString());
  404. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  405. StringArray documentExtensions;
  406. documentExtensions.addTokens (replacePreprocessorDefs (getAllPreprocessorDefs(), settings ["documentExtensions"]),
  407. ",", String::empty);
  408. documentExtensions.trim();
  409. documentExtensions.removeEmptyStrings (true);
  410. if (documentExtensions.size() > 0)
  411. {
  412. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  413. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  414. for (int i = 0; i < documentExtensions.size(); ++i)
  415. {
  416. String ex (documentExtensions[i]);
  417. if (ex.startsWithChar ('.'))
  418. ex = ex.substring (1);
  419. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  420. dict2->createNewChildElement ("array")->createNewChildElement ("string")->addTextElement (ex);
  421. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  422. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  423. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  424. }
  425. }
  426. if (settings ["UIFileSharingEnabled"])
  427. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  428. if (settings ["UIStatusBarHidden"])
  429. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  430. for (int i = 0; i < xcodeExtraPListEntries.size(); ++i)
  431. dict->addChildElement (new XmlElement (xcodeExtraPListEntries.getReference(i)));
  432. MemoryOutputStream mo;
  433. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  434. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  435. }
  436. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  437. {
  438. StringArray searchPaths (extraSearchPaths);
  439. searchPaths.addArray (config.getHeaderSearchPaths());
  440. searchPaths.removeDuplicates (false);
  441. return searchPaths;
  442. }
  443. void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths) const
  444. {
  445. jassert (library.getFileNameWithoutExtension().substring (0, 3) == "lib");
  446. flags.add ("-l" + library.getFileNameWithoutExtension().substring (3));
  447. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  448. if (! library.isAbsolute())
  449. {
  450. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  451. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  452. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  453. searchPath = srcRoot + searchPath;
  454. }
  455. librarySearchPaths.add (sanitisePath (searchPath));
  456. }
  457. void getLinkerFlags (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  458. {
  459. if (xcodeIsBundle)
  460. flags.add ("-bundle");
  461. const Array<RelativePath>& extraLibs = config.isDebug() ? xcodeExtraLibrariesDebug
  462. : xcodeExtraLibrariesRelease;
  463. for (int i = 0; i < extraLibs.size(); ++i)
  464. getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
  465. flags.add (replacePreprocessorTokens (config, getExtraLinkerFlagsString()));
  466. flags.removeEmptyStrings (true);
  467. }
  468. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  469. {
  470. StringArray s;
  471. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  472. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  473. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  474. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  475. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  476. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  477. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  478. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  479. s.add ("WARNING_CFLAGS = -Wreorder");
  480. s.add ("GCC_MODEL_TUNING = G5");
  481. if (projectType.isLibrary())
  482. {
  483. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  484. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  485. }
  486. else
  487. {
  488. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  489. }
  490. if (iOS)
  491. {
  492. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  493. s.add ("SDKROOT = iphoneos");
  494. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  495. const String iosVersion (config.getiOSCompatibilityVersion());
  496. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  497. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  498. }
  499. s.add ("ZERO_LINK = NO");
  500. if (xcodeCanUseDwarf)
  501. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  502. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryNameString() + "\"");
  503. return s;
  504. }
  505. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  506. {
  507. StringArray s;
  508. const String arch (config.getMacArchitecture());
  509. if (arch == osxArch_Native) s.add ("ARCHS = \"$(ARCHS_NATIVE)\"");
  510. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  511. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  512. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  513. s.add ("HEADER_SEARCH_PATHS = \"" + replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" ")) + " $(inherited)\"");
  514. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  515. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  516. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  517. if (extraFlags.isNotEmpty())
  518. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  519. if (xcodeProductInstallPath.isNotEmpty())
  520. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  521. if (xcodeIsBundle)
  522. {
  523. s.add ("LIBRARY_STYLE = Bundle");
  524. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  525. s.add ("GENERATE_PKGINFO_FILE = YES");
  526. }
  527. if (xcodeOtherRezFlags.isNotEmpty())
  528. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  529. if (projectType.isLibrary())
  530. {
  531. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  532. {
  533. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  534. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  535. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  536. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  537. }
  538. s.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  539. s.add ("DEPLOYMENT_LOCATION = YES");
  540. }
  541. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  542. if (! iOS)
  543. {
  544. const String sdk (config.getMacSDKVersion());
  545. const String sdkCompat (config.getMacCompatibilityVersion());
  546. if (sdk == osxVersion10_5) s.add ("SDKROOT = macosx10.5");
  547. else if (sdk == osxVersion10_6) s.add ("SDKROOT = macosx10.6");
  548. else if (sdk == osxVersion10_7) s.add ("SDKROOT = macosx10.7");
  549. if (sdkCompat == osxVersion10_4) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.4");
  550. else if (sdkCompat == osxVersion10_5) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.5");
  551. else if (sdkCompat == osxVersion10_6) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.6");
  552. else if (sdkCompat == osxVersion10_7) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.7");
  553. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  554. s.add ("SDKROOT_ppc = macosx10.5");
  555. if (xcodeExcludedFiles64Bit.isNotEmpty())
  556. {
  557. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  558. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  559. }
  560. }
  561. s.add ("GCC_VERSION = " + gccVersion);
  562. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  563. if (config.getCppLibType().isNotEmpty())
  564. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  565. {
  566. StringArray linkerFlags, librarySearchPaths;
  567. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  568. if (linkerFlags.size() > 0)
  569. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  570. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  571. librarySearchPaths.removeDuplicates (false);
  572. if (librarySearchPaths.size() > 0)
  573. {
  574. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  575. for (int i = 0; i < librarySearchPaths.size(); ++i)
  576. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  577. s.add (libPaths + ")");
  578. }
  579. }
  580. StringPairArray defines;
  581. if (config.isDebug())
  582. {
  583. defines.set ("_DEBUG", "1");
  584. defines.set ("DEBUG", "1");
  585. if (config.getMacArchitecture() == osxArch_Default
  586. || config.getMacArchitecture().isEmpty())
  587. s.add ("ONLY_ACTIVE_ARCH = YES");
  588. s.add ("COPY_PHASE_STRIP = NO");
  589. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  590. }
  591. else
  592. {
  593. defines.set ("_NDEBUG", "1");
  594. defines.set ("NDEBUG", "1");
  595. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  596. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  597. }
  598. {
  599. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  600. StringArray defsList;
  601. for (int i = 0; i < defines.size(); ++i)
  602. {
  603. String def (defines.getAllKeys()[i]);
  604. const String value (defines.getAllValues()[i]);
  605. if (value.isNotEmpty())
  606. def << "=" << value;
  607. defsList.add (def.quoted());
  608. }
  609. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  610. }
  611. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  612. s.trim();
  613. s.removeEmptyStrings();
  614. s.removeDuplicates (false);
  615. return s;
  616. }
  617. void addFrameworks() const
  618. {
  619. if (! isStaticLibrary())
  620. {
  621. StringArray s (xcodeFrameworks);
  622. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  623. s.trim();
  624. s.removeDuplicates (true);
  625. s.sort (true);
  626. for (int i = 0; i < s.size(); ++i)
  627. addFramework (s[i]);
  628. }
  629. }
  630. //==============================================================================
  631. void writeProjectFile (OutputStream& output) const
  632. {
  633. output << "// !$*UTF8*$!\n{\n"
  634. "\tarchiveVersion = 1;\n"
  635. "\tclasses = {\n\t};\n"
  636. "\tobjectVersion = 46;\n"
  637. "\tobjects = {\n\n";
  638. Array <ValueTree*> objects;
  639. objects.addArray (pbxBuildFiles);
  640. objects.addArray (pbxFileReferences);
  641. objects.addArray (pbxGroups);
  642. objects.addArray (targetConfigs);
  643. objects.addArray (projectConfigs);
  644. objects.addArray (misc);
  645. for (int i = 0; i < objects.size(); ++i)
  646. {
  647. ValueTree& o = *objects.getUnchecked(i);
  648. output << "\t\t" << o.getType().toString() << " = { ";
  649. for (int j = 0; j < o.getNumProperties(); ++j)
  650. {
  651. const Identifier propertyName (o.getPropertyName(j));
  652. String val (o.getProperty (propertyName).toString());
  653. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_\r\n")
  654. && ! (val.trimStart().startsWithChar ('(')
  655. || val.trimStart().startsWithChar ('{'))))
  656. val = val.quoted();
  657. output << propertyName.toString() << " = " << val << "; ";
  658. }
  659. output << "};\n";
  660. }
  661. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  662. }
  663. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  664. {
  665. forEachXmlChildElementWithTagName (*xml, e, "key")
  666. {
  667. if (e->getAllSubText().trim().equalsIgnoreCase (key))
  668. {
  669. if (e->getNextElement() != nullptr && e->getNextElement()->hasTagName ("key"))
  670. {
  671. // try to fix broken plist format..
  672. xml->removeChildElement (e, true);
  673. break;
  674. }
  675. else
  676. {
  677. return; // (value already exists)
  678. }
  679. }
  680. }
  681. xml->createNewChildElement ("key") ->addTextElement (key);
  682. xml->createNewChildElement ("string")->addTextElement (value);
  683. }
  684. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  685. {
  686. xml->createNewChildElement ("key")->addTextElement (key);
  687. xml->createNewChildElement (value ? "true" : "false");
  688. }
  689. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  690. {
  691. String fileID (createID (path + "buildref"));
  692. if (addToSourceBuildPhase)
  693. sourceIDs.add (fileID);
  694. ValueTree* v = new ValueTree (fileID);
  695. v->setProperty ("isa", "PBXBuildFile", 0);
  696. v->setProperty ("fileRef", fileRefID, 0);
  697. if (inhibitWarnings)
  698. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", 0);
  699. pbxBuildFiles.add (v);
  700. return fileID;
  701. }
  702. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  703. {
  704. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  705. }
  706. String addFileReference (String pathString) const
  707. {
  708. String sourceTree ("SOURCE_ROOT");
  709. RelativePath path (pathString, RelativePath::unknown);
  710. if (pathString.startsWith ("${"))
  711. {
  712. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  713. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  714. }
  715. else if (path.isAbsolute())
  716. {
  717. sourceTree = "<absolute>";
  718. }
  719. const String fileRefID (createFileRefID (pathString));
  720. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  721. v->setProperty ("isa", "PBXFileReference", 0);
  722. v->setProperty ("lastKnownFileType", getFileType (path), 0);
  723. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), 0);
  724. v->setProperty ("path", sanitisePath (pathString), 0);
  725. v->setProperty ("sourceTree", sourceTree, 0);
  726. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  727. if (existing >= 0)
  728. {
  729. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  730. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  731. }
  732. else
  733. {
  734. pbxFileReferences.addSorted (*this, v.release());
  735. }
  736. return fileRefID;
  737. }
  738. public:
  739. static int compareElements (const ValueTree* first, const ValueTree* second)
  740. {
  741. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  742. }
  743. private:
  744. static String getFileType (const RelativePath& file)
  745. {
  746. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  747. else if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  748. else if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  749. else if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  750. else if (file.hasFileExtension (".framework")) return "wrapper.framework";
  751. else if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  752. else if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  753. else if (file.hasFileExtension ("html;htm")) return "text.html";
  754. else if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  755. else if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  756. else if (file.hasFileExtension ("plist")) return "text.plist.xml";
  757. else if (file.hasFileExtension ("app")) return "wrapper.application";
  758. else if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  759. else if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  760. else if (file.hasFileExtension ("a")) return "archive.ar";
  761. return "file" + file.getFileExtension();
  762. }
  763. String addFile (const RelativePath& path, bool shouldBeCompiled, bool inhibitWarnings) const
  764. {
  765. const String pathAsString (path.toUnixStyle());
  766. const String refID (addFileReference (path.toUnixStyle()));
  767. if (shouldBeCompiled)
  768. {
  769. if (path.hasFileExtension (".r"))
  770. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  771. else
  772. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  773. }
  774. return refID;
  775. }
  776. String addProjectItem (const Project::Item& projectItem) const
  777. {
  778. if (projectItem.isGroup())
  779. {
  780. StringArray childIDs;
  781. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  782. {
  783. const String childID (addProjectItem (projectItem.getChild(i)));
  784. if (childID.isNotEmpty())
  785. childIDs.add (childID);
  786. }
  787. return addGroup (projectItem, childIDs);
  788. }
  789. else
  790. {
  791. if (projectItem.shouldBeAddedToTargetProject())
  792. {
  793. String itemPath (projectItem.getFilePath());
  794. bool inhibitWarnings = projectItem.shouldInhibitWarnings();
  795. if (itemPath.startsWith ("${"))
  796. {
  797. const RelativePath path (itemPath, RelativePath::unknown);
  798. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  799. }
  800. else
  801. {
  802. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  803. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  804. }
  805. }
  806. }
  807. return String::empty;
  808. }
  809. void addFramework (const String& frameworkName) const
  810. {
  811. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  812. const String fileRefID (createFileRefID (path));
  813. addFileReference ("${SDKROOT}/" + path);
  814. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  815. frameworkFileIDs.add (fileRefID);
  816. }
  817. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  818. {
  819. ValueTree* v = new ValueTree (groupID);
  820. v->setProperty ("isa", "PBXGroup", 0);
  821. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", 0);
  822. v->setProperty (Ids::name, groupName, 0);
  823. v->setProperty ("sourceTree", "<group>", 0);
  824. pbxGroups.add (v);
  825. }
  826. String addGroup (const Project::Item& item, StringArray& childIDs) const
  827. {
  828. const String groupName (item.getName());
  829. const String groupID (getIDForGroup (item));
  830. addGroup (groupID, groupName, childIDs);
  831. return groupID;
  832. }
  833. void addMainBuildProduct() const
  834. {
  835. jassert (xcodeFileType.isNotEmpty());
  836. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  837. String productName (getConfiguration(0)->getTargetBinaryName().toString());
  838. if (xcodeFileType == "archive.ar")
  839. productName = getLibbedFilename (productName);
  840. else
  841. productName += xcodeBundleExtension;
  842. addBuildProduct (xcodeFileType, productName);
  843. }
  844. void addBuildProduct (const String& fileType, const String& binaryName) const
  845. {
  846. ValueTree* v = new ValueTree (createID ("__productFileID"));
  847. v->setProperty ("isa", "PBXFileReference", 0);
  848. v->setProperty ("explicitFileType", fileType, 0);
  849. v->setProperty ("includeInIndex", (int) 0, 0);
  850. v->setProperty ("path", sanitisePath (binaryName), 0);
  851. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", 0);
  852. pbxFileReferences.add (v);
  853. }
  854. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  855. {
  856. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  857. v->setProperty ("isa", "XCBuildConfiguration", 0);
  858. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  859. v->setProperty (Ids::name, configName, 0);
  860. targetConfigs.add (v);
  861. }
  862. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  863. {
  864. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  865. v->setProperty ("isa", "XCBuildConfiguration", 0);
  866. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  867. v->setProperty (Ids::name, configName, 0);
  868. projectConfigs.add (v);
  869. }
  870. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  871. {
  872. StringArray configIDs;
  873. for (int i = 0; i < configsToUse.size(); ++i)
  874. configIDs.add (configsToUse[i]->getType().toString());
  875. ValueTree* v = new ValueTree (listID);
  876. v->setProperty ("isa", "XCConfigurationList", 0);
  877. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", 0);
  878. v->setProperty ("defaultConfigurationIsVisible", (int) 0, 0);
  879. if (configsToUse[0] != nullptr)
  880. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), 0);
  881. misc.add (v);
  882. }
  883. ValueTree* addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  884. {
  885. String phaseId (createID (phaseType + "resbuildphase"));
  886. buildPhaseIDs.add (phaseId);
  887. ValueTree* v = new ValueTree (phaseId);
  888. v->setProperty ("isa", phaseType, 0);
  889. v->setProperty ("buildActionMask", "2147483647", 0);
  890. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", 0);
  891. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, 0);
  892. misc.add (v);
  893. return v;
  894. }
  895. void addTargetObject() const
  896. {
  897. ValueTree* const v = new ValueTree (createID ("__target"));
  898. v->setProperty ("isa", "PBXNativeTarget", 0);
  899. v->setProperty ("buildConfigurationList", createID ("__configList"), 0);
  900. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", 0);
  901. v->setProperty ("buildRules", "( )", 0);
  902. v->setProperty ("dependencies", "( )", 0);
  903. v->setProperty (Ids::name, projectName, 0);
  904. v->setProperty ("productName", projectName, 0);
  905. v->setProperty ("productReference", createID ("__productFileID"), 0);
  906. if (xcodeProductInstallPath.isNotEmpty())
  907. v->setProperty ("productInstallPath", xcodeProductInstallPath, 0);
  908. jassert (xcodeProductType.isNotEmpty());
  909. v->setProperty ("productType", xcodeProductType, 0);
  910. misc.add (v);
  911. }
  912. void addProjectObject() const
  913. {
  914. ValueTree* const v = new ValueTree (createID ("__root"));
  915. v->setProperty ("isa", "PBXProject", 0);
  916. v->setProperty ("buildConfigurationList", createID ("__projList"), 0);
  917. v->setProperty ("compatibilityVersion", "Xcode 3.2", 0);
  918. v->setProperty ("hasScannedForEncodings", (int) 0, 0);
  919. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), 0);
  920. v->setProperty ("projectDirPath", "\"\"", 0);
  921. v->setProperty ("projectRoot", "\"\"", 0);
  922. v->setProperty ("targets", "( " + createID ("__target") + " )", 0);
  923. misc.add (v);
  924. }
  925. void addShellScriptPhase() const
  926. {
  927. if (getPostBuildScript().isNotEmpty())
  928. {
  929. ValueTree* const v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  930. v->setProperty (Ids::name, "Post-build script", 0);
  931. v->setProperty ("shellPath", "/bin/sh", 0);
  932. v->setProperty ("shellScript", getPostBuildScript().replace ("\\", "\\\\")
  933. .replace ("\"", "\\\"")
  934. .replace ("\r\n", "\\n")
  935. .replace ("\n", "\\n"), 0);
  936. }
  937. }
  938. //==============================================================================
  939. static String indentList (const StringArray& list, const String& separator)
  940. {
  941. if (list.size() == 0)
  942. return " ";
  943. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  944. + (separator == ";" ? separator : String::empty);
  945. }
  946. String createID (String rootString) const
  947. {
  948. if (rootString.startsWith ("${"))
  949. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  950. rootString += project.getProjectUID();
  951. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  952. }
  953. String createFileRefID (const RelativePath& path) const
  954. {
  955. return createFileRefID (path.toUnixStyle());
  956. }
  957. String createFileRefID (const String& path) const
  958. {
  959. return createID ("__fileref_" + path);
  960. }
  961. String getIDForGroup (const Project::Item& item) const
  962. {
  963. return createID (item.getID());
  964. }
  965. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  966. {
  967. return file.hasFileExtension (sourceFileExtensions);
  968. }
  969. };
  970. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__