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.

1244 lines
51KB

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