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.

1061 lines
43KB

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