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.

1258 lines
52KB

  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))) return new XCodeProjectExporter (project, settings, false);
  54. if (settings.hasType (getValueTreeTypeName (true))) return new XCodeProjectExporter (project, settings, true);
  55. return nullptr;
  56. }
  57. //==============================================================================
  58. Value getPListToMergeValue() { return getSetting ("customPList"); }
  59. String getPListToMergeString() const { return settings ["customPList"]; }
  60. Value getExtraFrameworksValue() { return getSetting (Ids::extraFrameworks); }
  61. String getExtraFrameworksString() const { return settings [Ids::extraFrameworks]; }
  62. Value getPostBuildScriptValue() { return getSetting (Ids::postbuildCommand); }
  63. String getPostBuildScript() const { return settings [Ids::postbuildCommand]; }
  64. Value getPreBuildScriptValue() { return getSetting (Ids::prebuildCommand); }
  65. String getPreBuildScript() const { return settings [Ids::prebuildCommand]; }
  66. bool isAvailableOnCurrentOS()
  67. {
  68. #if JUCE_MAC
  69. return true;
  70. #else
  71. return false;
  72. #endif
  73. }
  74. bool usesMMFiles() const { return true; }
  75. bool isXcode() const { return true; }
  76. bool isOSX() const { return ! iOS; }
  77. bool canCopeWithDuplicateFiles() { return true; }
  78. void createExporterProperties (PropertyListBuilder& props)
  79. {
  80. if (projectType.isGUIApplication() && ! iOS)
  81. {
  82. props.add (new TextPropertyComponent (getSetting ("documentExtensions"), "Document file extensions", 128, false),
  83. "A comma-separated list of file extensions for documents that your app can open. "
  84. "Using a leading '.' is optional, and the extensions are not case-sensitive.");
  85. }
  86. else if (iOS)
  87. {
  88. props.add (new BooleanPropertyComponent (getSetting ("UIFileSharingEnabled"), "File Sharing Enabled", "Enabled"),
  89. "Enable this to expose your app's files to iTunes.");
  90. props.add (new BooleanPropertyComponent (getSetting ("UIStatusBarHidden"), "Status Bar Hidden", "Enabled"),
  91. "Enable this to disable the status bar in your app.");
  92. }
  93. props.add (new TextPropertyComponent (getPListToMergeValue(), "Custom PList", 8192, true),
  94. "You can paste the contents of an XML PList file in here, and the settings that it contains will override any "
  95. "settings that the Introjucer creates. BEWARE! When doing this, be careful to remove from the XML any "
  96. "values that you DO want the introjucer to change!");
  97. props.add (new TextPropertyComponent (getExtraFrameworksValue(), "Extra Frameworks", 2048, false),
  98. "A comma-separated list of extra frameworks that should be added to the build. "
  99. "(Don't include the .framework extension in the name)");
  100. if (projectType.isLibrary())
  101. {
  102. const char* const libTypes[] = { "Static Library (.a)", "Dynamic Library (.dylib)", 0 };
  103. const int libTypeValues[] = { 1, 2, 0 };
  104. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type",
  105. StringArray (libTypes), Array<var> (libTypeValues)));
  106. }
  107. props.add (new TextPropertyComponent (getPreBuildScriptValue(), "Pre-build shell script", 32768, true),
  108. "Some shell-script that will be run before a build starts.");
  109. props.add (new TextPropertyComponent (getPostBuildScriptValue(), "Post-build shell script", 32768, true),
  110. "Some shell-script that will be run after a build completes.");
  111. }
  112. bool launchProject()
  113. {
  114. #if JUCE_MAC
  115. return getProjectBundle().startAsProcess();
  116. #else
  117. return false;
  118. #endif
  119. }
  120. //==============================================================================
  121. void create (const OwnedArray<LibraryModule>&) const
  122. {
  123. infoPlistFile = getTargetFolder().getChildFile ("Info.plist");
  124. menuNibFile = getTargetFolder().getChildFile ("RecentFilesMenuTemplate.nib");
  125. createIconFile();
  126. File projectBundle (getProjectBundle());
  127. createDirectoryOrThrow (projectBundle);
  128. createObjects();
  129. File projectFile (projectBundle.getChildFile ("project.pbxproj"));
  130. {
  131. MemoryOutputStream mo;
  132. writeProjectFile (mo);
  133. overwriteFileIfDifferentOrThrow (projectFile, mo);
  134. }
  135. writeInfoPlistFile();
  136. }
  137. protected:
  138. Value getLibraryType() { return getSetting (Ids::libraryType); }
  139. bool isStaticLibrary() const { return projectType.isLibrary() && (int) settings [Ids::libraryType] == 1; }
  140. //==============================================================================
  141. class XcodeBuildConfiguration : public BuildConfiguration
  142. {
  143. public:
  144. XcodeBuildConfiguration (Project& p, const ValueTree& t, const bool isIOS)
  145. : BuildConfiguration (p, t), iOS (isIOS)
  146. {
  147. if (iOS)
  148. {
  149. if (getiOSCompatibilityVersion().isEmpty())
  150. getiOSCompatibilityVersionValue() = osxVersionDefault;
  151. }
  152. else
  153. {
  154. if (getMacSDKVersion().isEmpty())
  155. getMacSDKVersionValue() = osxVersionDefault;
  156. if (getMacCompatibilityVersion().isEmpty())
  157. getMacCompatibilityVersionValue() = osxVersionDefault;
  158. if (getMacArchitecture().isEmpty())
  159. getMacArchitectureValue() = osxArch_Default;
  160. }
  161. }
  162. Value getMacSDKVersionValue() { return getValue (Ids::osxSDK); }
  163. String getMacSDKVersion() const { return config [Ids::osxSDK]; }
  164. Value getMacCompatibilityVersionValue() { return getValue (Ids::osxCompatibility); }
  165. String getMacCompatibilityVersion() const { return config [Ids::osxCompatibility]; }
  166. Value getiOSCompatibilityVersionValue() { return getValue (Ids::iosCompatibility); }
  167. String getiOSCompatibilityVersion() const { return config [Ids::iosCompatibility]; }
  168. Value getMacArchitectureValue() { return getValue (Ids::osxArchitecture); }
  169. String getMacArchitecture() const { return config [Ids::osxArchitecture]; }
  170. Value getCustomXcodeFlagsValue() { return getValue (Ids::customXcodeFlags); }
  171. String getCustomXcodeFlags() const { return config [Ids::customXcodeFlags]; }
  172. Value getCppLibTypeValue() { return getValue (Ids::cppLibType); }
  173. String getCppLibType() const { return config [Ids::cppLibType]; }
  174. void createConfigProperties (PropertyListBuilder& props)
  175. {
  176. if (iOS)
  177. {
  178. const char* iosVersions[] = { "Use Default", "3.2", "4.0", "4.1", "4.2", "4.3", "5.0", "5.1", 0 };
  179. const char* iosVersionValues[] = { osxVersionDefault, "3.2", "4.0", "4.1", "4.2", "4.3", "5.0", "5.1", 0 };
  180. props.add (new ChoicePropertyComponent (getiOSCompatibilityVersionValue(), "iOS Deployment Target",
  181. StringArray (iosVersions), Array<var> (iosVersionValues)),
  182. "The minimum version of iOS that the target binary will run on.");
  183. }
  184. else
  185. {
  186. const char* osxVersions[] = { "Use Default", osxVersion10_5, osxVersion10_6, osxVersion10_7, 0 };
  187. const char* osxVersionValues[] = { osxVersionDefault, osxVersion10_5, osxVersion10_6, osxVersion10_7, 0 };
  188. props.add (new ChoicePropertyComponent (getMacSDKVersionValue(), "OSX Base SDK Version",
  189. StringArray (osxVersions), Array<var> (osxVersionValues)),
  190. "The version of OSX to link against in the XCode build.");
  191. props.add (new ChoicePropertyComponent (getMacCompatibilityVersionValue(), "OSX Compatibility Version",
  192. StringArray (osxVersions), Array<var> (osxVersionValues)),
  193. "The minimum version of OSX that the target binary will be compatible with.");
  194. const char* osxArch[] = { "Use Default", "Native architecture of build machine",
  195. "Universal Binary (32-bit)", "Universal Binary (64-bit)", "64-bit Intel", 0 };
  196. const char* osxArchValues[] = { osxArch_Default, osxArch_Native, osxArch_32BitUniversal,
  197. osxArch_64BitUniversal, osxArch_64Bit, 0 };
  198. props.add (new ChoicePropertyComponent (getMacArchitectureValue(), "OSX Architecture",
  199. StringArray (osxArch), Array<var> (osxArchValues)),
  200. "The type of OSX binary that will be produced.");
  201. }
  202. props.add (new TextPropertyComponent (getCustomXcodeFlagsValue(), "Custom Xcode flags", 8192, false),
  203. "A comma-separated list of custom Xcode setting flags which will be appended to the list of generated flags, "
  204. "e.g. MACOSX_DEPLOYMENT_TARGET_i386 = 10.5, VALID_ARCHS = \"ppc i386 x86_64\"");
  205. const char* cppLibNames[] = { "Use Default", "Use LLVM libc++", 0 };
  206. Array<var> cppLibValues;
  207. cppLibValues.add (var::null);
  208. cppLibValues.add ("libc++");
  209. props.add (new ChoicePropertyComponent (getCppLibTypeValue(), "C++ Library", StringArray (cppLibNames), cppLibValues),
  210. "The type of C++ std lib that will be linked.");
  211. }
  212. bool iOS;
  213. };
  214. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  215. {
  216. return new XcodeBuildConfiguration (project, settings, iOS);
  217. }
  218. private:
  219. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  220. mutable StringArray buildPhaseIDs, resourceIDs, sourceIDs, frameworkIDs;
  221. mutable StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  222. mutable File infoPlistFile, menuNibFile, iconFile;
  223. const bool iOS;
  224. static String sanitisePath (const String& path)
  225. {
  226. if (path.startsWithChar ('~'))
  227. return "$(HOME)" + path.substring (1);
  228. return path;
  229. }
  230. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  231. //==============================================================================
  232. void createObjects() const
  233. {
  234. addFrameworks();
  235. addMainBuildProduct();
  236. if (xcodeCreatePList)
  237. {
  238. RelativePath plistPath (infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  239. addFileReference (plistPath.toUnixStyle());
  240. resourceFileRefs.add (createFileRefID (plistPath));
  241. }
  242. if (! iOS)
  243. {
  244. MemoryOutputStream nib;
  245. nib.write (BinaryData::RecentFilesMenuTemplate_nib, BinaryData::RecentFilesMenuTemplate_nibSize);
  246. overwriteFileIfDifferentOrThrow (menuNibFile, nib);
  247. RelativePath menuNibPath (menuNibFile, getTargetFolder(), RelativePath::buildTargetFolder);
  248. addFileReference (menuNibPath.toUnixStyle());
  249. resourceIDs.add (addBuildFile (menuNibPath, false, false));
  250. resourceFileRefs.add (createFileRefID (menuNibPath));
  251. }
  252. if (iconFile.exists())
  253. {
  254. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  255. addFileReference (iconPath.toUnixStyle());
  256. resourceIDs.add (addBuildFile (iconPath, false, false));
  257. resourceFileRefs.add (createFileRefID (iconPath));
  258. }
  259. {
  260. StringArray topLevelGroupIDs;
  261. for (int i = 0; i < getAllGroups().size(); ++i)
  262. {
  263. const Project::Item& group = getAllGroups().getReference(i);
  264. if (group.getNumChildren() > 0)
  265. topLevelGroupIDs.add (addProjectItem (group));
  266. }
  267. { // Add 'resources' group
  268. String resourcesGroupID (createID ("__resources"));
  269. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  270. topLevelGroupIDs.add (resourcesGroupID);
  271. }
  272. { // Add 'frameworks' group
  273. String frameworksGroupID (createID ("__frameworks"));
  274. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  275. topLevelGroupIDs.add (frameworksGroupID);
  276. }
  277. { // Add 'products' group
  278. String productsGroupID (createID ("__products"));
  279. StringArray products;
  280. products.add (createID ("__productFileID"));
  281. addGroup (productsGroupID, "Products", products);
  282. topLevelGroupIDs.add (productsGroupID);
  283. }
  284. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  285. }
  286. for (ConstConfigIterator config (*this); config.next();)
  287. {
  288. const XcodeBuildConfiguration& xcodeConfig = dynamic_cast <const XcodeBuildConfiguration&> (*config);
  289. addProjectConfig (config->getName(), getProjectSettings (xcodeConfig));
  290. addTargetConfig (config->getName(), getTargetSettings (xcodeConfig));
  291. }
  292. addConfigList (projectConfigs, createID ("__projList"));
  293. addConfigList (targetConfigs, createID ("__configList"));
  294. addShellScriptBuildPhase ("Pre-build script", getPreBuildScript());
  295. if (! isStaticLibrary())
  296. addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  297. if (rezFileIDs.size() > 0)
  298. addBuildPhase ("PBXRezBuildPhase", rezFileIDs);
  299. addBuildPhase ("PBXSourcesBuildPhase", sourceIDs);
  300. if (! isStaticLibrary())
  301. addBuildPhase ("PBXFrameworksBuildPhase", frameworkIDs);
  302. addShellScriptBuildPhase ("Post-build script", getPostBuildScript());
  303. addTargetObject();
  304. addProjectObject();
  305. }
  306. static Image fixMacIconImageSize (Image& image)
  307. {
  308. const int validSizes[] = { 16, 32, 48, 128, 256, 512, 1024 };
  309. const int w = image.getWidth();
  310. const int h = image.getHeight();
  311. int bestSize = 16;
  312. for (int i = 0; i < numElementsInArray (validSizes); ++i)
  313. {
  314. if (w == h && w == validSizes[i])
  315. return image;
  316. if (jmax (w, h) > validSizes[i])
  317. bestSize = validSizes[i];
  318. }
  319. return rescaleImageForIcon (image, bestSize);
  320. }
  321. static void writeOldIconFormat (MemoryOutputStream& out, const Image& image, const char* type, const char* maskType)
  322. {
  323. const int w = image.getWidth();
  324. const int h = image.getHeight();
  325. out.write (type, 4);
  326. out.writeIntBigEndian (8 + 4 * w * h);
  327. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  328. for (int y = 0; y < h; ++y)
  329. {
  330. for (int x = 0; x < w; ++x)
  331. {
  332. const Colour pixel (bitmap.getPixelColour (x, y));
  333. out.writeByte ((char) pixel.getAlpha());
  334. out.writeByte ((char) pixel.getRed());
  335. out.writeByte ((char) pixel.getGreen());
  336. out.writeByte ((char) pixel.getBlue());
  337. }
  338. }
  339. out.write (maskType, 4);
  340. out.writeIntBigEndian (8 + w * h);
  341. for (int y = 0; y < h; ++y)
  342. {
  343. for (int x = 0; x < w; ++x)
  344. {
  345. const Colour pixel (bitmap.getPixelColour (x, y));
  346. out.writeByte ((char) pixel.getAlpha());
  347. }
  348. }
  349. }
  350. static void writeNewIconFormat (MemoryOutputStream& out, const Image& image, const char* type)
  351. {
  352. MemoryOutputStream pngData;
  353. PNGImageFormat pngFormat;
  354. pngFormat.writeImageToStream (image, pngData);
  355. out.write (type, 4);
  356. out.writeIntBigEndian (8 + pngData.getDataSize());
  357. out << pngData;
  358. }
  359. void writeIcnsFile (const Array<Image>& images, OutputStream& out) const
  360. {
  361. MemoryOutputStream data;
  362. for (int i = 0; i < images.size(); ++i)
  363. {
  364. const Image image (fixMacIconImageSize (images.getReference (i)));
  365. jassert (image.getWidth() == image.getHeight());
  366. switch (image.getWidth())
  367. {
  368. case 16: writeOldIconFormat (data, image, "is32", "s8mk"); break;
  369. case 32: writeOldIconFormat (data, image, "il32", "l8mk"); break;
  370. case 48: writeOldIconFormat (data, image, "ih32", "h8mk"); break;
  371. case 128: writeOldIconFormat (data, image, "it32", "t8mk"); break;
  372. case 256: writeNewIconFormat (data, image, "ic08"); break;
  373. case 512: writeNewIconFormat (data, image, "ic09"); break;
  374. case 1024: writeNewIconFormat (data, image, "ic10"); break;
  375. default: break;
  376. }
  377. }
  378. jassert (data.getDataSize() > 0); // no suitable sized images?
  379. out.write ("icns", 4);
  380. out.writeIntBigEndian (data.getDataSize() + 8);
  381. out << data;
  382. }
  383. void createIconFile() const
  384. {
  385. Array<Image> images;
  386. Image bigIcon (getBigIcon());
  387. if (bigIcon.isValid())
  388. images.add (bigIcon);
  389. Image smallIcon (getSmallIcon());
  390. if (smallIcon.isValid())
  391. images.add (smallIcon);
  392. if (images.size() > 0)
  393. {
  394. MemoryOutputStream mo;
  395. writeIcnsFile (images, mo);
  396. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  397. overwriteFileIfDifferentOrThrow (iconFile, mo);
  398. }
  399. }
  400. void writeInfoPlistFile() const
  401. {
  402. if (! xcodeCreatePList)
  403. return;
  404. ScopedPointer<XmlElement> plist (XmlDocument::parse (getPListToMergeString()));
  405. if (plist == nullptr || ! plist->hasTagName ("plist"))
  406. plist = new XmlElement ("plist");
  407. XmlElement* dict = plist->getChildByName ("dict");
  408. if (dict == nullptr)
  409. dict = plist->createNewChildElement ("dict");
  410. if (iOS)
  411. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  412. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  413. addPlistDictionaryKey (dict, "CFBundleIconFile", iconFile.exists() ? iconFile.getFileName() : String::empty);
  414. addPlistDictionaryKey (dict, "CFBundleIdentifier", project.getBundleIdentifier().toString());
  415. addPlistDictionaryKey (dict, "CFBundleName", projectName);
  416. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  417. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  418. addPlistDictionaryKey (dict, "CFBundleShortVersionString", project.getVersionString());
  419. addPlistDictionaryKey (dict, "CFBundleVersion", project.getVersionString());
  420. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", project.getCompanyName().toString());
  421. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  422. StringArray documentExtensions;
  423. documentExtensions.addTokens (replacePreprocessorDefs (getAllPreprocessorDefs(), settings ["documentExtensions"]),
  424. ",", String::empty);
  425. documentExtensions.trim();
  426. documentExtensions.removeEmptyStrings (true);
  427. if (documentExtensions.size() > 0)
  428. {
  429. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  430. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  431. XmlElement* arrayTag = nullptr;
  432. for (int i = 0; i < documentExtensions.size(); ++i)
  433. {
  434. String ex (documentExtensions[i]);
  435. if (ex.startsWithChar ('.'))
  436. ex = ex.substring (1);
  437. if (arrayTag == nullptr)
  438. {
  439. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  440. arrayTag = dict2->createNewChildElement ("array");
  441. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  442. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  443. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  444. }
  445. arrayTag->createNewChildElement ("string")->addTextElement (ex);
  446. }
  447. }
  448. if (settings ["UIFileSharingEnabled"])
  449. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  450. if (settings ["UIStatusBarHidden"])
  451. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  452. for (int i = 0; i < xcodeExtraPListEntries.size(); ++i)
  453. dict->addChildElement (new XmlElement (xcodeExtraPListEntries.getReference(i)));
  454. MemoryOutputStream mo;
  455. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  456. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  457. }
  458. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  459. {
  460. StringArray searchPaths (extraSearchPaths);
  461. searchPaths.addArray (config.getHeaderSearchPaths());
  462. searchPaths.removeDuplicates (false);
  463. return searchPaths;
  464. }
  465. void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths) const
  466. {
  467. jassert (library.getFileNameWithoutExtension().substring (0, 3) == "lib");
  468. flags.add ("-l" + library.getFileNameWithoutExtension().substring (3));
  469. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  470. if (! library.isAbsolute())
  471. {
  472. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  473. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  474. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  475. searchPath = srcRoot + searchPath;
  476. }
  477. librarySearchPaths.add (sanitisePath (searchPath));
  478. }
  479. void getLinkerFlags (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  480. {
  481. if (xcodeIsBundle)
  482. flags.add ("-bundle");
  483. const Array<RelativePath>& extraLibs = config.isDebug() ? xcodeExtraLibrariesDebug
  484. : xcodeExtraLibrariesRelease;
  485. for (int i = 0; i < extraLibs.size(); ++i)
  486. getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
  487. flags.add (replacePreprocessorTokens (config, getExtraLinkerFlagsString()));
  488. flags.add (getExternalLibraryFlags (config));
  489. flags.removeEmptyStrings (true);
  490. }
  491. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  492. {
  493. StringArray s;
  494. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  495. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  496. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  497. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  498. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  499. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  500. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  501. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  502. s.add ("WARNING_CFLAGS = -Wreorder");
  503. s.add ("GCC_MODEL_TUNING = G5");
  504. if (projectType.isLibrary())
  505. {
  506. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  507. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  508. }
  509. else
  510. {
  511. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  512. }
  513. if (iOS)
  514. {
  515. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  516. s.add ("SDKROOT = iphoneos");
  517. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  518. const String iosVersion (config.getiOSCompatibilityVersion());
  519. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  520. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  521. }
  522. s.add ("ZERO_LINK = NO");
  523. if (xcodeCanUseDwarf)
  524. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  525. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryNameString() + "\"");
  526. return s;
  527. }
  528. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  529. {
  530. StringArray s;
  531. const String arch (config.getMacArchitecture());
  532. if (arch == osxArch_Native) s.add ("ARCHS = \"$(ARCHS_NATIVE)\"");
  533. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  534. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  535. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  536. s.add ("HEADER_SEARCH_PATHS = \"" + replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" ")) + " $(inherited)\"");
  537. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  538. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  539. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  540. if (extraFlags.isNotEmpty())
  541. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  542. if (xcodeProductInstallPath.isNotEmpty())
  543. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  544. if (xcodeIsBundle)
  545. {
  546. s.add ("LIBRARY_STYLE = Bundle");
  547. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  548. s.add ("GENERATE_PKGINFO_FILE = YES");
  549. }
  550. if (xcodeOtherRezFlags.isNotEmpty())
  551. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  552. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  553. {
  554. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  555. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  556. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  557. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  558. }
  559. if (projectType.isLibrary())
  560. {
  561. s.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  562. s.add ("DEPLOYMENT_LOCATION = YES");
  563. }
  564. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  565. if (! iOS)
  566. {
  567. const String sdk (config.getMacSDKVersion());
  568. const String sdkCompat (config.getMacCompatibilityVersion());
  569. if (sdk == osxVersion10_5) s.add ("SDKROOT = macosx10.5");
  570. else if (sdk == osxVersion10_6) s.add ("SDKROOT = macosx10.6");
  571. else if (sdk == osxVersion10_7) s.add ("SDKROOT = macosx10.7");
  572. if (sdkCompat == osxVersion10_4) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.4");
  573. else if (sdkCompat == osxVersion10_5) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.5");
  574. else if (sdkCompat == osxVersion10_6) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.6");
  575. else if (sdkCompat == osxVersion10_7) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.7");
  576. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  577. s.add ("SDKROOT_ppc = macosx10.5");
  578. if (xcodeExcludedFiles64Bit.isNotEmpty())
  579. {
  580. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  581. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  582. }
  583. }
  584. s.add ("GCC_VERSION = " + gccVersion);
  585. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  586. s.add ("CLANG_LINK_OBJC_RUNTIME = NO");
  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. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  773. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  774. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  775. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  776. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  777. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  778. if (file.hasFileExtension ("html;htm")) return "text.html";
  779. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  780. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  781. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  782. if (file.hasFileExtension ("app")) return "wrapper.application";
  783. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  784. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  785. 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. int n = 0;
  918. while (buildPhaseIDs.contains (phaseId))
  919. phaseId = createID (phaseType + "resbuildphase" + String (++n));
  920. buildPhaseIDs.add (phaseId);
  921. ValueTree* v = new ValueTree (phaseId);
  922. v->setProperty ("isa", phaseType, nullptr);
  923. v->setProperty ("buildActionMask", "2147483647", nullptr);
  924. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", nullptr);
  925. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  926. misc.add (v);
  927. return *v;
  928. }
  929. void addTargetObject() const
  930. {
  931. ValueTree* const v = new ValueTree (createID ("__target"));
  932. v->setProperty ("isa", "PBXNativeTarget", nullptr);
  933. v->setProperty ("buildConfigurationList", createID ("__configList"), nullptr);
  934. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", nullptr);
  935. v->setProperty ("buildRules", "( )", nullptr);
  936. v->setProperty ("dependencies", "( )", nullptr);
  937. v->setProperty (Ids::name, projectName, nullptr);
  938. v->setProperty ("productName", projectName, nullptr);
  939. v->setProperty ("productReference", createID ("__productFileID"), nullptr);
  940. if (xcodeProductInstallPath.isNotEmpty())
  941. v->setProperty ("productInstallPath", xcodeProductInstallPath, nullptr);
  942. jassert (xcodeProductType.isNotEmpty());
  943. v->setProperty ("productType", xcodeProductType, nullptr);
  944. misc.add (v);
  945. }
  946. void addProjectObject() const
  947. {
  948. ValueTree* const v = new ValueTree (createID ("__root"));
  949. v->setProperty ("isa", "PBXProject", nullptr);
  950. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  951. v->setProperty ("attributes", "{ LastUpgradeCheck = 0440; }", nullptr);
  952. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  953. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  954. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  955. v->setProperty ("projectDirPath", "\"\"", nullptr);
  956. v->setProperty ("projectRoot", "\"\"", nullptr);
  957. v->setProperty ("targets", "( " + createID ("__target") + " )", nullptr);
  958. misc.add (v);
  959. }
  960. void addShellScriptBuildPhase (const String& name, const String& script) const
  961. {
  962. if (script.trim().isNotEmpty())
  963. {
  964. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  965. v.setProperty (Ids::name, name, nullptr);
  966. v.setProperty ("shellPath", "/bin/sh", nullptr);
  967. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  968. .replace ("\"", "\\\"")
  969. .replace ("\r\n", "\\n")
  970. .replace ("\n", "\\n"), nullptr);
  971. }
  972. }
  973. //==============================================================================
  974. static String indentList (const StringArray& list, const String& separator)
  975. {
  976. if (list.size() == 0)
  977. return " ";
  978. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  979. + (separator == ";" ? separator : String::empty);
  980. }
  981. String createID (String rootString) const
  982. {
  983. if (rootString.startsWith ("${"))
  984. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  985. rootString += project.getProjectUID();
  986. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  987. }
  988. String createFileRefID (const RelativePath& path) const
  989. {
  990. return createFileRefID (path.toUnixStyle());
  991. }
  992. String createFileRefID (const String& path) const
  993. {
  994. return createID ("__fileref_" + path);
  995. }
  996. String getIDForGroup (const Project::Item& item) const
  997. {
  998. return createID (item.getID());
  999. }
  1000. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  1001. {
  1002. return file.hasFileExtension (sourceFileExtensions);
  1003. }
  1004. };
  1005. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__