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.

1252 lines
51KB

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