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.

1205 lines
49KB

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