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.

1226 lines
50KB

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