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.

1239 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)))
  54. return new XCodeProjectExporter (project, settings, false);
  55. else if (settings.hasType (getValueTreeTypeName (true)))
  56. return new XCodeProjectExporter (project, settings, true);
  57. return nullptr;
  58. }
  59. //==============================================================================
  60. Value getPListToMergeValue() { return getSetting ("customPList"); }
  61. String getPListToMergeString() const { return settings ["customPList"]; }
  62. Value getExtraFrameworksValue() { return getSetting (Ids::extraFrameworks); }
  63. String getExtraFrameworksString() const { return settings [Ids::extraFrameworks]; }
  64. Value getPostBuildScriptValue() { return getSetting (Ids::postbuildCommand); }
  65. String getPostBuildScript() const { return settings [Ids::postbuildCommand]; }
  66. Value getPreBuildScriptValue() { return getSetting (Ids::prebuildCommand); }
  67. String getPreBuildScript() const { return settings [Ids::prebuildCommand]; }
  68. bool isAvailableOnCurrentOS()
  69. {
  70. #if JUCE_MAC
  71. return true;
  72. #else
  73. return false;
  74. #endif
  75. }
  76. bool usesMMFiles() const { return true; }
  77. bool isXcode() const { return true; }
  78. bool isOSX() const { return ! iOS; }
  79. bool canCopeWithDuplicateFiles() { return true; }
  80. void createExporterProperties (PropertyListBuilder& props)
  81. {
  82. if (projectType.isGUIApplication() && ! iOS)
  83. {
  84. props.add (new TextPropertyComponent (getSetting ("documentExtensions"), "Document file extensions", 128, false),
  85. "A comma-separated list of file extensions for documents that your app can open. "
  86. "Using a leading '.' is optional, and the extensions are not case-sensitive.");
  87. }
  88. else if (iOS)
  89. {
  90. props.add (new BooleanPropertyComponent (getSetting ("UIFileSharingEnabled"), "File Sharing Enabled", "Enabled"),
  91. "Enable this to expose your app's files to iTunes.");
  92. props.add (new BooleanPropertyComponent (getSetting ("UIStatusBarHidden"), "Status Bar Hidden", "Enabled"),
  93. "Enable this to disable the status bar in your app.");
  94. }
  95. props.add (new TextPropertyComponent (getPListToMergeValue(), "Custom PList", 8192, true),
  96. "You can paste the contents of an XML PList file in here, and the settings that it contains will override any "
  97. "settings that the Introjucer creates. BEWARE! When doing this, be careful to remove from the XML any "
  98. "values that you DO want the introjucer to change!");
  99. props.add (new TextPropertyComponent (getExtraFrameworksValue(), "Extra Frameworks", 2048, false),
  100. "A comma-separated list of extra frameworks that should be added to the build. "
  101. "(Don't include the .framework extension in the name)");
  102. if (projectType.isLibrary())
  103. {
  104. const char* const libTypes[] = { "Static Library (.a)", "Dynamic Library (.dylib)", 0 };
  105. const int libTypeValues[] = { 1, 2, 0 };
  106. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type",
  107. StringArray (libTypes), Array<var> (libTypeValues)));
  108. }
  109. props.add (new TextPropertyComponent (getPreBuildScriptValue(), "Pre-build shell script", 32768, true),
  110. "Some shell-script that will be run before a build starts.");
  111. props.add (new TextPropertyComponent (getPostBuildScriptValue(), "Post-build shell script", 32768, true),
  112. "Some shell-script that will be run after a build completes.");
  113. }
  114. bool launchProject()
  115. {
  116. #if JUCE_MAC
  117. return getProjectBundle().startAsProcess();
  118. #else
  119. return false;
  120. #endif
  121. }
  122. //==============================================================================
  123. void create (const OwnedArray<LibraryModule>&) const
  124. {
  125. infoPlistFile = getTargetFolder().getChildFile ("Info.plist");
  126. createIconFile();
  127. File projectBundle (getProjectBundle());
  128. createDirectoryOrThrow (projectBundle);
  129. createObjects();
  130. File projectFile (projectBundle.getChildFile ("project.pbxproj"));
  131. {
  132. MemoryOutputStream mo;
  133. writeProjectFile (mo);
  134. overwriteFileIfDifferentOrThrow (projectFile, mo);
  135. }
  136. writeInfoPlistFile();
  137. }
  138. protected:
  139. Value getLibraryType() { return getSetting (Ids::libraryType); }
  140. bool isStaticLibrary() const { return projectType.isLibrary() && (int) settings [Ids::libraryType] == 1; }
  141. //==============================================================================
  142. class XcodeBuildConfiguration : public BuildConfiguration
  143. {
  144. public:
  145. XcodeBuildConfiguration (Project& p, const ValueTree& t, const bool isIOS)
  146. : BuildConfiguration (p, t), iOS (isIOS)
  147. {
  148. if (iOS)
  149. {
  150. if (getiOSCompatibilityVersion().isEmpty())
  151. getiOSCompatibilityVersionValue() = osxVersionDefault;
  152. }
  153. else
  154. {
  155. if (getMacSDKVersion().isEmpty())
  156. getMacSDKVersionValue() = osxVersionDefault;
  157. if (getMacCompatibilityVersion().isEmpty())
  158. getMacCompatibilityVersionValue() = osxVersionDefault;
  159. if (getMacArchitecture().isEmpty())
  160. getMacArchitectureValue() = osxArch_Default;
  161. }
  162. }
  163. Value getMacSDKVersionValue() { return getValue (Ids::osxSDK); }
  164. String getMacSDKVersion() const { return config [Ids::osxSDK]; }
  165. Value getMacCompatibilityVersionValue() { return getValue (Ids::osxCompatibility); }
  166. String getMacCompatibilityVersion() const { return config [Ids::osxCompatibility]; }
  167. Value getiOSCompatibilityVersionValue() { return getValue (Ids::iosCompatibility); }
  168. String getiOSCompatibilityVersion() const { return config [Ids::iosCompatibility]; }
  169. Value getMacArchitectureValue() { return getValue (Ids::osxArchitecture); }
  170. String getMacArchitecture() const { return config [Ids::osxArchitecture]; }
  171. Value getCustomXcodeFlagsValue() { return getValue (Ids::customXcodeFlags); }
  172. String getCustomXcodeFlags() const { return config [Ids::customXcodeFlags]; }
  173. Value getCppLibTypeValue() { return getValue (Ids::cppLibType); }
  174. String getCppLibType() const { return config [Ids::cppLibType]; }
  175. void createConfigProperties (PropertyListBuilder& props)
  176. {
  177. if (iOS)
  178. {
  179. const char* iosVersions[] = { "Use Default", "3.2", "4.0", "4.1", "4.2", "4.3", "5.0", "5.1", 0 };
  180. const char* iosVersionValues[] = { osxVersionDefault, "3.2", "4.0", "4.1", "4.2", "4.3", "5.0", "5.1", 0 };
  181. props.add (new ChoicePropertyComponent (getiOSCompatibilityVersionValue(), "iOS Deployment Target",
  182. StringArray (iosVersions), Array<var> (iosVersionValues)),
  183. "The minimum version of iOS that the target binary will run on.");
  184. }
  185. else
  186. {
  187. const char* osxVersions[] = { "Use Default", osxVersion10_5, osxVersion10_6, osxVersion10_7, 0 };
  188. const char* osxVersionValues[] = { osxVersionDefault, osxVersion10_5, osxVersion10_6, osxVersion10_7, 0 };
  189. props.add (new ChoicePropertyComponent (getMacSDKVersionValue(), "OSX Base SDK Version",
  190. StringArray (osxVersions), Array<var> (osxVersionValues)),
  191. "The version of OSX to link against in the XCode build.");
  192. props.add (new ChoicePropertyComponent (getMacCompatibilityVersionValue(), "OSX Compatibility Version",
  193. StringArray (osxVersions), Array<var> (osxVersionValues)),
  194. "The minimum version of OSX that the target binary will be compatible with.");
  195. const char* osxArch[] = { "Use Default", "Native architecture of build machine",
  196. "Universal Binary (32-bit)", "Universal Binary (64-bit)", "64-bit Intel", 0 };
  197. const char* osxArchValues[] = { osxArch_Default, osxArch_Native, osxArch_32BitUniversal,
  198. osxArch_64BitUniversal, osxArch_64Bit, 0 };
  199. props.add (new ChoicePropertyComponent (getMacArchitectureValue(), "OSX Architecture",
  200. StringArray (osxArch), Array<var> (osxArchValues)),
  201. "The type of OSX binary that will be produced.");
  202. }
  203. props.add (new TextPropertyComponent (getCustomXcodeFlagsValue(), "Custom Xcode flags", 8192, false),
  204. "A comma-separated list of custom Xcode setting flags which will be appended to the list of generated flags, "
  205. "e.g. MACOSX_DEPLOYMENT_TARGET_i386 = 10.5, VALID_ARCHS = \"ppc i386 x86_64\"");
  206. const char* cppLibNames[] = { "Use Default", "Use LLVM libc++", 0 };
  207. Array<var> cppLibValues;
  208. cppLibValues.add (var::null);
  209. cppLibValues.add ("libc++");
  210. props.add (new ChoicePropertyComponent (getCppLibTypeValue(), "C++ Library", StringArray (cppLibNames), cppLibValues),
  211. "The type of C++ std lib that will be linked.");
  212. }
  213. bool iOS;
  214. };
  215. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  216. {
  217. return new XcodeBuildConfiguration (project, settings, iOS);
  218. }
  219. private:
  220. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  221. mutable StringArray buildPhaseIDs, resourceIDs, sourceIDs, frameworkIDs;
  222. mutable StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  223. mutable File infoPlistFile, iconFile;
  224. const bool iOS;
  225. static String sanitisePath (const String& path)
  226. {
  227. if (path.startsWithChar ('~'))
  228. return "$(HOME)" + path.substring (1);
  229. return path;
  230. }
  231. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  232. //==============================================================================
  233. void createObjects() const
  234. {
  235. addFrameworks();
  236. addMainBuildProduct();
  237. if (xcodeCreatePList)
  238. {
  239. RelativePath plistPath (infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  240. addFileReference (plistPath.toUnixStyle());
  241. resourceFileRefs.add (createFileRefID (plistPath));
  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 (! isStaticLibrary())
  287. addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  288. if (rezFileIDs.size() > 0)
  289. addBuildPhase ("PBXRezBuildPhase", rezFileIDs);
  290. addBuildPhase ("PBXSourcesBuildPhase", sourceIDs);
  291. if (! 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.removeEmptyStrings (true);
  480. }
  481. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  482. {
  483. StringArray s;
  484. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  485. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  486. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  487. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  488. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  489. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  490. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  491. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  492. s.add ("WARNING_CFLAGS = -Wreorder");
  493. s.add ("GCC_MODEL_TUNING = G5");
  494. if (projectType.isLibrary())
  495. {
  496. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  497. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  498. }
  499. else
  500. {
  501. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  502. }
  503. if (iOS)
  504. {
  505. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  506. s.add ("SDKROOT = iphoneos");
  507. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  508. const String iosVersion (config.getiOSCompatibilityVersion());
  509. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  510. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  511. }
  512. s.add ("ZERO_LINK = NO");
  513. if (xcodeCanUseDwarf)
  514. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  515. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryNameString() + "\"");
  516. return s;
  517. }
  518. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  519. {
  520. StringArray s;
  521. const String arch (config.getMacArchitecture());
  522. if (arch == osxArch_Native) s.add ("ARCHS = \"$(ARCHS_NATIVE)\"");
  523. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  524. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  525. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  526. s.add ("HEADER_SEARCH_PATHS = \"" + replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" ")) + " $(inherited)\"");
  527. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  528. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  529. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  530. if (extraFlags.isNotEmpty())
  531. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  532. if (xcodeProductInstallPath.isNotEmpty())
  533. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  534. if (xcodeIsBundle)
  535. {
  536. s.add ("LIBRARY_STYLE = Bundle");
  537. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  538. s.add ("GENERATE_PKGINFO_FILE = YES");
  539. }
  540. if (xcodeOtherRezFlags.isNotEmpty())
  541. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  542. if (projectType.isLibrary())
  543. {
  544. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  545. {
  546. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  547. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  548. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  549. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  550. }
  551. s.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  552. s.add ("DEPLOYMENT_LOCATION = YES");
  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. if (config.getCppLibType().isNotEmpty())
  577. s.add ("CLANG_CXX_LIBRARY = " + config.getCppLibType().quoted());
  578. s.add ("COMBINE_HIDPI_IMAGES = YES");
  579. {
  580. StringArray linkerFlags, librarySearchPaths;
  581. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  582. if (linkerFlags.size() > 0)
  583. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  584. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  585. librarySearchPaths.removeDuplicates (false);
  586. if (librarySearchPaths.size() > 0)
  587. {
  588. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  589. for (int i = 0; i < librarySearchPaths.size(); ++i)
  590. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  591. s.add (libPaths + ")");
  592. }
  593. }
  594. StringPairArray defines;
  595. if (config.isDebug())
  596. {
  597. defines.set ("_DEBUG", "1");
  598. defines.set ("DEBUG", "1");
  599. if (config.getMacArchitecture() == osxArch_Default
  600. || config.getMacArchitecture().isEmpty())
  601. s.add ("ONLY_ACTIVE_ARCH = YES");
  602. s.add ("COPY_PHASE_STRIP = NO");
  603. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  604. }
  605. else
  606. {
  607. defines.set ("_NDEBUG", "1");
  608. defines.set ("NDEBUG", "1");
  609. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  610. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  611. }
  612. {
  613. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  614. StringArray defsList;
  615. for (int i = 0; i < defines.size(); ++i)
  616. {
  617. String def (defines.getAllKeys()[i]);
  618. const String value (defines.getAllValues()[i]);
  619. if (value.isNotEmpty())
  620. def << "=" << value.replace ("\"", "\\\"");
  621. defsList.add ("\"" + def + "\"");
  622. }
  623. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  624. }
  625. s.addTokens (config.getCustomXcodeFlags(), ",", "\"'");
  626. s.trim();
  627. s.removeEmptyStrings();
  628. s.removeDuplicates (false);
  629. return s;
  630. }
  631. void addFrameworks() const
  632. {
  633. if (! isStaticLibrary())
  634. {
  635. StringArray s (xcodeFrameworks);
  636. s.addTokens (getExtraFrameworksString(), ",;", "\"'");
  637. s.trim();
  638. s.removeDuplicates (true);
  639. s.sort (true);
  640. for (int i = 0; i < s.size(); ++i)
  641. addFramework (s[i]);
  642. }
  643. }
  644. //==============================================================================
  645. void writeProjectFile (OutputStream& output) const
  646. {
  647. output << "// !$*UTF8*$!\n{\n"
  648. "\tarchiveVersion = 1;\n"
  649. "\tclasses = {\n\t};\n"
  650. "\tobjectVersion = 46;\n"
  651. "\tobjects = {\n\n";
  652. Array <ValueTree*> objects;
  653. objects.addArray (pbxBuildFiles);
  654. objects.addArray (pbxFileReferences);
  655. objects.addArray (pbxGroups);
  656. objects.addArray (targetConfigs);
  657. objects.addArray (projectConfigs);
  658. objects.addArray (misc);
  659. for (int i = 0; i < objects.size(); ++i)
  660. {
  661. ValueTree& o = *objects.getUnchecked(i);
  662. output << "\t\t" << o.getType().toString() << " = { ";
  663. for (int j = 0; j < o.getNumProperties(); ++j)
  664. {
  665. const Identifier propertyName (o.getPropertyName(j));
  666. String val (o.getProperty (propertyName).toString());
  667. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n")
  668. && ! (val.trimStart().startsWithChar ('(')
  669. || val.trimStart().startsWithChar ('{'))))
  670. val = val.quoted();
  671. output << propertyName.toString() << " = " << val << "; ";
  672. }
  673. output << "};\n";
  674. }
  675. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  676. }
  677. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  678. {
  679. forEachXmlChildElementWithTagName (*xml, e, "key")
  680. {
  681. if (e->getAllSubText().trim().equalsIgnoreCase (key))
  682. {
  683. if (e->getNextElement() != nullptr && e->getNextElement()->hasTagName ("key"))
  684. {
  685. // try to fix broken plist format..
  686. xml->removeChildElement (e, true);
  687. break;
  688. }
  689. else
  690. {
  691. return; // (value already exists)
  692. }
  693. }
  694. }
  695. xml->createNewChildElement ("key") ->addTextElement (key);
  696. xml->createNewChildElement ("string")->addTextElement (value);
  697. }
  698. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  699. {
  700. xml->createNewChildElement ("key")->addTextElement (key);
  701. xml->createNewChildElement (value ? "true" : "false");
  702. }
  703. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings) const
  704. {
  705. String fileID (createID (path + "buildref"));
  706. if (addToSourceBuildPhase)
  707. sourceIDs.add (fileID);
  708. ValueTree* v = new ValueTree (fileID);
  709. v->setProperty ("isa", "PBXBuildFile", nullptr);
  710. v->setProperty ("fileRef", fileRefID, nullptr);
  711. if (inhibitWarnings)
  712. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  713. pbxBuildFiles.add (v);
  714. return fileID;
  715. }
  716. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings) const
  717. {
  718. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings);
  719. }
  720. String addFileReference (String pathString) const
  721. {
  722. String sourceTree ("SOURCE_ROOT");
  723. RelativePath path (pathString, RelativePath::unknown);
  724. if (pathString.startsWith ("${"))
  725. {
  726. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  727. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  728. }
  729. else if (path.isAbsolute())
  730. {
  731. sourceTree = "<absolute>";
  732. }
  733. const String fileRefID (createFileRefID (pathString));
  734. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  735. v->setProperty ("isa", "PBXFileReference", nullptr);
  736. v->setProperty ("lastKnownFileType", getFileType (path), nullptr);
  737. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  738. v->setProperty ("path", sanitisePath (pathString), nullptr);
  739. v->setProperty ("sourceTree", sourceTree, nullptr);
  740. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  741. if (existing >= 0)
  742. {
  743. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  744. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  745. }
  746. else
  747. {
  748. pbxFileReferences.addSorted (*this, v.release());
  749. }
  750. return fileRefID;
  751. }
  752. public:
  753. static int compareElements (const ValueTree* first, const ValueTree* second)
  754. {
  755. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  756. }
  757. private:
  758. static String getFileType (const RelativePath& file)
  759. {
  760. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  761. else if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  762. else if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  763. else if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  764. else if (file.hasFileExtension (".framework")) return "wrapper.framework";
  765. else if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  766. else if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  767. else if (file.hasFileExtension ("html;htm")) return "text.html";
  768. else if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  769. else if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  770. else if (file.hasFileExtension ("plist")) return "text.plist.xml";
  771. else if (file.hasFileExtension ("app")) return "wrapper.application";
  772. else if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  773. else if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  774. else if (file.hasFileExtension ("a")) return "archive.ar";
  775. return "file" + file.getFileExtension();
  776. }
  777. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources, bool inhibitWarnings) const
  778. {
  779. const String pathAsString (path.toUnixStyle());
  780. const String refID (addFileReference (path.toUnixStyle()));
  781. if (shouldBeCompiled)
  782. {
  783. if (path.hasFileExtension (".r"))
  784. rezFileIDs.add (addBuildFile (pathAsString, refID, false, inhibitWarnings));
  785. else
  786. addBuildFile (pathAsString, refID, true, inhibitWarnings);
  787. }
  788. else if (! shouldBeAddedToBinaryResources)
  789. {
  790. const String fileType (getFileType (path));
  791. if (fileType.startsWith ("image.") || fileType.startsWith ("text.") || fileType.startsWith ("file."))
  792. {
  793. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  794. resourceFileRefs.add (refID);
  795. }
  796. }
  797. return refID;
  798. }
  799. String addProjectItem (const Project::Item& projectItem) const
  800. {
  801. if (projectItem.isGroup())
  802. {
  803. StringArray childIDs;
  804. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  805. {
  806. const String childID (addProjectItem (projectItem.getChild(i)));
  807. if (childID.isNotEmpty())
  808. childIDs.add (childID);
  809. }
  810. return addGroup (projectItem, childIDs);
  811. }
  812. else
  813. {
  814. if (projectItem.shouldBeAddedToTargetProject())
  815. {
  816. const String itemPath (projectItem.getFilePath());
  817. RelativePath path;
  818. if (itemPath.startsWith ("${"))
  819. path = RelativePath (itemPath, RelativePath::unknown);
  820. else
  821. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  822. return addFile (path, projectItem.shouldBeCompiled(),
  823. projectItem.shouldBeAddedToBinaryResources(),
  824. projectItem.shouldInhibitWarnings());
  825. }
  826. }
  827. return String::empty;
  828. }
  829. void addFramework (const String& frameworkName) const
  830. {
  831. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  832. const String fileRefID (createFileRefID (path));
  833. addFileReference ("${SDKROOT}/" + path);
  834. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  835. frameworkFileIDs.add (fileRefID);
  836. }
  837. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  838. {
  839. ValueTree* v = new ValueTree (groupID);
  840. v->setProperty ("isa", "PBXGroup", nullptr);
  841. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", nullptr);
  842. v->setProperty (Ids::name, groupName, nullptr);
  843. v->setProperty ("sourceTree", "<group>", nullptr);
  844. pbxGroups.add (v);
  845. }
  846. String addGroup (const Project::Item& item, StringArray& childIDs) const
  847. {
  848. const String groupName (item.getName());
  849. const String groupID (getIDForGroup (item));
  850. addGroup (groupID, groupName, childIDs);
  851. return groupID;
  852. }
  853. void addMainBuildProduct() const
  854. {
  855. jassert (xcodeFileType.isNotEmpty());
  856. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  857. String productName (getConfiguration(0)->getTargetBinaryName().toString());
  858. if (xcodeFileType == "archive.ar")
  859. productName = getLibbedFilename (productName);
  860. else
  861. productName += xcodeBundleExtension;
  862. addBuildProduct (xcodeFileType, productName);
  863. }
  864. void addBuildProduct (const String& fileType, const String& binaryName) const
  865. {
  866. ValueTree* v = new ValueTree (createID ("__productFileID"));
  867. v->setProperty ("isa", "PBXFileReference", nullptr);
  868. v->setProperty ("explicitFileType", fileType, nullptr);
  869. v->setProperty ("includeInIndex", (int) 0, nullptr);
  870. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  871. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  872. pbxFileReferences.add (v);
  873. }
  874. void addTargetConfig (const String& configName, const StringArray& buildSettings) const
  875. {
  876. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  877. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  878. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  879. v->setProperty (Ids::name, configName, nullptr);
  880. targetConfigs.add (v);
  881. }
  882. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  883. {
  884. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  885. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  886. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", nullptr);
  887. v->setProperty (Ids::name, configName, nullptr);
  888. projectConfigs.add (v);
  889. }
  890. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  891. {
  892. StringArray configIDs;
  893. for (int i = 0; i < configsToUse.size(); ++i)
  894. configIDs.add (configsToUse[i]->getType().toString());
  895. ValueTree* v = new ValueTree (listID);
  896. v->setProperty ("isa", "XCConfigurationList", nullptr);
  897. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", nullptr);
  898. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  899. if (configsToUse[0] != nullptr)
  900. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), nullptr);
  901. misc.add (v);
  902. }
  903. ValueTree& addBuildPhase (const String& phaseType, const StringArray& fileIds) const
  904. {
  905. String phaseId (createID (phaseType + "resbuildphase"));
  906. buildPhaseIDs.add (phaseId);
  907. ValueTree* v = new ValueTree (phaseId);
  908. v->setProperty ("isa", phaseType, nullptr);
  909. v->setProperty ("buildActionMask", "2147483647", nullptr);
  910. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", nullptr);
  911. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  912. misc.add (v);
  913. return *v;
  914. }
  915. void addTargetObject() const
  916. {
  917. ValueTree* const v = new ValueTree (createID ("__target"));
  918. v->setProperty ("isa", "PBXNativeTarget", nullptr);
  919. v->setProperty ("buildConfigurationList", createID ("__configList"), nullptr);
  920. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", nullptr);
  921. v->setProperty ("buildRules", "( )", nullptr);
  922. v->setProperty ("dependencies", "( )", nullptr);
  923. v->setProperty (Ids::name, projectName, nullptr);
  924. v->setProperty ("productName", projectName, nullptr);
  925. v->setProperty ("productReference", createID ("__productFileID"), nullptr);
  926. if (xcodeProductInstallPath.isNotEmpty())
  927. v->setProperty ("productInstallPath", xcodeProductInstallPath, nullptr);
  928. jassert (xcodeProductType.isNotEmpty());
  929. v->setProperty ("productType", xcodeProductType, nullptr);
  930. misc.add (v);
  931. }
  932. void addProjectObject() const
  933. {
  934. ValueTree* const v = new ValueTree (createID ("__root"));
  935. v->setProperty ("isa", "PBXProject", nullptr);
  936. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  937. v->setProperty ("attributes", "{ LastUpgradeCheck = 0440; }", nullptr);
  938. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  939. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  940. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  941. v->setProperty ("projectDirPath", "\"\"", nullptr);
  942. v->setProperty ("projectRoot", "\"\"", nullptr);
  943. v->setProperty ("targets", "( " + createID ("__target") + " )", nullptr);
  944. misc.add (v);
  945. }
  946. void addShellScriptBuildPhase (const String& name, const String& script) const
  947. {
  948. if (script.trim().isNotEmpty())
  949. {
  950. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  951. v.setProperty (Ids::name, name, nullptr);
  952. v.setProperty ("shellPath", "/bin/sh", nullptr);
  953. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  954. .replace ("\"", "\\\"")
  955. .replace ("\r\n", "\\n")
  956. .replace ("\n", "\\n"), nullptr);
  957. }
  958. }
  959. //==============================================================================
  960. static String indentList (const StringArray& list, const String& separator)
  961. {
  962. if (list.size() == 0)
  963. return " ";
  964. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  965. + (separator == ";" ? separator : String::empty);
  966. }
  967. String createID (String rootString) const
  968. {
  969. if (rootString.startsWith ("${"))
  970. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  971. rootString += project.getProjectUID();
  972. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  973. }
  974. String createFileRefID (const RelativePath& path) const
  975. {
  976. return createFileRefID (path.toUnixStyle());
  977. }
  978. String createFileRefID (const String& path) const
  979. {
  980. return createID ("__fileref_" + path);
  981. }
  982. String getIDForGroup (const Project::Item& item) const
  983. {
  984. return createID (item.getID());
  985. }
  986. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  987. {
  988. return file.hasFileExtension (sourceFileExtensions);
  989. }
  990. };
  991. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__