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.

1230 lines
50KB

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