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.

1236 lines
51KB

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