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. StringArray libraries;
  489. libraries.addTokens (getExternalLibrariesString(), ";", "\"'");
  490. libraries.removeEmptyStrings (true);
  491. if (libraries.size() != 0)
  492. flags.add (replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim());
  493. flags.removeEmptyStrings (true);
  494. }
  495. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  496. {
  497. StringArray s;
  498. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  499. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  500. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  501. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  502. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  503. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  504. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  505. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  506. s.add ("WARNING_CFLAGS = -Wreorder");
  507. s.add ("GCC_MODEL_TUNING = G5");
  508. if (projectType.isLibrary())
  509. {
  510. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  511. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  512. }
  513. else
  514. {
  515. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  516. }
  517. if (iOS)
  518. {
  519. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  520. s.add ("SDKROOT = iphoneos");
  521. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  522. const String iosVersion (config.getiOSCompatibilityVersion());
  523. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  524. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  525. }
  526. s.add ("ZERO_LINK = NO");
  527. if (xcodeCanUseDwarf)
  528. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  529. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryNameString() + "\"");
  530. return s;
  531. }
  532. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  533. {
  534. StringArray s;
  535. const String arch (config.getMacArchitecture());
  536. if (arch == osxArch_Native) s.add ("ARCHS = \"$(ARCHS_NATIVE)\"");
  537. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  538. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  539. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  540. s.add ("HEADER_SEARCH_PATHS = \"" + replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" ")) + " $(inherited)\"");
  541. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  542. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  543. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  544. if (extraFlags.isNotEmpty())
  545. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  546. if (xcodeProductInstallPath.isNotEmpty())
  547. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  548. if (xcodeIsBundle)
  549. {
  550. s.add ("LIBRARY_STYLE = Bundle");
  551. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  552. s.add ("GENERATE_PKGINFO_FILE = YES");
  553. }
  554. if (xcodeOtherRezFlags.isNotEmpty())
  555. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  556. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  557. {
  558. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  559. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  560. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  561. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  562. }
  563. if (projectType.isLibrary())
  564. {
  565. s.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  566. s.add ("DEPLOYMENT_LOCATION = YES");
  567. }
  568. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  569. if (! iOS)
  570. {
  571. const String sdk (config.getMacSDKVersion());
  572. const String sdkCompat (config.getMacCompatibilityVersion());
  573. if (sdk == osxVersion10_5) s.add ("SDKROOT = macosx10.5");
  574. else if (sdk == osxVersion10_6) s.add ("SDKROOT = macosx10.6");
  575. else if (sdk == osxVersion10_7) s.add ("SDKROOT = macosx10.7");
  576. if (sdkCompat == osxVersion10_4) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.4");
  577. else if (sdkCompat == osxVersion10_5) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.5");
  578. else if (sdkCompat == osxVersion10_6) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.6");
  579. else if (sdkCompat == osxVersion10_7) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.7");
  580. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  581. s.add ("SDKROOT_ppc = macosx10.5");
  582. if (xcodeExcludedFiles64Bit.isNotEmpty())
  583. {
  584. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  585. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  586. }
  587. }
  588. s.add ("GCC_VERSION = " + gccVersion);
  589. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  590. if (config.getCppLibType().isNotEmpty())
  591. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  592. s.add ("COMBINE_HIDPI_IMAGES = YES");
  593. {
  594. StringArray linkerFlags, librarySearchPaths;
  595. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  596. if (linkerFlags.size() > 0)
  597. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  598. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  599. librarySearchPaths.removeDuplicates (false);
  600. if (librarySearchPaths.size() > 0)
  601. {
  602. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  603. for (int i = 0; i < librarySearchPaths.size(); ++i)
  604. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  605. s.add (libPaths + ")");
  606. }
  607. }
  608. StringPairArray defines;
  609. if (config.isDebug())
  610. {
  611. defines.set ("_DEBUG", "1");
  612. defines.set ("DEBUG", "1");
  613. if (config.getMacArchitecture() == osxArch_Default
  614. || config.getMacArchitecture().isEmpty())
  615. s.add ("ONLY_ACTIVE_ARCH = YES");
  616. s.add ("COPY_PHASE_STRIP = NO");
  617. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  618. }
  619. else
  620. {
  621. defines.set ("_NDEBUG", "1");
  622. defines.set ("NDEBUG", "1");
  623. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  624. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  625. }
  626. {
  627. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  628. StringArray defsList;
  629. for (int i = 0; i < defines.size(); ++i)
  630. {
  631. String def (defines.getAllKeys()[i]);
  632. const String value (defines.getAllValues()[i]);
  633. if (value.isNotEmpty())
  634. def << "=" << value.replace ("\"", "\\\"");
  635. defsList.add ("\"" + def + "\"");
  636. }
  637. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  638. }
  639. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  640. s.trim();
  641. s.removeEmptyStrings();
  642. s.removeDuplicates (false);
  643. return s;
  644. }
  645. void addFrameworks() const
  646. {
  647. if (! isStaticLibrary())
  648. {
  649. StringArray s (xcodeFrameworks);
  650. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  651. s.trim();
  652. s.removeDuplicates (true);
  653. s.sort (true);
  654. for (int i = 0; i < s.size(); ++i)
  655. addFramework (s[i]);
  656. }
  657. }
  658. //==============================================================================
  659. void writeProjectFile (OutputStream& output) const
  660. {
  661. output << "// !$*UTF8*$!\n{\n"
  662. "\tarchiveVersion = 1;\n"
  663. "\tclasses = {\n\t};\n"
  664. "\tobjectVersion = 46;\n"
  665. "\tobjects = {\n\n";
  666. Array <ValueTree*> objects;
  667. objects.addArray (pbxBuildFiles);
  668. objects.addArray (pbxFileReferences);
  669. objects.addArray (pbxGroups);
  670. objects.addArray (targetConfigs);
  671. objects.addArray (projectConfigs);
  672. objects.addArray (misc);
  673. for (int i = 0; i < objects.size(); ++i)
  674. {
  675. ValueTree& o = *objects.getUnchecked(i);
  676. output << "\t\t" << o.getType().toString() << " = { ";
  677. for (int j = 0; j < o.getNumProperties(); ++j)
  678. {
  679. const Identifier propertyName (o.getPropertyName(j));
  680. String val (o.getProperty (propertyName).toString());
  681. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n")
  682. && ! (val.trimStart().startsWithChar ('(')
  683. || val.trimStart().startsWithChar ('{'))))
  684. val = "\"" + val + "\"";
  685. output << propertyName.toString() << " = " << val << "; ";
  686. }
  687. output << "};\n";
  688. }
  689. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  690. }
  691. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  692. {
  693. forEachXmlChildElementWithTagName (*xml, e, "key")
  694. {
  695. if (e->getAllSubText().trim().equalsIgnoreCase (key))
  696. {
  697. if (e->getNextElement() != nullptr && e->getNextElement()->hasTagName ("key"))
  698. {
  699. // try to fix broken plist format..
  700. xml->removeChildElement (e, true);
  701. break;
  702. }
  703. else
  704. {
  705. return; // (value already exists)
  706. }
  707. }
  708. }
  709. xml->createNewChildElement ("key") ->addTextElement (key);
  710. xml->createNewChildElement ("string")->addTextElement (value);
  711. }
  712. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  713. {
  714. xml->createNewChildElement ("key")->addTextElement (key);
  715. xml->createNewChildElement (value ? "true" : "false");
  716. }
  717. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  718. {
  719. String fileID (createID (path + "buildref"));
  720. if (addToSourceBuildPhase)
  721. sourceIDs.add (fileID);
  722. ValueTree* v = new ValueTree (fileID);
  723. v->setProperty ("isa", "PBXBuildFile", nullptr);
  724. v->setProperty ("fileRef", fileRefID, nullptr);
  725. if (inhibitWarnings)
  726. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  727. pbxBuildFiles.add (v);
  728. return fileID;
  729. }
  730. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  731. {
  732. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  733. }
  734. String addFileReference (String pathString) const
  735. {
  736. String sourceTree ("SOURCE_ROOT");
  737. RelativePath path (pathString, RelativePath::unknown);
  738. if (pathString.startsWith ("${"))
  739. {
  740. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  741. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  742. }
  743. else if (path.isAbsolute())
  744. {
  745. sourceTree = "<absolute>";
  746. }
  747. const String fileRefID (createFileRefID (pathString));
  748. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  749. v->setProperty ("isa", "PBXFileReference", nullptr);
  750. v->setProperty ("lastKnownFileType", getFileType (path), nullptr);
  751. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  752. v->setProperty ("path", sanitisePath (pathString), nullptr);
  753. v->setProperty ("sourceTree", sourceTree, nullptr);
  754. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  755. if (existing >= 0)
  756. {
  757. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  758. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  759. }
  760. else
  761. {
  762. pbxFileReferences.addSorted (*this, v.release());
  763. }
  764. return fileRefID;
  765. }
  766. public:
  767. static int compareElements (const ValueTree* first, const ValueTree* second)
  768. {
  769. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  770. }
  771. private:
  772. static String getFileType (const RelativePath& file)
  773. {
  774. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  775. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  776. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  777. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  778. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  779. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  780. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  781. if (file.hasFileExtension ("html;htm")) return "text.html";
  782. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  783. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  784. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  785. if (file.hasFileExtension ("app")) return "wrapper.application";
  786. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  787. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  788. if (file.hasFileExtension ("a")) return "archive.ar";
  789. return "file" + file.getFileExtension();
  790. }
  791. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources, bool inhibitWarnings) const
  792. {
  793. const String pathAsString (path.toUnixStyle());
  794. const String refID (addFileReference (path.toUnixStyle()));
  795. if (shouldBeCompiled)
  796. {
  797. if (path.hasFileExtension (".r"))
  798. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  799. else
  800. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  801. }
  802. else if (! shouldBeAddedToBinaryResources)
  803. {
  804. const String fileType (getFileType (path));
  805. if (fileType.startsWith ("image.") || fileType.startsWith ("text.") || fileType.startsWith ("file."))
  806. {
  807. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  808. resourceFileRefs.add (refID);
  809. }
  810. }
  811. return refID;
  812. }
  813. String addProjectItem (const Project::Item& projectItem) const
  814. {
  815. if (projectItem.isGroup())
  816. {
  817. StringArray childIDs;
  818. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  819. {
  820. const String childID (addProjectItem (projectItem.getChild(i)));
  821. if (childID.isNotEmpty())
  822. childIDs.add (childID);
  823. }
  824. return addGroup (projectItem, childIDs);
  825. }
  826. else
  827. {
  828. if (projectItem.shouldBeAddedToTargetProject())
  829. {
  830. const String itemPath (projectItem.getFilePath());
  831. RelativePath path;
  832. if (itemPath.startsWith ("${"))
  833. path = RelativePath (itemPath, RelativePath::unknown);
  834. else
  835. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  836. return addFile (path, projectItem.shouldBeCompiled(),
  837. projectItem.shouldBeAddedToBinaryResources(),
  838. projectItem.shouldInhibitWarnings());
  839. }
  840. }
  841. return String::empty;
  842. }
  843. void addFramework (const String& frameworkName) const
  844. {
  845. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  846. const String fileRefID (createFileRefID (path));
  847. addFileReference ("${SDKROOT}/" + path);
  848. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  849. frameworkFileIDs.add (fileRefID);
  850. }
  851. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  852. {
  853. ValueTree* v = new ValueTree (groupID);
  854. v->setProperty ("isa", "PBXGroup", nullptr);
  855. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", nullptr);
  856. v->setProperty (Ids::name, groupName, nullptr);
  857. v->setProperty ("sourceTree", "<group>", nullptr);
  858. pbxGroups.add (v);
  859. }
  860. String addGroup (const Project::Item& item, StringArray& childIDs) const
  861. {
  862. const String groupName (item.getName());
  863. const String groupID (getIDForGroup (item));
  864. addGroup (groupID, groupName, childIDs);
  865. return groupID;
  866. }
  867. void addMainBuildProduct() const
  868. {
  869. jassert (xcodeFileType.isNotEmpty());
  870. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  871. String productName (getConfiguration(0)->getTargetBinaryName().toString());
  872. if (xcodeFileType == "archive.ar")
  873. productName = getLibbedFilename (productName);
  874. else
  875. productName += xcodeBundleExtension;
  876. addBuildProduct (xcodeFileType, productName);
  877. }
  878. void addBuildProduct (const String& fileType, const String& binaryName) const
  879. {
  880. ValueTree* v = new ValueTree (createID ("__productFileID"));
  881. v->setProperty ("isa", "PBXFileReference", nullptr);
  882. v->setProperty ("explicitFileType", fileType, nullptr);
  883. v->setProperty ("includeInIndex", (int) 0, nullptr);
  884. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  885. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  886. pbxFileReferences.add (v);
  887. }
  888. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  889. {
  890. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  891. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  892. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  893. v->setProperty (Ids::name, configName, nullptr);
  894. targetConfigs.add (v);
  895. }
  896. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  897. {
  898. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  899. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  900. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  901. v->setProperty (Ids::name, configName, nullptr);
  902. projectConfigs.add (v);
  903. }
  904. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  905. {
  906. StringArray configIDs;
  907. for (int i = 0; i < configsToUse.size(); ++i)
  908. configIDs.add (configsToUse[i]->getType().toString());
  909. ValueTree* v = new ValueTree (listID);
  910. v->setProperty ("isa", "XCConfigurationList", nullptr);
  911. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", nullptr);
  912. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  913. if (configsToUse[0] != nullptr)
  914. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), nullptr);
  915. misc.add (v);
  916. }
  917. ValueTree& addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  918. {
  919. String phaseId (createID (phaseType + "resbuildphase"));
  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__