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.

1264 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. s.add ("CLANG_LINK_OBJC_RUNTIME = NO");
  591. if (config.getCppLibType().isNotEmpty())
  592. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  593. s.add ("COMBINE_HIDPI_IMAGES = YES");
  594. {
  595. StringArray linkerFlags, librarySearchPaths;
  596. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  597. if (linkerFlags.size() > 0)
  598. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  599. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  600. librarySearchPaths.removeDuplicates (false);
  601. if (librarySearchPaths.size() > 0)
  602. {
  603. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  604. for (int i = 0; i < librarySearchPaths.size(); ++i)
  605. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  606. s.add (libPaths + ")");
  607. }
  608. }
  609. StringPairArray defines;
  610. if (config.isDebug())
  611. {
  612. defines.set ("_DEBUG", "1");
  613. defines.set ("DEBUG", "1");
  614. if (config.getMacArchitecture() == osxArch_Default
  615. || config.getMacArchitecture().isEmpty())
  616. s.add ("ONLY_ACTIVE_ARCH = YES");
  617. s.add ("COPY_PHASE_STRIP = NO");
  618. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  619. }
  620. else
  621. {
  622. defines.set ("_NDEBUG", "1");
  623. defines.set ("NDEBUG", "1");
  624. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  625. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  626. }
  627. {
  628. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  629. StringArray defsList;
  630. for (int i = 0; i < defines.size(); ++i)
  631. {
  632. String def (defines.getAllKeys()[i]);
  633. const String value (defines.getAllValues()[i]);
  634. if (value.isNotEmpty())
  635. def << "=" << value.replace ("\"", "\\\"");
  636. defsList.add ("\"" + def + "\"");
  637. }
  638. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  639. }
  640. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  641. s.trim();
  642. s.removeEmptyStrings();
  643. s.removeDuplicates (false);
  644. return s;
  645. }
  646. void addFrameworks() const
  647. {
  648. if (! isStaticLibrary())
  649. {
  650. StringArray s (xcodeFrameworks);
  651. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  652. s.trim();
  653. s.removeDuplicates (true);
  654. s.sort (true);
  655. for (int i = 0; i < s.size(); ++i)
  656. addFramework (s[i]);
  657. }
  658. }
  659. //==============================================================================
  660. void writeProjectFile (OutputStream& output) const
  661. {
  662. output << "// !$*UTF8*$!\n{\n"
  663. "\tarchiveVersion = 1;\n"
  664. "\tclasses = {\n\t};\n"
  665. "\tobjectVersion = 46;\n"
  666. "\tobjects = {\n\n";
  667. Array <ValueTree*> objects;
  668. objects.addArray (pbxBuildFiles);
  669. objects.addArray (pbxFileReferences);
  670. objects.addArray (pbxGroups);
  671. objects.addArray (targetConfigs);
  672. objects.addArray (projectConfigs);
  673. objects.addArray (misc);
  674. for (int i = 0; i < objects.size(); ++i)
  675. {
  676. ValueTree& o = *objects.getUnchecked(i);
  677. output << "\t\t" << o.getType().toString() << " = { ";
  678. for (int j = 0; j < o.getNumProperties(); ++j)
  679. {
  680. const Identifier propertyName (o.getPropertyName(j));
  681. String val (o.getProperty (propertyName).toString());
  682. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n")
  683. && ! (val.trimStart().startsWithChar ('(')
  684. || val.trimStart().startsWithChar ('{'))))
  685. val = "\"" + val + "\"";
  686. output << propertyName.toString() << " = " << val << "; ";
  687. }
  688. output << "};\n";
  689. }
  690. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  691. }
  692. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  693. {
  694. forEachXmlChildElementWithTagName (*xml, e, "key")
  695. {
  696. if (e->getAllSubText().trim().equalsIgnoreCase (key))
  697. {
  698. if (e->getNextElement() != nullptr && e->getNextElement()->hasTagName ("key"))
  699. {
  700. // try to fix broken plist format..
  701. xml->removeChildElement (e, true);
  702. break;
  703. }
  704. else
  705. {
  706. return; // (value already exists)
  707. }
  708. }
  709. }
  710. xml->createNewChildElement ("key") ->addTextElement (key);
  711. xml->createNewChildElement ("string")->addTextElement (value);
  712. }
  713. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  714. {
  715. xml->createNewChildElement ("key")->addTextElement (key);
  716. xml->createNewChildElement (value ? "true" : "false");
  717. }
  718. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  719. {
  720. String fileID (createID (path + "buildref"));
  721. if (addToSourceBuildPhase)
  722. sourceIDs.add (fileID);
  723. ValueTree* v = new ValueTree (fileID);
  724. v->setProperty ("isa", "PBXBuildFile", nullptr);
  725. v->setProperty ("fileRef", fileRefID, nullptr);
  726. if (inhibitWarnings)
  727. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  728. pbxBuildFiles.add (v);
  729. return fileID;
  730. }
  731. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  732. {
  733. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  734. }
  735. String addFileReference (String pathString) const
  736. {
  737. String sourceTree ("SOURCE_ROOT");
  738. RelativePath path (pathString, RelativePath::unknown);
  739. if (pathString.startsWith ("${"))
  740. {
  741. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  742. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  743. }
  744. else if (path.isAbsolute())
  745. {
  746. sourceTree = "<absolute>";
  747. }
  748. const String fileRefID (createFileRefID (pathString));
  749. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  750. v->setProperty ("isa", "PBXFileReference", nullptr);
  751. v->setProperty ("lastKnownFileType", getFileType (path), nullptr);
  752. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  753. v->setProperty ("path", sanitisePath (pathString), nullptr);
  754. v->setProperty ("sourceTree", sourceTree, nullptr);
  755. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  756. if (existing >= 0)
  757. {
  758. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  759. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  760. }
  761. else
  762. {
  763. pbxFileReferences.addSorted (*this, v.release());
  764. }
  765. return fileRefID;
  766. }
  767. public:
  768. static int compareElements (const ValueTree* first, const ValueTree* second)
  769. {
  770. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  771. }
  772. private:
  773. static String getFileType (const RelativePath& file)
  774. {
  775. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  776. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  777. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  778. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  779. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  780. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  781. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  782. if (file.hasFileExtension ("html;htm")) return "text.html";
  783. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  784. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  785. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  786. if (file.hasFileExtension ("app")) return "wrapper.application";
  787. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  788. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  789. if (file.hasFileExtension ("a")) return "archive.ar";
  790. return "file" + file.getFileExtension();
  791. }
  792. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources, bool inhibitWarnings) const
  793. {
  794. const String pathAsString (path.toUnixStyle());
  795. const String refID (addFileReference (path.toUnixStyle()));
  796. if (shouldBeCompiled)
  797. {
  798. if (path.hasFileExtension (".r"))
  799. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  800. else
  801. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  802. }
  803. else if (! shouldBeAddedToBinaryResources)
  804. {
  805. const String fileType (getFileType (path));
  806. if (fileType.startsWith ("image.") || fileType.startsWith ("text.") || fileType.startsWith ("file."))
  807. {
  808. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  809. resourceFileRefs.add (refID);
  810. }
  811. }
  812. return refID;
  813. }
  814. String addProjectItem (const Project::Item& projectItem) const
  815. {
  816. if (projectItem.isGroup())
  817. {
  818. StringArray childIDs;
  819. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  820. {
  821. const String childID (addProjectItem (projectItem.getChild(i)));
  822. if (childID.isNotEmpty())
  823. childIDs.add (childID);
  824. }
  825. return addGroup (projectItem, childIDs);
  826. }
  827. else
  828. {
  829. if (projectItem.shouldBeAddedToTargetProject())
  830. {
  831. const String itemPath (projectItem.getFilePath());
  832. RelativePath path;
  833. if (itemPath.startsWith ("${"))
  834. path = RelativePath (itemPath, RelativePath::unknown);
  835. else
  836. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  837. return addFile (path, projectItem.shouldBeCompiled(),
  838. projectItem.shouldBeAddedToBinaryResources(),
  839. projectItem.shouldInhibitWarnings());
  840. }
  841. }
  842. return String::empty;
  843. }
  844. void addFramework (const String& frameworkName) const
  845. {
  846. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  847. const String fileRefID (createFileRefID (path));
  848. addFileReference ("${SDKROOT}/" + path);
  849. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  850. frameworkFileIDs.add (fileRefID);
  851. }
  852. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  853. {
  854. ValueTree* v = new ValueTree (groupID);
  855. v->setProperty ("isa", "PBXGroup", nullptr);
  856. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", nullptr);
  857. v->setProperty (Ids::name, groupName, nullptr);
  858. v->setProperty ("sourceTree", "<group>", nullptr);
  859. pbxGroups.add (v);
  860. }
  861. String addGroup (const Project::Item& item, StringArray& childIDs) const
  862. {
  863. const String groupName (item.getName());
  864. const String groupID (getIDForGroup (item));
  865. addGroup (groupID, groupName, childIDs);
  866. return groupID;
  867. }
  868. void addMainBuildProduct() const
  869. {
  870. jassert (xcodeFileType.isNotEmpty());
  871. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  872. String productName (getConfiguration(0)->getTargetBinaryName().toString());
  873. if (xcodeFileType == "archive.ar")
  874. productName = getLibbedFilename (productName);
  875. else
  876. productName += xcodeBundleExtension;
  877. addBuildProduct (xcodeFileType, productName);
  878. }
  879. void addBuildProduct (const String& fileType, const String& binaryName) const
  880. {
  881. ValueTree* v = new ValueTree (createID ("__productFileID"));
  882. v->setProperty ("isa", "PBXFileReference", nullptr);
  883. v->setProperty ("explicitFileType", fileType, nullptr);
  884. v->setProperty ("includeInIndex", (int) 0, nullptr);
  885. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  886. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  887. pbxFileReferences.add (v);
  888. }
  889. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  890. {
  891. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  892. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  893. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  894. v->setProperty (Ids::name, configName, nullptr);
  895. targetConfigs.add (v);
  896. }
  897. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  898. {
  899. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  900. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  901. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  902. v->setProperty (Ids::name, configName, nullptr);
  903. projectConfigs.add (v);
  904. }
  905. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  906. {
  907. StringArray configIDs;
  908. for (int i = 0; i < configsToUse.size(); ++i)
  909. configIDs.add (configsToUse[i]->getType().toString());
  910. ValueTree* v = new ValueTree (listID);
  911. v->setProperty ("isa", "XCConfigurationList", nullptr);
  912. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", nullptr);
  913. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  914. if (configsToUse[0] != nullptr)
  915. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), nullptr);
  916. misc.add (v);
  917. }
  918. ValueTree& addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  919. {
  920. String phaseId (createID (phaseType + "resbuildphase"));
  921. int n = 0;
  922. while (buildPhaseIDs.contains (phaseId))
  923. phaseId = createID (phaseType + "resbuildphase" + String (++n));
  924. buildPhaseIDs.add (phaseId);
  925. ValueTree* v = new ValueTree (phaseId);
  926. v->setProperty ("isa", phaseType, nullptr);
  927. v->setProperty ("buildActionMask", "2147483647", nullptr);
  928. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", nullptr);
  929. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  930. misc.add (v);
  931. return *v;
  932. }
  933. void addTargetObject() const
  934. {
  935. ValueTree* const v = new ValueTree (createID ("__target"));
  936. v->setProperty ("isa", "PBXNativeTarget", nullptr);
  937. v->setProperty ("buildConfigurationList", createID ("__configList"), nullptr);
  938. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", nullptr);
  939. v->setProperty ("buildRules", "( )", nullptr);
  940. v->setProperty ("dependencies", "( )", nullptr);
  941. v->setProperty (Ids::name, projectName, nullptr);
  942. v->setProperty ("productName", projectName, nullptr);
  943. v->setProperty ("productReference", createID ("__productFileID"), nullptr);
  944. if (xcodeProductInstallPath.isNotEmpty())
  945. v->setProperty ("productInstallPath", xcodeProductInstallPath, nullptr);
  946. jassert (xcodeProductType.isNotEmpty());
  947. v->setProperty ("productType", xcodeProductType, nullptr);
  948. misc.add (v);
  949. }
  950. void addProjectObject() const
  951. {
  952. ValueTree* const v = new ValueTree (createID ("__root"));
  953. v->setProperty ("isa", "PBXProject", nullptr);
  954. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  955. v->setProperty ("attributes", "{ LastUpgradeCheck = 0440; }", nullptr);
  956. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  957. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  958. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  959. v->setProperty ("projectDirPath", "\"\"", nullptr);
  960. v->setProperty ("projectRoot", "\"\"", nullptr);
  961. v->setProperty ("targets", "( " + createID ("__target") + " )", nullptr);
  962. misc.add (v);
  963. }
  964. void addShellScriptBuildPhase (const String& name, const String& script) const
  965. {
  966. if (script.trim().isNotEmpty())
  967. {
  968. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  969. v.setProperty (Ids::name, name, nullptr);
  970. v.setProperty ("shellPath", "/bin/sh", nullptr);
  971. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  972. .replace ("\"", "\\\"")
  973. .replace ("\r\n", "\\n")
  974. .replace ("\n", "\\n"), nullptr);
  975. }
  976. }
  977. //==============================================================================
  978. static String indentList (const StringArray& list, const String& separator)
  979. {
  980. if (list.size() == 0)
  981. return " ";
  982. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  983. + (separator == ";" ? separator : String::empty);
  984. }
  985. String createID (String rootString) const
  986. {
  987. if (rootString.startsWith ("${"))
  988. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  989. rootString += project.getProjectUID();
  990. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  991. }
  992. String createFileRefID (const RelativePath& path) const
  993. {
  994. return createFileRefID (path.toUnixStyle());
  995. }
  996. String createFileRefID (const String& path) const
  997. {
  998. return createID ("__fileref_" + path);
  999. }
  1000. String getIDForGroup (const Project::Item& item) const
  1001. {
  1002. return createID (item.getID());
  1003. }
  1004. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  1005. {
  1006. return file.hasFileExtension (sourceFileExtensions);
  1007. }
  1008. };
  1009. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__