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.

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