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.

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