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.

1257 lines
51KB

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