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.

1210 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. s.add ("ONLY_ACTIVE_ARCH = YES");
  586. s.add ("COPY_PHASE_STRIP = NO");
  587. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  588. }
  589. else
  590. {
  591. defines.set ("_NDEBUG", "1");
  592. defines.set ("NDEBUG", "1");
  593. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  594. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  595. }
  596. {
  597. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  598. StringArray defsList;
  599. for (int i = 0; i < defines.size(); ++i)
  600. {
  601. String def (defines.getAllKeys()[i]);
  602. const String value (defines.getAllValues()[i]);
  603. if (value.isNotEmpty())
  604. def << "=" << value;
  605. defsList.add (def.quoted());
  606. }
  607. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  608. }
  609. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  610. s.trim();
  611. s.removeEmptyStrings();
  612. s.removeDuplicates (false);
  613. return s;
  614. }
  615. void addFrameworks() const
  616. {
  617. if (! isStaticLibrary())
  618. {
  619. StringArray s (xcodeFrameworks);
  620. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  621. s.trim();
  622. s.removeDuplicates (true);
  623. s.sort (true);
  624. for (int i = 0; i < s.size(); ++i)
  625. addFramework (s[i]);
  626. }
  627. }
  628. //==============================================================================
  629. void writeProjectFile (OutputStream& output) const
  630. {
  631. output << "// !$*UTF8*$!\n{\n"
  632. "\tarchiveVersion = 1;\n"
  633. "\tclasses = {\n\t};\n"
  634. "\tobjectVersion = 46;\n"
  635. "\tobjects = {\n\n";
  636. Array <ValueTree*> objects;
  637. objects.addArray (pbxBuildFiles);
  638. objects.addArray (pbxFileReferences);
  639. objects.addArray (pbxGroups);
  640. objects.addArray (targetConfigs);
  641. objects.addArray (projectConfigs);
  642. objects.addArray (misc);
  643. for (int i = 0; i < objects.size(); ++i)
  644. {
  645. ValueTree& o = *objects.getUnchecked(i);
  646. output << "\t\t" << o.getType().toString() << " = { ";
  647. for (int j = 0; j < o.getNumProperties(); ++j)
  648. {
  649. const Identifier propertyName (o.getPropertyName(j));
  650. String val (o.getProperty (propertyName).toString());
  651. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_\r\n")
  652. && ! (val.trimStart().startsWithChar ('(')
  653. || val.trimStart().startsWithChar ('{'))))
  654. val = val.quoted();
  655. output << propertyName.toString() << " = " << val << "; ";
  656. }
  657. output << "};\n";
  658. }
  659. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  660. }
  661. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  662. {
  663. forEachXmlChildElementWithTagName (*xml, e, "key")
  664. {
  665. if (e->getAllSubText().trim().equalsIgnoreCase (key))
  666. {
  667. if (e->getNextElement() != nullptr && e->getNextElement()->hasTagName ("key"))
  668. {
  669. // try to fix broken plist format..
  670. xml->removeChildElement (e, true);
  671. break;
  672. }
  673. else
  674. {
  675. return; // (value already exists)
  676. }
  677. }
  678. }
  679. xml->createNewChildElement ("key") ->addTextElement (key);
  680. xml->createNewChildElement ("string")->addTextElement (value);
  681. }
  682. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  683. {
  684. xml->createNewChildElement ("key")->addTextElement (key);
  685. xml->createNewChildElement (value ? "true" : "false");
  686. }
  687. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  688. {
  689. String fileID (createID (path + "buildref"));
  690. if (addToSourceBuildPhase)
  691. sourceIDs.add (fileID);
  692. ValueTree* v = new ValueTree (fileID);
  693. v->setProperty ("isa", "PBXBuildFile", 0);
  694. v->setProperty ("fileRef", fileRefID, 0);
  695. if (inhibitWarnings)
  696. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", 0);
  697. pbxBuildFiles.add (v);
  698. return fileID;
  699. }
  700. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  701. {
  702. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  703. }
  704. String addFileReference (String pathString) const
  705. {
  706. String sourceTree ("SOURCE_ROOT");
  707. RelativePath path (pathString, RelativePath::unknown);
  708. if (pathString.startsWith ("${"))
  709. {
  710. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  711. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  712. }
  713. else if (path.isAbsolute())
  714. {
  715. sourceTree = "<absolute>";
  716. }
  717. const String fileRefID (createFileRefID (pathString));
  718. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  719. v->setProperty ("isa", "PBXFileReference", 0);
  720. v->setProperty ("lastKnownFileType", getFileType (path), 0);
  721. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), 0);
  722. v->setProperty ("path", sanitisePath (pathString), 0);
  723. v->setProperty ("sourceTree", sourceTree, 0);
  724. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  725. if (existing >= 0)
  726. {
  727. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  728. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  729. }
  730. else
  731. {
  732. pbxFileReferences.addSorted (*this, v.release());
  733. }
  734. return fileRefID;
  735. }
  736. public:
  737. static int compareElements (const ValueTree* first, const ValueTree* second)
  738. {
  739. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  740. }
  741. private:
  742. static String getFileType (const RelativePath& file)
  743. {
  744. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  745. else if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  746. else if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  747. else if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  748. else if (file.hasFileExtension (".framework")) return "wrapper.framework";
  749. else if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  750. else if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  751. else if (file.hasFileExtension ("html;htm")) return "text.html";
  752. else if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  753. else if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  754. else if (file.hasFileExtension ("plist")) return "text.plist.xml";
  755. else if (file.hasFileExtension ("app")) return "wrapper.application";
  756. else if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  757. else if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  758. else if (file.hasFileExtension ("a")) return "archive.ar";
  759. return "file" + file.getFileExtension();
  760. }
  761. String addFile (const RelativePath& path, bool shouldBeCompiled, bool inhibitWarnings) const
  762. {
  763. const String pathAsString (path.toUnixStyle());
  764. const String refID (addFileReference (path.toUnixStyle()));
  765. if (shouldBeCompiled)
  766. {
  767. if (path.hasFileExtension (".r"))
  768. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  769. else
  770. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  771. }
  772. return refID;
  773. }
  774. String addProjectItem (const Project::Item& projectItem) const
  775. {
  776. if (projectItem.isGroup())
  777. {
  778. StringArray childIDs;
  779. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  780. {
  781. const String childID (addProjectItem (projectItem.getChild(i)));
  782. if (childID.isNotEmpty())
  783. childIDs.add (childID);
  784. }
  785. return addGroup (projectItem, childIDs);
  786. }
  787. else
  788. {
  789. if (projectItem.shouldBeAddedToTargetProject())
  790. {
  791. String itemPath (projectItem.getFilePath());
  792. bool inhibitWarnings = projectItem.shouldInhibitWarnings();
  793. if (itemPath.startsWith ("${"))
  794. {
  795. const RelativePath path (itemPath, RelativePath::unknown);
  796. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  797. }
  798. else
  799. {
  800. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  801. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  802. }
  803. }
  804. }
  805. return String::empty;
  806. }
  807. void addFramework (const String& frameworkName) const
  808. {
  809. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  810. const String fileRefID (createFileRefID (path));
  811. addFileReference ("${SDKROOT}/" + path);
  812. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  813. frameworkFileIDs.add (fileRefID);
  814. }
  815. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  816. {
  817. ValueTree* v = new ValueTree (groupID);
  818. v->setProperty ("isa", "PBXGroup", 0);
  819. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", 0);
  820. v->setProperty (Ids::name, groupName, 0);
  821. v->setProperty ("sourceTree", "<group>", 0);
  822. pbxGroups.add (v);
  823. }
  824. String addGroup (const Project::Item& item, StringArray& childIDs) const
  825. {
  826. const String groupName (item.getName());
  827. const String groupID (getIDForGroup (item));
  828. addGroup (groupID, groupName, childIDs);
  829. return groupID;
  830. }
  831. void addMainBuildProduct() const
  832. {
  833. jassert (xcodeFileType.isNotEmpty());
  834. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  835. String productName (getConfiguration(0)->getTargetBinaryName().toString());
  836. if (xcodeFileType == "archive.ar")
  837. productName = getLibbedFilename (productName);
  838. else
  839. productName += xcodeBundleExtension;
  840. addBuildProduct (xcodeFileType, productName);
  841. }
  842. void addBuildProduct (const String& fileType, const String& binaryName) const
  843. {
  844. ValueTree* v = new ValueTree (createID ("__productFileID"));
  845. v->setProperty ("isa", "PBXFileReference", 0);
  846. v->setProperty ("explicitFileType", fileType, 0);
  847. v->setProperty ("includeInIndex", (int) 0, 0);
  848. v->setProperty ("path", sanitisePath (binaryName), 0);
  849. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", 0);
  850. pbxFileReferences.add (v);
  851. }
  852. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  853. {
  854. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  855. v->setProperty ("isa", "XCBuildConfiguration", 0);
  856. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  857. v->setProperty (Ids::name, configName, 0);
  858. targetConfigs.add (v);
  859. }
  860. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  861. {
  862. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  863. v->setProperty ("isa", "XCBuildConfiguration", 0);
  864. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  865. v->setProperty (Ids::name, configName, 0);
  866. projectConfigs.add (v);
  867. }
  868. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  869. {
  870. StringArray configIDs;
  871. for (int i = 0; i < configsToUse.size(); ++i)
  872. configIDs.add (configsToUse[i]->getType().toString());
  873. ValueTree* v = new ValueTree (listID);
  874. v->setProperty ("isa", "XCConfigurationList", 0);
  875. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", 0);
  876. v->setProperty ("defaultConfigurationIsVisible", (int) 0, 0);
  877. if (configsToUse[0] != nullptr)
  878. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), 0);
  879. misc.add (v);
  880. }
  881. ValueTree* addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  882. {
  883. String phaseId (createID (phaseType + "resbuildphase"));
  884. buildPhaseIDs.add (phaseId);
  885. ValueTree* v = new ValueTree (phaseId);
  886. v->setProperty ("isa", phaseType, 0);
  887. v->setProperty ("buildActionMask", "2147483647", 0);
  888. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", 0);
  889. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, 0);
  890. misc.add (v);
  891. return v;
  892. }
  893. void addTargetObject() const
  894. {
  895. ValueTree* const v = new ValueTree (createID ("__target"));
  896. v->setProperty ("isa", "PBXNativeTarget", 0);
  897. v->setProperty ("buildConfigurationList", createID ("__configList"), 0);
  898. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", 0);
  899. v->setProperty ("buildRules", "( )", 0);
  900. v->setProperty ("dependencies", "( )", 0);
  901. v->setProperty (Ids::name, projectName, 0);
  902. v->setProperty ("productName", projectName, 0);
  903. v->setProperty ("productReference", createID ("__productFileID"), 0);
  904. if (xcodeProductInstallPath.isNotEmpty())
  905. v->setProperty ("productInstallPath", xcodeProductInstallPath, 0);
  906. jassert (xcodeProductType.isNotEmpty());
  907. v->setProperty ("productType", xcodeProductType, 0);
  908. misc.add (v);
  909. }
  910. void addProjectObject() const
  911. {
  912. ValueTree* const v = new ValueTree (createID ("__root"));
  913. v->setProperty ("isa", "PBXProject", 0);
  914. v->setProperty ("buildConfigurationList", createID ("__projList"), 0);
  915. v->setProperty ("compatibilityVersion", "Xcode 3.2", 0);
  916. v->setProperty ("hasScannedForEncodings", (int) 0, 0);
  917. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), 0);
  918. v->setProperty ("projectDirPath", "\"\"", 0);
  919. v->setProperty ("projectRoot", "\"\"", 0);
  920. v->setProperty ("targets", "( " + createID ("__target") + " )", 0);
  921. misc.add (v);
  922. }
  923. void addShellScriptPhase() const
  924. {
  925. if (getPostBuildScript().isNotEmpty())
  926. {
  927. ValueTree* const v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  928. v->setProperty (Ids::name, "Post-build script", 0);
  929. v->setProperty ("shellPath", "/bin/sh", 0);
  930. v->setProperty ("shellScript", getPostBuildScript().replace ("\\", "\\\\")
  931. .replace ("\"", "\\\"")
  932. .replace ("\r\n", "\\n")
  933. .replace ("\n", "\\n"), 0);
  934. }
  935. }
  936. //==============================================================================
  937. static String indentList (const StringArray& list, const String& separator)
  938. {
  939. if (list.size() == 0)
  940. return " ";
  941. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  942. + (separator == ";" ? separator : String::empty);
  943. }
  944. String createID (String rootString) const
  945. {
  946. if (rootString.startsWith ("${"))
  947. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  948. rootString += project.getProjectUID();
  949. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  950. }
  951. String createFileRefID (const RelativePath& path) const
  952. {
  953. return createFileRefID (path.toUnixStyle());
  954. }
  955. String createFileRefID (const String& path) const
  956. {
  957. return createID ("__fileref_" + path);
  958. }
  959. String getIDForGroup (const Project::Item& item) const
  960. {
  961. return createID (item.getID());
  962. }
  963. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  964. {
  965. return file.hasFileExtension (sourceFileExtensions);
  966. }
  967. };
  968. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__