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.

1252 lines
51KB

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