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.

1006 lines
39KB

  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. //==============================================================================
  22. class XCodeProjectExporter : public ProjectExporter
  23. {
  24. public:
  25. //==============================================================================
  26. static const char* getNameMac() { return "XCode (MacOSX)"; }
  27. static const char* getNameiOS() { return "XCode (iOS)"; }
  28. static const char* getValueTreeTypeName (bool iPhone) { return iPhone ? "XCODE_IPHONE" : "XCODE_MAC"; }
  29. //==============================================================================
  30. XCodeProjectExporter (Project& project_, const ValueTree& settings_, const bool iPhone_)
  31. : ProjectExporter (project_, settings_),
  32. iPhone (iPhone_)
  33. {
  34. name = iPhone ? getNameiOS() : getNameMac();
  35. projectIDSalt = hashCode64 (project.getProjectUID());
  36. if (getTargetLocation().toString().isEmpty())
  37. getTargetLocation() = getDefaultBuildsRootFolder() + (iPhone ? "iOS" : "MacOSX");
  38. if (getSettings() ["objCExtraSuffix"].isVoid())
  39. getObjCSuffix() = createAlphaNumericUID();
  40. }
  41. static XCodeProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  42. {
  43. if (settings.hasType (getValueTreeTypeName (false)))
  44. return new XCodeProjectExporter (project, settings, false);
  45. else if (settings.hasType (getValueTreeTypeName (true)))
  46. return new XCodeProjectExporter (project, settings, true);
  47. return 0;
  48. }
  49. //==============================================================================
  50. Value getObjCSuffix() { return getSetting ("objCExtraSuffix"); }
  51. int getLaunchPreferenceOrderForCurrentOS()
  52. {
  53. #if JUCE_MAC
  54. return iPhone ? 1 : 2;
  55. #else
  56. return 0;
  57. #endif
  58. }
  59. bool isAvailableOnCurrentOS()
  60. {
  61. #if JUCE_MAC
  62. return true;
  63. #else
  64. return false;
  65. #endif
  66. }
  67. bool isPossibleForCurrentProject() { return projectType.isGUIApplication() || ! iPhone; }
  68. bool usesMMFiles() const { return true; }
  69. bool isXcode() const { return true; }
  70. void createPropertyEditors (Array <PropertyComponent*>& props)
  71. {
  72. ProjectExporter::createPropertyEditors (props);
  73. props.add (new TextPropertyComponent (getObjCSuffix(), "Objective-C class name suffix", 64, false));
  74. props.getLast()->setTooltip ("Because objective-C linkage is done by string-matching, you can get horrible linkage mix-ups when different modules containing the "
  75. "same class-names are loaded simultaneously. This setting lets you provide a unique string that will be used in naming the obj-C classes in your executable to avoid this.");
  76. if (projectType.isGUIApplication() && ! iPhone)
  77. {
  78. props.add (new TextPropertyComponent (getSetting ("documentExtensions"), "Document file extensions", 128, false));
  79. props.getLast()->setTooltip ("A comma-separated list of file extensions for documents that your app can open.");
  80. }
  81. else if (iPhone)
  82. {
  83. props.add (new BooleanPropertyComponent (getSetting ("UIFileSharingEnabled"), "File Sharing Enabled", "Enabled"));
  84. props.getLast()->setTooltip ("Enable this to expose your app's files to iTunes.");
  85. props.add (new BooleanPropertyComponent (getSetting ("UIStatusBarHidden"), "Status Bar Hidden", "Enabled"));
  86. props.getLast()->setTooltip ("Enable this to disable the status bar in your app.");
  87. }
  88. }
  89. void launchProject()
  90. {
  91. getProjectBundle().startAsProcess();
  92. }
  93. //==============================================================================
  94. void create()
  95. {
  96. infoPlistFile = getTargetFolder().getChildFile ("Info.plist");
  97. createIconFile();
  98. File projectBundle (getProjectBundle());
  99. createDirectoryOrThrow (projectBundle);
  100. createObjects();
  101. File projectFile (projectBundle.getChildFile ("project.pbxproj"));
  102. {
  103. MemoryOutputStream mo;
  104. writeProjectFile (mo);
  105. overwriteFileIfDifferentOrThrow (projectFile, mo);
  106. }
  107. writeInfoPlistFile();
  108. }
  109. private:
  110. OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  111. StringArray buildPhaseIDs, resourceIDs, sourceIDs, frameworkIDs;
  112. StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  113. File infoPlistFile, iconFile;
  114. int64 projectIDSalt;
  115. const bool iPhone;
  116. static String sanitisePath (const String& path)
  117. {
  118. if (path.startsWithChar ('~'))
  119. return "$(HOME)" + path.substring (1);
  120. return path;
  121. }
  122. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  123. //==============================================================================
  124. void createObjects()
  125. {
  126. addFrameworks();
  127. addMainBuildProduct();
  128. if (xcodeCreatePList)
  129. {
  130. RelativePath plistPath (infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  131. addFileReference (plistPath.toUnixStyle());
  132. resourceFileRefs.add (createID (plistPath));
  133. }
  134. if (iconFile.exists())
  135. {
  136. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  137. addFileReference (iconPath.toUnixStyle());
  138. resourceIDs.add (addBuildFile (iconPath, false, false));
  139. resourceFileRefs.add (createID (iconPath));
  140. }
  141. {
  142. StringArray topLevelGroupIDs;
  143. for (int i = 0; i < groups.size(); ++i)
  144. if (groups.getReference(i).getNumChildren() > 0)
  145. topLevelGroupIDs.add (addProjectItem (groups.getReference(i)));
  146. { // Add 'resources' group
  147. String resourcesGroupID (createID ("__resources"));
  148. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  149. topLevelGroupIDs.add (resourcesGroupID);
  150. }
  151. { // Add 'frameworks' group
  152. String frameworksGroupID (createID ("__frameworks"));
  153. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  154. topLevelGroupIDs.add (frameworksGroupID);
  155. }
  156. { // Add 'products' group
  157. String productsGroupID (createID ("__products"));
  158. StringArray products;
  159. products.add (createID ("__productFileID"));
  160. addGroup (productsGroupID, "Products", products);
  161. topLevelGroupIDs.add (productsGroupID);
  162. }
  163. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  164. }
  165. for (int i = 0; i < configs.size(); ++i)
  166. {
  167. const Project::BuildConfiguration& config = configs.getReference(i);
  168. addProjectConfig (config.getName().getValue(), getProjectSettings (config));
  169. addTargetConfig (config.getName().getValue(), getTargetSettings (config));
  170. }
  171. addConfigList (projectConfigs, createID ("__projList"));
  172. addConfigList (targetConfigs, createID ("__configList"));
  173. if (! projectType.isLibrary())
  174. addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  175. if (rezFileIDs.size() > 0)
  176. addBuildPhase ("PBXRezBuildPhase", rezFileIDs);
  177. addBuildPhase ("PBXSourcesBuildPhase", sourceIDs);
  178. if (! projectType.isLibrary())
  179. addBuildPhase ("PBXFrameworksBuildPhase", frameworkIDs);
  180. addShellScriptPhase();
  181. addTargetObject();
  182. addProjectObject();
  183. }
  184. static Image fixMacIconImageSize (Image& image)
  185. {
  186. const int w = image.getWidth();
  187. const int h = image.getHeight();
  188. if (w != h || (w != 16 && w != 32 && w != 48 && w != 64))
  189. {
  190. const int newSize = w >= 128 ? 128 : (w >= 64 ? 64 : (w >= 32 ? 32 : 16));
  191. Image newIm (Image::ARGB, newSize, newSize, true, Image::SoftwareImage);
  192. Graphics g (newIm);
  193. g.drawImageWithin (image, 0, 0, newSize, newSize,
  194. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  195. return newIm;
  196. }
  197. return image;
  198. }
  199. void writeIcnsFile (const Array<Image>& images, OutputStream& out)
  200. {
  201. MemoryOutputStream data;
  202. for (int i = 0; i < images.size(); ++i)
  203. {
  204. Image image (fixMacIconImageSize (images.getReference (i)));
  205. const int w = image.getWidth();
  206. const int h = image.getHeight();
  207. const char* type = nullptr;
  208. const char* maskType = nullptr;
  209. if (w == h)
  210. {
  211. if (w == 16) { type = "is32"; maskType = "s8mk"; }
  212. if (w == 32) { type = "il32"; maskType = "l8mk"; }
  213. if (w == 48) { type = "ih32"; maskType = "h8mk"; }
  214. if (w == 128) { type = "it32"; maskType = "t8mk"; }
  215. }
  216. if (type != nullptr)
  217. {
  218. data.write (type, 4);
  219. data.writeIntBigEndian (8 + 4 * w * h);
  220. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  221. int y;
  222. for (y = 0; y < h; ++y)
  223. {
  224. for (int x = 0; x < w; ++x)
  225. {
  226. const Colour pixel (bitmap.getPixelColour (x, y));
  227. data.writeByte ((char) pixel.getAlpha());
  228. data.writeByte ((char) pixel.getRed());
  229. data.writeByte ((char) pixel.getGreen());
  230. data.writeByte ((char) pixel.getBlue());
  231. }
  232. }
  233. data.write (maskType, 4);
  234. data.writeIntBigEndian (8 + w * h);
  235. for (y = 0; y < h; ++y)
  236. {
  237. for (int x = 0; x < w; ++x)
  238. {
  239. const Colour pixel (bitmap.getPixelColour (x, y));
  240. data.writeByte ((char) pixel.getAlpha());
  241. }
  242. }
  243. }
  244. }
  245. jassert (data.getDataSize() > 0); // no suitable sized images?
  246. out.write ("icns", 4);
  247. out.writeIntBigEndian (data.getDataSize() + 8);
  248. out << data;
  249. }
  250. void createIconFile()
  251. {
  252. Array<Image> images;
  253. Image bigIcon (project.getBigIcon());
  254. if (bigIcon.isValid())
  255. images.add (bigIcon);
  256. Image smallIcon (project.getSmallIcon());
  257. if (smallIcon.isValid())
  258. images.add (smallIcon);
  259. if (images.size() > 0)
  260. {
  261. MemoryOutputStream mo;
  262. writeIcnsFile (images, mo);
  263. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  264. overwriteFileIfDifferentOrThrow (iconFile, mo);
  265. }
  266. }
  267. void writeInfoPlistFile()
  268. {
  269. if (! xcodeCreatePList)
  270. return;
  271. XmlElement plist ("plist");
  272. XmlElement* dict = plist.createNewChildElement ("dict");
  273. if (iPhone)
  274. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  275. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  276. addPlistDictionaryKey (dict, "CFBundleIconFile", iconFile.exists() ? iconFile.getFileName() : String::empty);
  277. addPlistDictionaryKey (dict, "CFBundleIdentifier", project.getBundleIdentifier().toString());
  278. addPlistDictionaryKey (dict, "CFBundleName", projectName);
  279. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  280. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  281. addPlistDictionaryKey (dict, "CFBundleShortVersionString", project.getVersion().toString());
  282. addPlistDictionaryKey (dict, "CFBundleVersion", project.getVersion().toString());
  283. StringArray documentExtensions;
  284. documentExtensions.addTokens (replacePreprocessorDefs (getAllPreprocessorDefs(), getSetting ("documentExtensions").toString()),
  285. ",", String::empty);
  286. documentExtensions.trim();
  287. documentExtensions.removeEmptyStrings (true);
  288. if (documentExtensions.size() > 0)
  289. {
  290. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  291. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  292. for (int i = 0; i < documentExtensions.size(); ++i)
  293. {
  294. String ex (documentExtensions[i]);
  295. if (ex.startsWithChar ('.'))
  296. ex = ex.substring (1);
  297. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  298. dict2->createNewChildElement ("array")->createNewChildElement ("string")->addTextElement (ex);
  299. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  300. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  301. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  302. }
  303. }
  304. if (getSetting ("UIFileSharingEnabled").getValue())
  305. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  306. if (getSetting ("UIStatusBarHidden").getValue())
  307. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  308. MemoryOutputStream mo;
  309. plist.writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  310. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  311. }
  312. StringArray getHeaderSearchPaths (const Project::BuildConfiguration& config)
  313. {
  314. StringArray searchPaths (extraSearchPaths);
  315. searchPaths.addArray (config.getHeaderSearchPaths());
  316. searchPaths.removeDuplicates (false);
  317. return searchPaths;
  318. }
  319. static void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths)
  320. {
  321. jassert (library.getFileNameWithoutExtension().substring (0, 3) == "lib");
  322. flags.add ("-l" + library.getFileNameWithoutExtension().substring (3));
  323. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  324. if (! library.isAbsolute())
  325. searchPath = "$(SRCROOT)/" + searchPath;
  326. librarySearchPaths.add (sanitisePath (searchPath));
  327. }
  328. void getLinkerFlags (const Project::BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths)
  329. {
  330. if (xcodeIsBundle)
  331. flags.add ("-bundle");
  332. const Array<RelativePath>& extraLibs = config.isDebug().getValue() ? xcodeExtraLibrariesDebug
  333. : xcodeExtraLibrariesRelease;
  334. for (int i = 0; i < extraLibs.size(); ++i)
  335. getLinkerFlagsForStaticLibrary (extraLibs.getReference(i), flags, librarySearchPaths);
  336. /*if (project.getJuceLinkageMode() == Project::useLinkedJuce)
  337. {
  338. RelativePath juceLib (getJucePathFromTargetFolder().getChildFile (config.isDebug().getValue() ? "bin/libjucedebug.a"
  339. : "bin/libjuce.a"));
  340. getLinkerFlagsForStaticLibrary (juceLib, flags, librarySearchPaths);
  341. }*/
  342. flags.add (replacePreprocessorTokens (config, getExtraLinkerFlags().toString()));
  343. flags.removeEmptyStrings (true);
  344. }
  345. StringArray getProjectSettings (const Project::BuildConfiguration& config)
  346. {
  347. StringArray s;
  348. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  349. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  350. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  351. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  352. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  353. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  354. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  355. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  356. s.add ("WARNING_CFLAGS = -Wreorder");
  357. s.add ("GCC_MODEL_TUNING = G5");
  358. if (projectType.isLibrary() /*|| project.getJuceLinkageMode() == Project::useLinkedJuce*/)
  359. {
  360. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  361. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  362. }
  363. else
  364. {
  365. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  366. }
  367. if (iPhone)
  368. {
  369. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = \"iPhone Developer\"");
  370. s.add ("SDKROOT = iphoneos");
  371. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  372. }
  373. s.add ("ZERO_LINK = NO");
  374. if (xcodeCanUseDwarf)
  375. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  376. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryName().toString() + "\"");
  377. return s;
  378. }
  379. StringArray getTargetSettings (const Project::BuildConfiguration& config)
  380. {
  381. StringArray s;
  382. const String arch (config.getMacArchitecture().toString());
  383. if (arch == Project::BuildConfiguration::osxArch_Native) s.add ("ARCHS = \"$(ARCHS_NATIVE)\"");
  384. else if (arch == Project::BuildConfiguration::osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  385. else if (arch == Project::BuildConfiguration::osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  386. else if (arch == Project::BuildConfiguration::osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  387. s.add ("PREBINDING = NO");
  388. s.add ("HEADER_SEARCH_PATHS = \"" + replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" ")) + " $(inherited)\"");
  389. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  390. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  391. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  392. if (extraFlags.isNotEmpty())
  393. s.add ("OTHER_CPLUSPLUSFLAGS = " + extraFlags);
  394. if (xcodeProductInstallPath.isNotEmpty())
  395. s.add ("INSTALL_PATH = \"" + xcodeProductInstallPath + "\"");
  396. if (xcodeIsBundle)
  397. {
  398. s.add ("LIBRARY_STYLE = Bundle");
  399. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  400. s.add ("GENERATE_PKGINFO_FILE = YES");
  401. }
  402. if (xcodeOtherRezFlags.isNotEmpty())
  403. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  404. if (projectType.isLibrary())
  405. {
  406. if (config.getTargetBinaryRelativePath().toString().isNotEmpty())
  407. {
  408. RelativePath binaryPath (config.getTargetBinaryRelativePath().toString(), RelativePath::projectFolder);
  409. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  410. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  411. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  412. }
  413. s.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  414. s.add ("DEPLOYMENT_LOCATION = YES");
  415. }
  416. if (! iPhone)
  417. {
  418. const String sdk (config.getMacSDKVersion().toString());
  419. const String sdkCompat (config.getMacCompatibilityVersion().toString());
  420. if (sdk == Project::BuildConfiguration::osxVersion10_4)
  421. {
  422. s.add ("SDKROOT = macosx10.4");
  423. s.add ("GCC_VERSION = 4.0");
  424. }
  425. else if (sdk == Project::BuildConfiguration::osxVersion10_5)
  426. {
  427. s.add ("SDKROOT = macosx10.5");
  428. }
  429. else if (sdk == Project::BuildConfiguration::osxVersion10_6)
  430. {
  431. s.add ("SDKROOT = macosx10.6");
  432. }
  433. if (sdkCompat == Project::BuildConfiguration::osxVersion10_4) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.4");
  434. else if (sdkCompat == Project::BuildConfiguration::osxVersion10_5) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.5");
  435. else if (sdkCompat == Project::BuildConfiguration::osxVersion10_6) s.add ("MACOSX_DEPLOYMENT_TARGET = 10.6");
  436. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  437. }
  438. {
  439. StringArray linkerFlags, librarySearchPaths;
  440. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  441. if (linkerFlags.size() > 0)
  442. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  443. if (librarySearchPaths.size() > 0)
  444. {
  445. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  446. for (int i = 0; i < librarySearchPaths.size(); ++i)
  447. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  448. s.add (libPaths + ")");
  449. }
  450. }
  451. StringPairArray defines;
  452. if (config.isDebug().getValue())
  453. {
  454. defines.set ("_DEBUG", "1");
  455. defines.set ("DEBUG", "1");
  456. s.add ("ONLY_ACTIVE_ARCH = YES");
  457. s.add ("COPY_PHASE_STRIP = NO");
  458. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  459. s.add ("GCC_ENABLE_FIX_AND_CONTINUE = NO");
  460. }
  461. else
  462. {
  463. defines.set ("_NDEBUG", "1");
  464. defines.set ("NDEBUG", "1");
  465. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  466. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  467. }
  468. {
  469. const String objCSuffix (getObjCSuffix().toString().trim());
  470. if (objCSuffix.isNotEmpty())
  471. defines.set ("JUCE_ObjCExtraSuffix", replacePreprocessorTokens (config, objCSuffix));
  472. }
  473. {
  474. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  475. StringArray defsList;
  476. for (int i = 0; i < defines.size(); ++i)
  477. {
  478. String def (defines.getAllKeys()[i]);
  479. const String value (defines.getAllValues()[i]);
  480. if (value.isNotEmpty())
  481. def << "=" << value;
  482. defsList.add (def.quoted());
  483. }
  484. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defsList, ",") + ")");
  485. }
  486. return s;
  487. }
  488. void addFrameworks()
  489. {
  490. if (! projectType.isLibrary())
  491. {
  492. StringArray s (xcodeFrameworks);
  493. s.addTokens (iPhone ? "UIKit Foundation CoreGraphics CoreText AudioToolbox QuartzCore OpenGLES"
  494. : "Cocoa Carbon IOKit CoreAudio CoreMIDI WebKit DiscRecording OpenGL QuartzCore QTKit QuickTime AudioToolbox", false);
  495. s.removeDuplicates (true);
  496. s.sort (true);
  497. for (int i = 0; i < s.size(); ++i)
  498. addFramework (s[i]);
  499. }
  500. }
  501. //==============================================================================
  502. void writeProjectFile (OutputStream& output)
  503. {
  504. output << "// !$*UTF8*$!\n{\n"
  505. "\tarchiveVersion = 1;\n"
  506. "\tclasses = {\n\t};\n"
  507. "\tobjectVersion = 45;\n"
  508. "\tobjects = {\n\n";
  509. Array <ValueTree*> objects;
  510. objects.addArray (pbxBuildFiles);
  511. objects.addArray (pbxFileReferences);
  512. objects.addArray (pbxGroups);
  513. objects.addArray (targetConfigs);
  514. objects.addArray (projectConfigs);
  515. objects.addArray (misc);
  516. for (int i = 0; i < objects.size(); ++i)
  517. {
  518. ValueTree& o = *objects.getUnchecked(i);
  519. output << "\t\t" << o.getType().toString() << " = { ";
  520. for (int j = 0; j < o.getNumProperties(); ++j)
  521. {
  522. const Identifier propertyName (o.getPropertyName(j));
  523. String val (o.getProperty (propertyName).toString());
  524. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_\r\n")
  525. && ! (val.trimStart().startsWithChar ('(')
  526. || val.trimStart().startsWithChar ('{'))))
  527. val = val.quoted();
  528. output << propertyName.toString() << " = " << val << "; ";
  529. }
  530. output << "};\n";
  531. }
  532. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  533. }
  534. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  535. {
  536. xml->createNewChildElement ("key")->addTextElement (key);
  537. xml->createNewChildElement ("string")->addTextElement (value);
  538. }
  539. static void addPlistDictionaryKeyBool (XmlElement* xml, const String& key, const bool value)
  540. {
  541. xml->createNewChildElement ("key")->addTextElement (key);
  542. xml->createNewChildElement (value ? "true" : "false");
  543. }
  544. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings)
  545. {
  546. String fileID (createID (path + "buildref"));
  547. if (addToSourceBuildPhase)
  548. sourceIDs.add (fileID);
  549. ValueTree* v = new ValueTree (fileID);
  550. v->setProperty ("isa", "PBXBuildFile", 0);
  551. v->setProperty ("fileRef", fileRefID, 0);
  552. if (inhibitWarnings)
  553. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", 0);
  554. pbxBuildFiles.add (v);
  555. return fileID;
  556. }
  557. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings)
  558. {
  559. return addBuildFile (path.toUnixStyle(), createID (path), addToSourceBuildPhase, inhibitWarnings);
  560. }
  561. String addFileReference (String pathString)
  562. {
  563. String sourceTree ("SOURCE_ROOT");
  564. RelativePath path (pathString, RelativePath::unknown);
  565. if (pathString.startsWith ("${"))
  566. {
  567. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  568. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  569. }
  570. else if (path.isAbsolute())
  571. {
  572. sourceTree = "<absolute>";
  573. }
  574. const String fileRefID (createID (pathString));
  575. ValueTree* v = new ValueTree (fileRefID);
  576. v->setProperty ("isa", "PBXFileReference", 0);
  577. v->setProperty ("lastKnownFileType", getFileType (path), 0);
  578. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), 0);
  579. v->setProperty ("path", sanitisePath (pathString), 0);
  580. v->setProperty ("sourceTree", sourceTree, 0);
  581. pbxFileReferences.add (v);
  582. return fileRefID;
  583. }
  584. static String getFileType (const RelativePath& file)
  585. {
  586. if (file.hasFileExtension ("cpp;cc;cxx")) return "sourcecode.cpp.cpp";
  587. else if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  588. else if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  589. else if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  590. else if (file.hasFileExtension (".framework")) return "wrapper.framework";
  591. else if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  592. else if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  593. else if (file.hasFileExtension ("html;htm")) return "text.html";
  594. else if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  595. else if (file.hasFileExtension ("plist")) return "text.plist.xml";
  596. else if (file.hasFileExtension ("app")) return "wrapper.application";
  597. else if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  598. else if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  599. else if (file.hasFileExtension ("a")) return "archive.ar";
  600. return "file" + file.getFileExtension();
  601. }
  602. String addFile (const RelativePath& path, bool shouldBeCompiled, bool inhibitWarnings)
  603. {
  604. if (shouldBeCompiled)
  605. {
  606. if (path.hasFileExtension (".r"))
  607. rezFileIDs.add (addBuildFile (path, false, inhibitWarnings));
  608. else
  609. addBuildFile (path, true, inhibitWarnings);
  610. }
  611. return addFileReference (path.toUnixStyle());
  612. }
  613. String addProjectItem (const Project::Item& projectItem)
  614. {
  615. if (projectItem.isGroup())
  616. {
  617. StringArray childIDs;
  618. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  619. {
  620. const String childID (addProjectItem (projectItem.getChild(i)));
  621. if (childID.isNotEmpty())
  622. childIDs.add (childID);
  623. }
  624. return addGroup (projectItem, childIDs);
  625. }
  626. else
  627. {
  628. if (projectItem.shouldBeAddedToTargetProject())
  629. {
  630. String itemPath (projectItem.getFilePath());
  631. bool inhibitWarnings = projectItem.getShouldInhibitWarningsValue().getValue();
  632. if (itemPath.startsWith ("${"))
  633. {
  634. const RelativePath path (itemPath, RelativePath::unknown);
  635. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  636. }
  637. else
  638. {
  639. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  640. return addFile (path, projectItem.shouldBeCompiled(), inhibitWarnings);
  641. }
  642. }
  643. }
  644. return String::empty;
  645. }
  646. void addFramework (const String& frameworkName)
  647. {
  648. const String path ("System/Library/Frameworks/" + frameworkName + ".framework");
  649. const String fileRefID (createID (path));
  650. addFileReference ("${SDKROOT}/" + path);
  651. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  652. frameworkFileIDs.add (fileRefID);
  653. }
  654. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs)
  655. {
  656. ValueTree* v = new ValueTree (groupID);
  657. v->setProperty ("isa", "PBXGroup", 0);
  658. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", 0);
  659. v->setProperty (Ids::name, groupName, 0);
  660. v->setProperty ("sourceTree", "<group>", 0);
  661. pbxGroups.add (v);
  662. }
  663. String addGroup (const Project::Item& item, StringArray& childIDs)
  664. {
  665. const String groupName (item.getName().toString());
  666. const String groupID (getIDForGroup (item));
  667. addGroup (groupID, groupName, childIDs);
  668. return groupID;
  669. }
  670. void addMainBuildProduct()
  671. {
  672. jassert (xcodeFileType.isNotEmpty());
  673. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar('.'));
  674. String productName (configs.getReference(0).getTargetBinaryName().toString());
  675. if (xcodeFileType == "archive.ar")
  676. productName = getLibbedFilename (productName);
  677. else
  678. productName += xcodeBundleExtension;
  679. addBuildProduct (xcodeFileType, productName);
  680. }
  681. void addBuildProduct (const String& fileType, const String& binaryName)
  682. {
  683. ValueTree* v = new ValueTree (createID ("__productFileID"));
  684. v->setProperty ("isa", "PBXFileReference", 0);
  685. v->setProperty ("explicitFileType", fileType, 0);
  686. v->setProperty ("includeInIndex", (int) 0, 0);
  687. v->setProperty ("path", sanitisePath (binaryName), 0);
  688. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", 0);
  689. pbxFileReferences.add (v);
  690. }
  691. void addTargetConfig (const String& configName, const StringArray& buildSettings)
  692. {
  693. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  694. v->setProperty ("isa", "XCBuildConfiguration", 0);
  695. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  696. v->setProperty (Ids::name, configName, 0);
  697. targetConfigs.add (v);
  698. }
  699. void addProjectConfig (const String& configName, const StringArray& buildSettings)
  700. {
  701. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  702. v->setProperty ("isa", "XCBuildConfiguration", 0);
  703. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  704. v->setProperty (Ids::name, configName, 0);
  705. projectConfigs.add (v);
  706. }
  707. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID)
  708. {
  709. StringArray configIDs;
  710. for (int i = 0; i < configsToUse.size(); ++i)
  711. configIDs.add (configsToUse[i]->getType().toString());
  712. ValueTree* v = new ValueTree (listID);
  713. v->setProperty ("isa", "XCConfigurationList", 0);
  714. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", 0);
  715. v->setProperty ("defaultConfigurationIsVisible", (int) 0, 0);
  716. if (configsToUse[0] != nullptr)
  717. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty (Ids::name), 0);
  718. misc.add (v);
  719. }
  720. ValueTree* addBuildPhase (const String& phaseType, const StringArray& fileIds)
  721. {
  722. String phaseId (createID (phaseType + "resbuildphase"));
  723. buildPhaseIDs.add (phaseId);
  724. ValueTree* v = new ValueTree (phaseId);
  725. v->setProperty ("isa", phaseType, 0);
  726. v->setProperty ("buildActionMask", "2147483647", 0);
  727. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", 0);
  728. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, 0);
  729. misc.add (v);
  730. return v;
  731. }
  732. void addTargetObject()
  733. {
  734. ValueTree* const v = new ValueTree (createID ("__target"));
  735. v->setProperty ("isa", "PBXNativeTarget", 0);
  736. v->setProperty ("buildConfigurationList", createID ("__configList"), 0);
  737. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", 0);
  738. v->setProperty ("buildRules", "( )", 0);
  739. v->setProperty ("dependencies", "( )", 0);
  740. v->setProperty (Ids::name, projectName, 0);
  741. v->setProperty ("productName", projectName, 0);
  742. v->setProperty ("productReference", createID ("__productFileID"), 0);
  743. if (xcodeProductInstallPath.isNotEmpty())
  744. v->setProperty ("productInstallPath", xcodeProductInstallPath, 0);
  745. jassert (xcodeProductType.isNotEmpty());
  746. v->setProperty ("productType", xcodeProductType, 0);
  747. misc.add (v);
  748. }
  749. void addProjectObject()
  750. {
  751. ValueTree* const v = new ValueTree (createID ("__root"));
  752. v->setProperty ("isa", "PBXProject", 0);
  753. v->setProperty ("buildConfigurationList", createID ("__projList"), 0);
  754. v->setProperty ("compatibilityVersion", "Xcode 3.1", 0);
  755. v->setProperty ("hasScannedForEncodings", (int) 0, 0);
  756. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), 0);
  757. v->setProperty ("projectDirPath", "\"\"", 0);
  758. v->setProperty ("projectRoot", "\"\"", 0);
  759. v->setProperty ("targets", "( " + createID ("__target") + " )", 0);
  760. misc.add (v);
  761. }
  762. void addShellScriptPhase()
  763. {
  764. if (xcodeShellScript.isNotEmpty())
  765. {
  766. ValueTree* const v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  767. v->setProperty (Ids::name, xcodeShellScriptTitle, 0);
  768. v->setProperty ("shellPath", "/bin/sh", 0);
  769. v->setProperty ("shellScript", xcodeShellScript.replace ("\\", "\\\\")
  770. .replace ("\"", "\\\"")
  771. .replace ("\r\n", "\\n")
  772. .replace ("\n", "\\n"), 0);
  773. }
  774. }
  775. //==============================================================================
  776. static String indentList (const StringArray& list, const String& separator)
  777. {
  778. if (list.size() == 0)
  779. return " ";
  780. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  781. + (separator == ";" ? separator : String::empty);
  782. }
  783. String createID (const RelativePath& path) const
  784. {
  785. return createID (path.toUnixStyle());
  786. }
  787. String createID (String rootString) const
  788. {
  789. if (rootString.startsWith ("${"))
  790. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  791. static const char digits[] = "0123456789ABCDEF";
  792. char n[24];
  793. Random ran (projectIDSalt + hashCode64 (rootString));
  794. for (int i = 0; i < numElementsInArray (n); ++i)
  795. n[i] = digits [ran.nextInt() & 15];
  796. return String (n, numElementsInArray (n));
  797. }
  798. String getIDForGroup (const Project::Item& item) const
  799. {
  800. return createID (item.getID());
  801. }
  802. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  803. {
  804. return file.hasFileExtension (sourceFileExtensions);
  805. }
  806. };
  807. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__