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.

3438 lines
157KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "jucer_XcodeProjectParser.h"
  21. //==============================================================================
  22. namespace
  23. {
  24. const char* const osxVersionDefault = "10.11";
  25. const char* const iosVersionDefault = "9.3";
  26. const int oldestSDKVersion = 7;
  27. const int currentSDKVersion = 14;
  28. const int minimumAUv3SDKVersion = 11;
  29. const char* const osxArch_Default = "default";
  30. const char* const osxArch_Native = "Native";
  31. const char* const osxArch_32BitUniversal = "32BitUniversal";
  32. const char* const osxArch_64BitUniversal = "64BitUniversal";
  33. const char* const osxArch_64Bit = "64BitIntel";
  34. }
  35. //==============================================================================
  36. class XcodeProjectExporter : public ProjectExporter
  37. {
  38. public:
  39. //==============================================================================
  40. static const char* getNameMac() { return "Xcode (MacOSX)"; }
  41. static const char* getNameiOS() { return "Xcode (iOS)"; }
  42. static const char* getValueTreeTypeName (bool iOS) { return iOS ? "XCODE_IPHONE" : "XCODE_MAC"; }
  43. //==============================================================================
  44. XcodeProjectExporter (Project& p, const ValueTree& t, const bool isIOS)
  45. : ProjectExporter (p, t),
  46. xcodeCanUseDwarf (true),
  47. iOS (isIOS),
  48. customPListValue (settings, Ids::customPList, getUndoManager()),
  49. pListPrefixHeaderValue (settings, Ids::pListPrefixHeader, getUndoManager()),
  50. pListPreprocessValue (settings, Ids::pListPreprocess, getUndoManager()),
  51. subprojectsValue (settings, Ids::xcodeSubprojects, getUndoManager()),
  52. extraFrameworksValue (settings, Ids::extraFrameworks, getUndoManager()),
  53. frameworkSearchPathsValue (settings, Ids::frameworkSearchPaths, getUndoManager()),
  54. extraCustomFrameworksValue (settings, Ids::extraCustomFrameworks, getUndoManager()),
  55. embeddedFrameworksValue (settings, Ids::embeddedFrameworks, getUndoManager()),
  56. postbuildCommandValue (settings, Ids::postbuildCommand, getUndoManager()),
  57. prebuildCommandValue (settings, Ids::prebuildCommand, getUndoManager()),
  58. duplicateAppExResourcesFolderValue (settings, Ids::duplicateAppExResourcesFolder, getUndoManager(), true),
  59. iosDeviceFamilyValue (settings, Ids::iosDeviceFamily, getUndoManager(), "1,2"),
  60. iPhoneScreenOrientationValue (settings, Ids::iPhoneScreenOrientation, getUndoManager(), "portraitlandscape"),
  61. iPadScreenOrientationValue (settings, Ids::iPadScreenOrientation, getUndoManager(), "portraitlandscape"),
  62. customXcodeResourceFoldersValue (settings, Ids::customXcodeResourceFolders, getUndoManager()),
  63. customXcassetsFolderValue (settings, Ids::customXcassetsFolder, getUndoManager()),
  64. microphonePermissionNeededValue (settings, Ids::microphonePermissionNeeded, getUndoManager()),
  65. microphonePermissionsTextValue (settings, Ids::microphonePermissionsText, getUndoManager(),
  66. "This app requires audio input. If you do not have an audio interface connected it will use the built-in microphone."),
  67. cameraPermissionNeededValue (settings, Ids::cameraPermissionNeeded, getUndoManager()),
  68. cameraPermissionTextValue (settings, Ids::cameraPermissionText, getUndoManager(),
  69. "This app requires access to the camera to function correctly."),
  70. uiFileSharingEnabledValue (settings, Ids::UIFileSharingEnabled, getUndoManager()),
  71. uiSupportsDocumentBrowserValue (settings, Ids::UISupportsDocumentBrowser, getUndoManager()),
  72. uiStatusBarHiddenValue (settings, Ids::UIStatusBarHidden, getUndoManager()),
  73. documentExtensionsValue (settings, Ids::documentExtensions, getUndoManager()),
  74. iosInAppPurchasesValue (settings, Ids::iosInAppPurchases, getUndoManager()),
  75. iosBackgroundAudioValue (settings, Ids::iosBackgroundAudio, getUndoManager()),
  76. iosBackgroundBleValue (settings, Ids::iosBackgroundBle, getUndoManager()),
  77. iosPushNotificationsValue (settings, Ids::iosPushNotifications, getUndoManager()),
  78. iosAppGroupsValue (settings, Ids::iosAppGroups, getUndoManager()),
  79. iCloudPermissionsValue (settings, Ids::iCloudPermissions, getUndoManager()),
  80. iosDevelopmentTeamIDValue (settings, Ids::iosDevelopmentTeamID, getUndoManager()),
  81. iosAppGroupsIDValue (settings, Ids::iosAppGroupsId, getUndoManager()),
  82. keepCustomXcodeSchemesValue (settings, Ids::keepCustomXcodeSchemes, getUndoManager()),
  83. useHeaderMapValue (settings, Ids::useHeaderMap, getUndoManager())
  84. {
  85. name = iOS ? getNameiOS() : getNameMac();
  86. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderForExporter (getValueTreeTypeName (isIOS)));
  87. }
  88. static XcodeProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  89. {
  90. if (settings.hasType (getValueTreeTypeName (false))) return new XcodeProjectExporter (project, settings, false);
  91. if (settings.hasType (getValueTreeTypeName (true))) return new XcodeProjectExporter (project, settings, true);
  92. return nullptr;
  93. }
  94. //==============================================================================
  95. String getPListToMergeString() const { return customPListValue.get(); }
  96. String getPListPrefixHeaderString() const { return pListPrefixHeaderValue.get(); }
  97. bool isPListPreprocessEnabled() const { return pListPreprocessValue.get(); }
  98. String getSubprojectsString() const { return subprojectsValue.get(); }
  99. String getExtraFrameworksString() const { return extraFrameworksValue.get(); }
  100. String getFrameworkSearchPathsString() const { return frameworkSearchPathsValue.get(); }
  101. String getExtraCustomFrameworksString() const { return extraCustomFrameworksValue.get(); }
  102. String getEmbeddedFrameworksString() const { return embeddedFrameworksValue.get(); }
  103. String getPostBuildScript() const { return postbuildCommandValue.get(); }
  104. String getPreBuildScript() const { return prebuildCommandValue.get(); }
  105. bool shouldDuplicateAppExResourcesFolder() const { return duplicateAppExResourcesFolderValue.get(); }
  106. String getDeviceFamilyString() const { return iosDeviceFamilyValue.get(); }
  107. String getiPhoneScreenOrientationString() const { return iPhoneScreenOrientationValue.get(); }
  108. String getiPadScreenOrientationString() const { return iPadScreenOrientationValue.get(); }
  109. String getCustomResourceFoldersString() const { return customXcodeResourceFoldersValue.get().toString().replaceCharacters ("\r\n", "::"); }
  110. String getCustomXcassetsFolderString() const { return customXcassetsFolderValue.get(); }
  111. bool isMicrophonePermissionEnabled() const { return microphonePermissionNeededValue.get(); }
  112. String getMicrophonePermissionsTextString() const { return microphonePermissionsTextValue.get(); }
  113. bool isCameraPermissionEnabled() const { return cameraPermissionNeededValue.get(); }
  114. String getCameraPermissionTextString() const { return cameraPermissionTextValue.get(); }
  115. bool isInAppPurchasesEnabled() const { return iosInAppPurchasesValue.get(); }
  116. bool isBackgroundAudioEnabled() const { return iosBackgroundAudioValue.get(); }
  117. bool isBackgroundBleEnabled() const { return iosBackgroundBleValue.get(); }
  118. bool isPushNotificationsEnabled() const { return iosPushNotificationsValue.get(); }
  119. bool isAppGroupsEnabled() const { return iosAppGroupsValue.get(); }
  120. bool isiCloudPermissionsEnabled() const { return iCloudPermissionsValue.get(); }
  121. bool isFileSharingEnabled() const { return uiFileSharingEnabledValue.get(); }
  122. bool isDocumentBrowserEnabled() const { return uiSupportsDocumentBrowserValue.get(); }
  123. bool isStatusBarHidden() const { return uiStatusBarHiddenValue.get(); }
  124. String getIosDevelopmentTeamIDString() const { return iosDevelopmentTeamIDValue.get(); }
  125. String getAppGroupIdString() const { return iosAppGroupsIDValue.get(); }
  126. //==============================================================================
  127. bool usesMMFiles() const override { return true; }
  128. bool canCopeWithDuplicateFiles() override { return true; }
  129. bool supportsUserDefinedConfigurations() const override { return true; }
  130. bool isXcode() const override { return true; }
  131. bool isVisualStudio() const override { return false; }
  132. bool isCodeBlocks() const override { return false; }
  133. bool isMakefile() const override { return false; }
  134. bool isAndroidStudio() const override { return false; }
  135. bool isCLion() const override { return false; }
  136. bool isAndroid() const override { return false; }
  137. bool isWindows() const override { return false; }
  138. bool isLinux() const override { return false; }
  139. bool isOSX() const override { return ! iOS; }
  140. bool isiOS() const override { return iOS; }
  141. bool supportsTargetType (ProjectType::Target::Type type) const override
  142. {
  143. switch (type)
  144. {
  145. case ProjectType::Target::AudioUnitv3PlugIn:
  146. case ProjectType::Target::StandalonePlugIn:
  147. case ProjectType::Target::GUIApp:
  148. case ProjectType::Target::StaticLibrary:
  149. case ProjectType::Target::SharedCodeTarget:
  150. case ProjectType::Target::AggregateTarget:
  151. return true;
  152. case ProjectType::Target::ConsoleApp:
  153. case ProjectType::Target::VSTPlugIn:
  154. case ProjectType::Target::VST3PlugIn:
  155. case ProjectType::Target::AAXPlugIn:
  156. case ProjectType::Target::RTASPlugIn:
  157. case ProjectType::Target::AudioUnitPlugIn:
  158. case ProjectType::Target::DynamicLibrary:
  159. case ProjectType::Target::UnityPlugIn:
  160. return ! iOS;
  161. default:
  162. break;
  163. }
  164. return false;
  165. }
  166. void createExporterProperties (PropertyListBuilder& props) override
  167. {
  168. if (iOS)
  169. {
  170. props.add (new TextPropertyComponent (customXcassetsFolderValue, "Custom Xcassets Folder", 128, false),
  171. "If this field is not empty, your Xcode project will use the custom xcassets folder specified here "
  172. "for the app icons and launchimages, and will ignore the Icon files specified above.");
  173. }
  174. props.add (new TextPropertyComponent (customXcodeResourceFoldersValue, "Custom Xcode Resource Folders", 8192, true),
  175. "You can specify a list of custom resource folders here (separated by newlines or whitespace). "
  176. "References to these folders will then be added to the Xcode resources. "
  177. "This way you can specify them for OS X and iOS separately, and modify the content of the resource folders "
  178. "without re-saving the Projucer project.");
  179. if (getProject().getProjectType().isAudioPlugin())
  180. props.add (new ChoicePropertyComponent (duplicateAppExResourcesFolderValue, "Add Duplicate Resources Folder to App Extension"),
  181. "Disable this to prevent the Projucer from creating a duplicate resources folder for AUv3 app extensions.");
  182. if (iOS)
  183. {
  184. props.add (new ChoicePropertyComponent (iosDeviceFamilyValue, "Device Family",
  185. { "iPhone", "iPad", "Universal" },
  186. { "1", "2", "1,2" }),
  187. "The device family to target.");
  188. {
  189. StringArray orientationStrings { "Portrait and Landscape", "Portrait", "Landscape" };
  190. Array<var> orientationValues { "portraitlandscape", "portrait", "landscape"};
  191. props.add (new ChoicePropertyComponent (iPhoneScreenOrientationValue, "iPhone Screen Orientation",
  192. orientationStrings, orientationValues),
  193. "The screen orientations that this app should support on iPhones.");
  194. props.add (new ChoicePropertyComponent (iPadScreenOrientationValue, "iPad Screen Orientation",
  195. orientationStrings, orientationValues),
  196. "The screen orientations that this app should support on iPads.");
  197. }
  198. props.add (new ChoicePropertyComponent (uiFileSharingEnabledValue, "File Sharing Enabled"),
  199. "Enable this to expose your app's files to iTunes.");
  200. props.add (new ChoicePropertyComponent (uiSupportsDocumentBrowserValue, "Support Document Browser"),
  201. "Enable this to allow the user to access your app documents from a native file chooser.");
  202. props.add (new ChoicePropertyComponent (uiStatusBarHiddenValue, "Status Bar Hidden"),
  203. "Enable this to disable the status bar in your app.");
  204. }
  205. else if (projectType.isGUIApplication())
  206. {
  207. props.add (new TextPropertyComponent (documentExtensionsValue, "Document File Extensions", 128, false),
  208. "A comma-separated list of file extensions for documents that your app can open. "
  209. "Using a leading '.' is optional, and the extensions are not case-sensitive.");
  210. }
  211. props.add (new ChoicePropertyComponent (microphonePermissionNeededValue, "Microphone Access"),
  212. "Enable this to allow your app to use the microphone. "
  213. "The user of your app will be prompted to grant microphone access permissions.");
  214. props.add (new TextPropertyComponentWithEnablement (microphonePermissionsTextValue, microphonePermissionNeededValue,
  215. "Microphone Access Text", 1024, false),
  216. "A short description of why your app requires microphone access.");
  217. props.add (new ChoicePropertyComponent (cameraPermissionNeededValue, "Camera Access"),
  218. "Enable this to allow your app to use the camera. "
  219. "The user of your app will be prompted to grant camera access permissions.");
  220. props.add (new TextPropertyComponentWithEnablement (cameraPermissionTextValue, cameraPermissionNeededValue,
  221. "Camera Access Text", 1024, false),
  222. "A short description of why your app requires camera access.");
  223. props.add (new ChoicePropertyComponent (iosInAppPurchasesValue, "In-App Purchases Capability"),
  224. "Enable this to grant your app the capability for in-app purchases. "
  225. "This option requires that you specify a valid Development Team ID.");
  226. if (iOS)
  227. {
  228. props.add (new ChoicePropertyComponent (iosBackgroundAudioValue, "Audio Background Capability"),
  229. "Enable this to grant your app the capability to access audio when in background mode.");
  230. props.add (new ChoicePropertyComponent (iosBackgroundBleValue, "Bluetooth MIDI Background Capability"),
  231. "Enable this to grant your app the capability to connect to Bluetooth LE devices when in background mode.");
  232. props.add (new ChoicePropertyComponent (iosAppGroupsValue, "App Groups Capability"),
  233. "Enable this to grant your app the capability to share resources between apps using the same app group ID.");
  234. props.add (new ChoicePropertyComponent (iCloudPermissionsValue, "iCloud Permissions"),
  235. "Enable this to grant your app the capability to use native file load/save browser windows on iOS.");
  236. }
  237. props.add (new ChoicePropertyComponent (iosPushNotificationsValue, "Push Notifications Capability"),
  238. "Enable this to grant your app the capability to receive push notifications.");
  239. props.add (new TextPropertyComponent (customPListValue, "Custom PList", 8192, true),
  240. "You can paste the contents of an XML PList file in here, and the settings that it contains will override any "
  241. "settings that the Projucer creates. BEWARE! When doing this, be careful to remove from the XML any "
  242. "values that you DO want the Projucer to change!");
  243. props.add (new ChoicePropertyComponent (pListPreprocessValue, "PList Preprocess"),
  244. "Enable this to preprocess PList file. This will allow you to set values to preprocessor defines,"
  245. " for instance if you define: #define MY_FLAG 1 in a prefix header file (see PList prefix header), you can have"
  246. " a key with MY_FLAG value and it will be replaced with 1.");
  247. props.add (new TextPropertyComponent (pListPrefixHeaderValue, "PList Prefix Header", 512, false),
  248. "Header file containing definitions used in plist file (see PList Preprocess).");
  249. props.add (new TextPropertyComponent (extraFrameworksValue, "Extra System Frameworks", 2048, false),
  250. "A comma-separated list of extra system frameworks that should be added to the build. "
  251. "(Don't include the .framework extension in the name)"
  252. " The frameworks are expected to be located in /System/Library/Frameworks");
  253. props.add (new TextPropertyComponent (frameworkSearchPathsValue, "Framework Search Paths", 8192, true),
  254. "A set of paths to search for custom frameworks (one per line).");
  255. props.add (new TextPropertyComponent (extraCustomFrameworksValue, "Extra Custom Frameworks", 8192, true),
  256. "Paths to custom frameworks that should be added to the build (one per line). "
  257. "You will probably need to add an entry to the Framework Search Paths for each unique directory.");
  258. props.add (new TextPropertyComponent (embeddedFrameworksValue, "Embedded Frameworks", 8192, true),
  259. "Paths to frameworks to be embedded with the app (one per line). "
  260. "If you are adding a framework here then you do not need to specify it in Extra Custom Frameworks too. "
  261. "You will probably need to add an entry to the Framework Search Paths for each unique directory.");
  262. props.add (new TextPropertyComponent (subprojectsValue, "Xcode Subprojects", 8192, true),
  263. "Paths to Xcode projects that should be added to the build (one per line). "
  264. "The names of the required build products can be specified after a colon, comma seperated, "
  265. "e.g. \"path/to/MySubProject.xcodeproj: MySubProject, OtherTarget\". "
  266. "If no build products are specified, all build products associated with a subproject will be added.");
  267. props.add (new TextPropertyComponent (prebuildCommandValue, "Pre-Build Shell Script", 32768, true),
  268. "Some shell-script that will be run before a build starts.");
  269. props.add (new TextPropertyComponent (postbuildCommandValue, "Post-Build Shell Script", 32768, true),
  270. "Some shell-script that will be run after a build completes.");
  271. props.add (new TextPropertyComponent (iosDevelopmentTeamIDValue, "Development Team ID", 10, false),
  272. "The Development Team ID to be used for setting up code-signing your iOS app. This is a ten-character "
  273. "string (for example, \"S7B6T5XJ2Q\") that describes the distribution certificate Apple issued to you. "
  274. "You can find this string in the OS X app Keychain Access under \"Certificates\".");
  275. if (iOS)
  276. props.add (new TextPropertyComponentWithEnablement (iosAppGroupsIDValue, iosAppGroupsValue, "App Group ID", 256, false),
  277. "The App Group ID to be used for allowing multiple apps to access a shared resource folder. Multiple IDs can be "
  278. "added separated by a semicolon.");
  279. props.add (new ChoicePropertyComponent (keepCustomXcodeSchemesValue, "Keep Custom Xcode Schemes"),
  280. "Enable this to keep any Xcode schemes you have created for debugging or running, e.g. to launch a plug-in in"
  281. "various hosts. If disabled, all schemes are replaced by a default set.");
  282. props.add (new ChoicePropertyComponent (useHeaderMapValue, "USE_HEADERMAP"),
  283. "Enable this to make Xcode search all the projects folders for include files. This means you can be lazy "
  284. "and not bother using relative paths to include your headers, but it means your code won't be "
  285. "compatible with other build systems");
  286. }
  287. bool launchProject() override
  288. {
  289. #if JUCE_MAC
  290. return getProjectBundle().startAsProcess();
  291. #else
  292. return false;
  293. #endif
  294. }
  295. bool canLaunchProject() override
  296. {
  297. #if JUCE_MAC
  298. return true;
  299. #else
  300. return false;
  301. #endif
  302. }
  303. //==============================================================================
  304. void create (const OwnedArray<LibraryModule>&) const override
  305. {
  306. for (auto& target : targets)
  307. if (target->shouldCreatePList())
  308. target->infoPlistFile = getTargetFolder().getChildFile (target->getInfoPlistName());
  309. menuNibFile = getTargetFolder().getChildFile ("RecentFilesMenuTemplate.nib");
  310. createIconFile();
  311. auto projectBundle = getProjectBundle();
  312. createDirectoryOrThrow (projectBundle);
  313. createObjects();
  314. auto projectFile = projectBundle.getChildFile ("project.pbxproj");
  315. {
  316. MemoryOutputStream mo;
  317. writeProjectFile (mo);
  318. overwriteFileIfDifferentOrThrow (projectFile, mo);
  319. }
  320. writeInfoPlistFiles();
  321. // Deleting the .rsrc files can be needed to force Xcode to update the version number.
  322. deleteRsrcFiles (getTargetFolder().getChildFile ("build"));
  323. }
  324. //==============================================================================
  325. void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
  326. {
  327. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  328. {
  329. if (auto* target = new XcodeTarget (targetType, *this))
  330. {
  331. if (targetType == ProjectType::Target::AggregateTarget)
  332. targets.insert (0, target);
  333. else
  334. targets.add (target);
  335. }
  336. });
  337. // If you hit this assert, you tried to generate a project for an exporter
  338. // that does not support any of your targets!
  339. jassert (targets.size() > 0);
  340. }
  341. void updateDeprecatedProjectSettingsInteractively() override
  342. {
  343. if (hasInvalidPostBuildScript())
  344. {
  345. String alertWindowText = iOS ? "Your Xcode (iOS) Exporter settings use an invalid post-build script. Click 'Update' to remove it."
  346. : "Your Xcode (OSX) Exporter settings use a pre-JUCE 4.2 post-build script to move the plug-in binaries to their plug-in install folders.\n\n"
  347. "Since JUCE 4.2, this is instead done using \"AU/VST/VST2/AAX/RTAS Binary Location\" in the Xcode (OS X) configuration settings.\n\n"
  348. "Click 'Update' to remove the script (otherwise your plug-in may not compile correctly).";
  349. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  350. "Project settings: " + project.getDocumentTitle(),
  351. alertWindowText, "Update", "Cancel", nullptr, nullptr))
  352. postbuildCommandValue.resetToDefault();
  353. }
  354. }
  355. bool hasInvalidPostBuildScript() const
  356. {
  357. // check whether the script is identical to the old one that the Introjucer used to auto-generate
  358. return (MD5 (getPostBuildScript().toUTF8()).toHexString() == "265ac212a7e734c5bbd6150e1eae18a1");
  359. }
  360. //==============================================================================
  361. void initialiseDependencyPathValues() override
  362. {
  363. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder), Ids::vst3Path, TargetOS::osx)));
  364. aaxPath. referTo (Value (new DependencyPathValueSource (getSetting (Ids::aaxFolder), Ids::aaxPath, TargetOS::osx)));
  365. rtasPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::rtasFolder), Ids::rtasPath, TargetOS::osx)));
  366. }
  367. protected:
  368. //==============================================================================
  369. class XcodeBuildConfiguration : public BuildConfiguration
  370. {
  371. public:
  372. XcodeBuildConfiguration (Project& p, const ValueTree& t, const bool isIOS, const ProjectExporter& e)
  373. : BuildConfiguration (p, t, e),
  374. iOS (isIOS),
  375. osxSDKVersion (config, Ids::osxSDK, getUndoManager()),
  376. osxDeploymentTarget (config, Ids::osxCompatibility, getUndoManager(), String (osxVersionDefault) + " SDK"),
  377. iosDeploymentTarget (config, Ids::iosCompatibility, getUndoManager(), iosVersionDefault),
  378. osxArchitecture (config, Ids::osxArchitecture, getUndoManager(), osxArch_Default),
  379. customXcodeFlags (config, Ids::customXcodeFlags, getUndoManager()),
  380. plistPreprocessorDefinitions (config, Ids::plistPreprocessorDefinitions, getUndoManager()),
  381. codeSignIdentity (config, Ids::codeSigningIdentity, getUndoManager(), iOS ? "iPhone Developer" : "Mac Developer"),
  382. fastMathEnabled (config, Ids::fastMath, getUndoManager()),
  383. stripLocalSymbolsEnabled (config, Ids::stripLocalSymbols, getUndoManager()),
  384. pluginBinaryCopyStepEnabled (config, Ids::enablePluginBinaryCopyStep, getUndoManager(), true),
  385. vstBinaryLocation (config, Ids::vstBinaryLocation, getUndoManager(), "$(HOME)/Library/Audio/Plug-Ins/VST/"),
  386. vst3BinaryLocation (config, Ids::vst3BinaryLocation, getUndoManager(), "$(HOME)/Library/Audio/Plug-Ins/VST3/"),
  387. auBinaryLocation (config, Ids::auBinaryLocation, getUndoManager(), "$(HOME)/Library/Audio/Plug-Ins/Components/"),
  388. rtasBinaryLocation (config, Ids::rtasBinaryLocation, getUndoManager(), "/Library/Application Support/Digidesign/Plug-Ins/"),
  389. aaxBinaryLocation (config, Ids::aaxBinaryLocation, getUndoManager(), "/Library/Application Support/Avid/Audio/Plug-Ins/"),
  390. unityPluginBinaryLocation (config, Ids::unityPluginBinaryLocation, getUndoManager())
  391. {
  392. updateOldPluginBinaryLocations();
  393. updateOldSDKDefaults();
  394. optimisationLevelValue.setDefault (isDebug() ? gccO0 : gccO3);
  395. }
  396. //==========================================================================
  397. void createConfigProperties (PropertyListBuilder& props) override
  398. {
  399. addXcodePluginInstallPathProperties (props);
  400. addGCCOptimisationProperty (props);
  401. if (iOS)
  402. {
  403. props.add (new ChoicePropertyComponent (iosDeploymentTarget, "iOS Deployment Target",
  404. { "7.0", "7.1", "8.0", "8.1", "8.2", "8.3", "8.4",
  405. "9.0", "9.1", "9.2", "9.3", "10.0", "10.1", "10.2", "10.3",
  406. "11.0", "12.0" },
  407. { "7.0", "7.1", "8.0", "8.1", "8.2", "8.3", "8.4",
  408. "9.0", "9.1", "9.2", "9.3", "10.0", "10.1", "10.2", "10.3",
  409. "11.0", "12.0" }),
  410. "The minimum version of iOS that the target binary will run on.");
  411. }
  412. else
  413. {
  414. StringArray sdkVersionNames, osxVersionNames;
  415. Array<var> versionValues;
  416. for (int ver = oldestSDKVersion; ver <= currentSDKVersion; ++ver)
  417. {
  418. sdkVersionNames.add (getSDKName (ver));
  419. osxVersionNames.add (getOSXVersionName (ver));
  420. versionValues.add (getSDKName (ver));
  421. }
  422. props.add (new ChoicePropertyComponent (osxSDKVersion, "OSX Base SDK Version", sdkVersionNames, versionValues),
  423. "The version of OSX to link against in the Xcode build. If \"Default\" is selected then the field will be left "
  424. "empty and the Xcode default will be used.");
  425. props.add (new ChoicePropertyComponent (osxDeploymentTarget, "OSX Deployment Target", osxVersionNames, versionValues),
  426. "The minimum version of OSX that the target binary will be compatible with.");
  427. props.add (new ChoicePropertyComponent (osxArchitecture, "OSX Architecture",
  428. { "Native architecture of build machine", "Universal Binary (32-bit)", "Universal Binary (32/64-bit)", "64-bit Intel" },
  429. { osxArch_Native, osxArch_32BitUniversal, osxArch_64BitUniversal, osxArch_64Bit }),
  430. "The type of OSX binary that will be produced.");
  431. }
  432. props.add (new TextPropertyComponent (customXcodeFlags, "Custom Xcode Flags", 8192, false),
  433. "A comma-separated list of custom Xcode setting flags which will be appended to the list of generated flags, "
  434. "e.g. MACOSX_DEPLOYMENT_TARGET_i386 = 10.5, VALID_ARCHS = \"ppc i386 x86_64\"");
  435. props.add (new TextPropertyComponent (plistPreprocessorDefinitions, "PList Preprocessor Definitions", 2048, true),
  436. "Preprocessor definitions used during PList preprocessing (see PList Preprocess).");
  437. props.add (new TextPropertyComponent (codeSignIdentity, "Code-Signing Identity", 1024, false),
  438. "The name of a code-signing identity for Xcode to apply.");
  439. props.add (new ChoicePropertyComponent (fastMathEnabled, "Relax IEEE Compliance"),
  440. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  441. props.add (new ChoicePropertyComponent (stripLocalSymbolsEnabled, "Strip Local Symbols"),
  442. "Enable this to strip any locally defined symbols resulting in a smaller binary size. Enabling this "
  443. "will also remove any function names from crash logs. Must be disabled for static library projects.");
  444. }
  445. String getModuleLibraryArchName() const override
  446. {
  447. return "${CURRENT_ARCH}";
  448. }
  449. //==========================================================================
  450. String getOSXArchitectureString() const { return osxArchitecture.get(); }
  451. String getPListPreprocessorDefinitionsString() const { return plistPreprocessorDefinitions.get(); }
  452. bool isFastMathEnabled() const { return fastMathEnabled.get(); }
  453. bool isStripLocalSymbolsEnabled() const { return stripLocalSymbolsEnabled.get(); }
  454. String getCustomXcodeFlagsString() const { return customXcodeFlags.get(); }
  455. String getOSXSDKVersionString() const { return osxSDKVersion.get(); }
  456. String getOSXDeploymentTargetString() const { return osxDeploymentTarget.get(); }
  457. String getCodeSignIdentityString() const { return codeSignIdentity.get(); }
  458. bool isUsingDefaultCodeSignIdentity() const { return codeSignIdentity.isUsingDefault(); }
  459. String getiOSDeploymentTargetString() const { return iosDeploymentTarget.get(); }
  460. bool isPluginBinaryCopyStepEnabled() const { return pluginBinaryCopyStepEnabled.get(); }
  461. String getVSTBinaryLocationString() const { return vstBinaryLocation.get(); }
  462. String getVST3BinaryLocationString() const { return vst3BinaryLocation.get(); }
  463. String getAUBinaryLocationString() const { return auBinaryLocation.get(); }
  464. String getRTASBinaryLocationString() const { return rtasBinaryLocation.get();}
  465. String getAAXBinaryLocationString() const { return aaxBinaryLocation.get();}
  466. String getUnityPluginBinaryLocationString() const { return unityPluginBinaryLocation.get(); }
  467. private:
  468. //==========================================================================
  469. bool iOS;
  470. ValueWithDefault osxSDKVersion, osxDeploymentTarget, iosDeploymentTarget, osxArchitecture,
  471. customXcodeFlags, plistPreprocessorDefinitions, codeSignIdentity,
  472. fastMathEnabled, stripLocalSymbolsEnabled, pluginBinaryCopyStepEnabled,
  473. vstBinaryLocation, vst3BinaryLocation, auBinaryLocation, rtasBinaryLocation,
  474. aaxBinaryLocation, unityPluginBinaryLocation;
  475. //==========================================================================
  476. void addXcodePluginInstallPathProperties (PropertyListBuilder& props)
  477. {
  478. auto isBuildingAnyPlugins = (project.shouldBuildVST() || project.shouldBuildVST3() || project.shouldBuildAU()
  479. || project.shouldBuildRTAS() || project.shouldBuildAAX());
  480. if (isBuildingAnyPlugins)
  481. props.add (new ChoicePropertyComponent (pluginBinaryCopyStepEnabled, "Enable Plugin Copy Step"),
  482. "Enable this to copy plugin binaries to the specified folder after building.");
  483. if (project.shouldBuildVST3())
  484. props.add (new TextPropertyComponentWithEnablement (vst3BinaryLocation, pluginBinaryCopyStepEnabled, "VST3 Binary Location",
  485. 1024, false),
  486. "The folder in which the compiled VST3 binary should be placed.");
  487. if (project.shouldBuildAU())
  488. props.add (new TextPropertyComponentWithEnablement (auBinaryLocation, pluginBinaryCopyStepEnabled, "AU Binary Location",
  489. 1024, false),
  490. "The folder in which the compiled AU binary should be placed.");
  491. if (project.shouldBuildRTAS())
  492. props.add (new TextPropertyComponentWithEnablement (rtasBinaryLocation, pluginBinaryCopyStepEnabled, "RTAS Binary Location",
  493. 1024, false),
  494. "The folder in which the compiled RTAS binary should be placed.");
  495. if (project.shouldBuildAAX())
  496. props.add (new TextPropertyComponentWithEnablement (aaxBinaryLocation, pluginBinaryCopyStepEnabled, "AAX Binary Location",
  497. 1024, false),
  498. "The folder in which the compiled AAX binary should be placed.");
  499. if (project.shouldBuildUnityPlugin())
  500. props.add (new TextPropertyComponentWithEnablement (unityPluginBinaryLocation, pluginBinaryCopyStepEnabled, "Unity Binary Location",
  501. 1024, false),
  502. "The folder in which the compiled Unity plugin binary and associated C# GUI script should be placed.");
  503. if (project.shouldBuildVST())
  504. props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepEnabled, "VST Binary Location",
  505. 1024, false),
  506. "The folder in which the compiled legacy VST binary should be placed.");
  507. }
  508. void updateOldPluginBinaryLocations()
  509. {
  510. if (! config ["xcodeVstBinaryLocation"].isVoid()) vstBinaryLocation = config ["xcodeVstBinaryLocation"];
  511. if (! config ["xcodeVst3BinaryLocation"].isVoid()) vst3BinaryLocation = config ["xcodeVst3BinaryLocation"];
  512. if (! config ["xcodeAudioUnitBinaryLocation"].isVoid()) auBinaryLocation = config ["xcodeAudioUnitBinaryLocation"];
  513. if (! config ["xcodeRtasBinaryLocation"].isVoid()) rtasBinaryLocation = config ["xcodeRtasBinaryLocation"];
  514. if (! config ["xcodeAaxBinaryLocation"].isVoid()) aaxBinaryLocation = config ["xcodeAaxBinaryLocation"];
  515. }
  516. void updateOldSDKDefaults()
  517. {
  518. if (iosDeploymentTarget.get() == "default") iosDeploymentTarget.resetToDefault();
  519. if (osxArchitecture.get() == "default") osxArchitecture.resetToDefault();
  520. if (osxSDKVersion.get() == "default") osxSDKVersion.resetToDefault();
  521. if (osxDeploymentTarget.get() == "default") osxDeploymentTarget.resetToDefault();
  522. }
  523. };
  524. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  525. {
  526. return *new XcodeBuildConfiguration (project, v, iOS, *this);
  527. }
  528. public:
  529. //==============================================================================
  530. /* The numbers for these enum values are defined by Xcode for the different
  531. possible destinations of a "copy files" post-build step.
  532. */
  533. enum XcodeCopyFilesDestinationIDs
  534. {
  535. kWrapperFolder = 1,
  536. kExecutablesFolder = 6,
  537. kResourcesFolder = 7,
  538. kFrameworksFolder = 10,
  539. kSharedFrameworksFolder = 11,
  540. kSharedSupportFolder = 12,
  541. kPluginsFolder = 13,
  542. kJavaResourcesFolder = 15,
  543. kXPCServicesFolder = 16
  544. };
  545. //==============================================================================
  546. struct XcodeTarget : ProjectType::Target
  547. {
  548. //==============================================================================
  549. XcodeTarget (ProjectType::Target::Type targetType, const XcodeProjectExporter& exporter)
  550. : ProjectType::Target (targetType),
  551. owner (exporter)
  552. {
  553. switch (type)
  554. {
  555. case GUIApp:
  556. xcodePackageType = "APPL";
  557. xcodeBundleSignature = "????";
  558. xcodeFileType = "wrapper.application";
  559. xcodeBundleExtension = ".app";
  560. xcodeProductType = "com.apple.product-type.application";
  561. xcodeCopyToProductInstallPathAfterBuild = false;
  562. break;
  563. case ConsoleApp:
  564. xcodeFileType = "compiled.mach-o.executable";
  565. xcodeBundleExtension = String();
  566. xcodeProductType = "com.apple.product-type.tool";
  567. xcodeCopyToProductInstallPathAfterBuild = false;
  568. break;
  569. case StaticLibrary:
  570. xcodeFileType = "archive.ar";
  571. xcodeBundleExtension = ".a";
  572. xcodeProductType = "com.apple.product-type.library.static";
  573. xcodeCopyToProductInstallPathAfterBuild = false;
  574. break;
  575. case DynamicLibrary:
  576. xcodeFileType = "compiled.mach-o.dylib";
  577. xcodeProductType = "com.apple.product-type.library.dynamic";
  578. xcodeBundleExtension = ".dylib";
  579. xcodeCopyToProductInstallPathAfterBuild = false;
  580. break;
  581. case VSTPlugIn:
  582. xcodePackageType = "BNDL";
  583. xcodeBundleSignature = "????";
  584. xcodeFileType = "wrapper.cfbundle";
  585. xcodeBundleExtension = ".vst";
  586. xcodeProductType = "com.apple.product-type.bundle";
  587. xcodeCopyToProductInstallPathAfterBuild = true;
  588. break;
  589. case VST3PlugIn:
  590. xcodePackageType = "BNDL";
  591. xcodeBundleSignature = "????";
  592. xcodeFileType = "wrapper.cfbundle";
  593. xcodeBundleExtension = ".vst3";
  594. xcodeProductType = "com.apple.product-type.bundle";
  595. xcodeCopyToProductInstallPathAfterBuild = true;
  596. break;
  597. case AudioUnitPlugIn:
  598. xcodePackageType = "BNDL";
  599. xcodeBundleSignature = "????";
  600. xcodeFileType = "wrapper.cfbundle";
  601. xcodeBundleExtension = ".component";
  602. xcodeProductType = "com.apple.product-type.bundle";
  603. xcodeCopyToProductInstallPathAfterBuild = true;
  604. addExtraAudioUnitTargetSettings();
  605. break;
  606. case StandalonePlugIn:
  607. xcodePackageType = "APPL";
  608. xcodeBundleSignature = "????";
  609. xcodeFileType = "wrapper.application";
  610. xcodeBundleExtension = ".app";
  611. xcodeProductType = "com.apple.product-type.application";
  612. xcodeCopyToProductInstallPathAfterBuild = false;
  613. break;
  614. case AudioUnitv3PlugIn:
  615. xcodePackageType = "XPC!";
  616. xcodeBundleSignature = "????";
  617. xcodeFileType = "wrapper.app-extension";
  618. xcodeBundleExtension = ".appex";
  619. xcodeBundleIDSubPath = "AUv3";
  620. xcodeProductType = "com.apple.product-type.app-extension";
  621. xcodeCopyToProductInstallPathAfterBuild = false;
  622. addExtraAudioUnitv3PlugInTargetSettings();
  623. break;
  624. case AAXPlugIn:
  625. xcodePackageType = "TDMw";
  626. xcodeBundleSignature = "PTul";
  627. xcodeFileType = "wrapper.cfbundle";
  628. xcodeBundleExtension = ".aaxplugin";
  629. xcodeProductType = "com.apple.product-type.bundle";
  630. xcodeCopyToProductInstallPathAfterBuild = true;
  631. break;
  632. case RTASPlugIn:
  633. xcodePackageType = "TDMw";
  634. xcodeBundleSignature = "PTul";
  635. xcodeFileType = "wrapper.cfbundle";
  636. xcodeBundleExtension = ".dpm";
  637. xcodeProductType = "com.apple.product-type.bundle";
  638. xcodeCopyToProductInstallPathAfterBuild = true;
  639. break;
  640. case UnityPlugIn:
  641. xcodePackageType = "BNDL";
  642. xcodeBundleSignature = "????";
  643. xcodeFileType = "wrapper.cfbundle";
  644. xcodeBundleExtension = ".bundle";
  645. xcodeProductType = "com.apple.product-type.bundle";
  646. xcodeCopyToProductInstallPathAfterBuild = true;
  647. break;
  648. case SharedCodeTarget:
  649. xcodeFileType = "archive.ar";
  650. xcodeBundleExtension = ".a";
  651. xcodeProductType = "com.apple.product-type.library.static";
  652. xcodeCopyToProductInstallPathAfterBuild = false;
  653. break;
  654. case AggregateTarget:
  655. xcodeCopyToProductInstallPathAfterBuild = false;
  656. break;
  657. default:
  658. // unknown target type!
  659. jassertfalse;
  660. break;
  661. }
  662. }
  663. String getXcodeSchemeName() const
  664. {
  665. return owner.projectName + " - " + getName();
  666. }
  667. String getID() const
  668. {
  669. return owner.createID (String ("__target") + getName());
  670. }
  671. String getInfoPlistName() const
  672. {
  673. return String ("Info-") + String (getName()).replace (" ", "_") + String (".plist");
  674. }
  675. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  676. String xcodeProductType, xcodeFileType;
  677. String xcodeOtherRezFlags, xcodeBundleIDSubPath;
  678. bool xcodeCopyToProductInstallPathAfterBuild;
  679. StringArray xcodeFrameworks, xcodeLibs;
  680. Array<XmlElement> xcodeExtraPListEntries;
  681. StringArray frameworkIDs, buildPhaseIDs, configIDs, sourceIDs, rezFileIDs;
  682. StringArray frameworkNames;
  683. String dependencyID, mainBuildProductID;
  684. File infoPlistFile;
  685. struct SourceFileInfo
  686. {
  687. RelativePath path;
  688. bool shouldBeCompiled = false;
  689. };
  690. Array<SourceFileInfo> getSourceFilesInfo (const Project::Item& projectItem) const
  691. {
  692. Array<SourceFileInfo> result;
  693. auto targetType = (owner.getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  694. if (projectItem.isGroup())
  695. {
  696. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  697. result.addArray (getSourceFilesInfo (projectItem.getChild (i)));
  698. }
  699. else if (projectItem.shouldBeAddedToTargetProject()
  700. && owner.getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  701. {
  702. SourceFileInfo info;
  703. info.path = RelativePath (projectItem.getFile(), owner.getTargetFolder(), RelativePath::buildTargetFolder);
  704. jassert (info.path.getRoot() == RelativePath::buildTargetFolder);
  705. if (targetType == SharedCodeTarget || projectItem.shouldBeCompiled())
  706. info.shouldBeCompiled = projectItem.shouldBeCompiled();
  707. result.add (info);
  708. }
  709. return result;
  710. }
  711. //==============================================================================
  712. void addMainBuildProduct() const
  713. {
  714. jassert (xcodeFileType.isNotEmpty());
  715. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar ('.'));
  716. if (ProjectExporter::BuildConfiguration::Ptr config = owner.getConfiguration(0))
  717. {
  718. auto productName = owner.replacePreprocessorTokens (*config, config->getTargetBinaryNameString (type == UnityPlugIn));
  719. if (xcodeFileType == "archive.ar")
  720. productName = getStaticLibbedFilename (productName);
  721. else
  722. productName += xcodeBundleExtension;
  723. addBuildProduct (xcodeFileType, productName);
  724. }
  725. }
  726. //==============================================================================
  727. void addBuildProduct (const String& fileType, const String& binaryName) const
  728. {
  729. auto* v = new ValueTree (owner.createID (String ("__productFileID") + getName()));
  730. v->setProperty ("isa", "PBXFileReference", nullptr);
  731. v->setProperty ("explicitFileType", fileType, nullptr);
  732. v->setProperty ("includeInIndex", (int) 0, nullptr);
  733. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  734. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  735. owner.pbxFileReferences.add (v);
  736. }
  737. //==============================================================================
  738. void addDependency()
  739. {
  740. jassert (dependencyID.isEmpty());
  741. dependencyID = owner.createID (String ("__dependency") + getName());
  742. auto* v = new ValueTree (dependencyID);
  743. v->setProperty ("isa", "PBXTargetDependency", nullptr);
  744. v->setProperty ("target", getID(), nullptr);
  745. owner.misc.add (v);
  746. }
  747. String getDependencyID() const
  748. {
  749. jassert (dependencyID.isNotEmpty());
  750. return dependencyID;
  751. }
  752. //==============================================================================
  753. void addTargetConfig (const String& configName, const StringArray& buildSettings)
  754. {
  755. auto configID = owner.createID (String ("targetconfigid_") + getName() + String ("_") + configName);
  756. auto* v = new ValueTree (configID);
  757. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  758. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  759. v->setProperty (Ids::name, configName, nullptr);
  760. configIDs.add (configID);
  761. owner.targetConfigs.add (v);
  762. }
  763. //==============================================================================
  764. String getTargetAttributes() const
  765. {
  766. auto attributes = getID() + " = { ";
  767. auto developmentTeamID = owner.getIosDevelopmentTeamIDString();
  768. if (developmentTeamID.isNotEmpty())
  769. {
  770. attributes << "DevelopmentTeam = " << developmentTeamID << "; ";
  771. attributes << "ProvisioningStyle = Automatic; ";
  772. }
  773. auto appGroupsEnabled = (owner.iOS && owner.isAppGroupsEnabled() ? 1 : 0);
  774. auto inAppPurchasesEnabled = owner.isInAppPurchasesEnabled() ? 1 : 0;
  775. auto interAppAudioEnabled = (owner.iOS
  776. && type == Target::StandalonePlugIn
  777. && owner.getProject().shouldEnableIAA()) ? 1 : 0;
  778. auto pushNotificationsEnabled = owner.isPushNotificationsEnabled() ? 1 : 0;
  779. auto sandboxEnabled = (type == Target::AudioUnitv3PlugIn ? 1 : 0);
  780. attributes << "SystemCapabilities = {";
  781. attributes << "com.apple.ApplicationGroups.iOS = { enabled = " << appGroupsEnabled << "; }; ";
  782. attributes << "com.apple.InAppPurchase = { enabled = " << inAppPurchasesEnabled << "; }; ";
  783. attributes << "com.apple.InterAppAudio = { enabled = " << interAppAudioEnabled << "; }; ";
  784. attributes << "com.apple.Push = { enabled = " << pushNotificationsEnabled << "; }; ";
  785. attributes << "com.apple.Sandbox = { enabled = " << sandboxEnabled << "; }; ";
  786. if (owner.iOS && owner.isiCloudPermissionsEnabled())
  787. attributes << "com.apple.iCloud = { enabled = 1; }; ";
  788. attributes << "}; };";
  789. return attributes;
  790. }
  791. //==============================================================================
  792. ValueTree& addBuildPhase (const String& buildPhaseType, const StringArray& fileIds, const StringRef humanReadableName = StringRef())
  793. {
  794. auto buildPhaseName = buildPhaseType + "_" + getName() + "_" + (humanReadableName.isNotEmpty() ? String (humanReadableName) : String ("resbuildphase"));
  795. auto buildPhaseId (owner.createID (buildPhaseName));
  796. int n = 0;
  797. while (buildPhaseIDs.contains (buildPhaseId))
  798. buildPhaseId = owner.createID (buildPhaseName + String (++n));
  799. buildPhaseIDs.add (buildPhaseId);
  800. auto* v = new ValueTree (buildPhaseId);
  801. v->setProperty ("isa", buildPhaseType, nullptr);
  802. v->setProperty ("buildActionMask", "2147483647", nullptr);
  803. v->setProperty ("files", indentParenthesisedList (fileIds), nullptr);
  804. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  805. if (humanReadableName.isNotEmpty())
  806. v->setProperty ("name", String (humanReadableName), nullptr);
  807. owner.misc.add (v);
  808. return *v;
  809. }
  810. bool shouldCreatePList() const
  811. {
  812. auto fileType = getTargetFileType();
  813. return (fileType == executable && type != ConsoleApp) || fileType == pluginBundle || fileType == macOSAppex;
  814. }
  815. //==============================================================================
  816. bool shouldAddEntitlements() const
  817. {
  818. if (owner.isPushNotificationsEnabled() || owner.isAppGroupsEnabled() || (owner.isiOS() && owner.isiCloudPermissionsEnabled()))
  819. return true;
  820. if (owner.project.getProjectType().isAudioPlugin()
  821. && ( (owner.isOSX() && type == Target::AudioUnitv3PlugIn)
  822. || (owner.isiOS() && type == Target::StandalonePlugIn && owner.getProject().shouldEnableIAA())))
  823. return true;
  824. return false;
  825. }
  826. String getBundleIdentifier() const
  827. {
  828. auto bundleIdentifier = owner.project.getBundleIdentifierString();
  829. if (xcodeBundleIDSubPath.isNotEmpty())
  830. {
  831. auto bundleIdSegments = StringArray::fromTokens (bundleIdentifier, ".", StringRef());
  832. jassert (bundleIdSegments.size() > 0);
  833. bundleIdentifier += String (".") + bundleIdSegments[bundleIdSegments.size() - 1] + xcodeBundleIDSubPath;
  834. }
  835. return bundleIdentifier;
  836. }
  837. //==============================================================================
  838. StringPairArray getTargetSettings (const XcodeBuildConfiguration& config) const
  839. {
  840. StringPairArray s;
  841. if (type == AggregateTarget && ! owner.isiOS())
  842. {
  843. // the aggregate target needs to have the deployment target set for
  844. // pre-/post-build scripts
  845. String sdkRoot;
  846. s.set ("MACOSX_DEPLOYMENT_TARGET", getOSXDeploymentTarget (config, &sdkRoot));
  847. if (sdkRoot.isNotEmpty())
  848. s.set ("SDKROOT", sdkRoot);
  849. return s;
  850. }
  851. s.set ("PRODUCT_NAME", owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString (type == UnityPlugIn)).quoted());
  852. s.set ("PRODUCT_BUNDLE_IDENTIFIER", getBundleIdentifier());
  853. auto arch = (! owner.isiOS() && type == Target::AudioUnitv3PlugIn) ? osxArch_64Bit
  854. : config.getOSXArchitectureString();
  855. if (arch == osxArch_Native) s.set ("ARCHS", "\"$(NATIVE_ARCH_ACTUAL)\"");
  856. else if (arch == osxArch_32BitUniversal) s.set ("ARCHS", "\"$(ARCHS_STANDARD_32_BIT)\"");
  857. else if (arch == osxArch_64BitUniversal) s.set ("ARCHS", "\"$(ARCHS_STANDARD_32_64_BIT)\"");
  858. else if (arch == osxArch_64Bit) s.set ("ARCHS", "\"$(ARCHS_STANDARD_64_BIT)\"");
  859. StringArray headerPaths (getHeaderSearchPaths (config));
  860. headerPaths.add ("\"$(inherited)\"");
  861. s.set ("HEADER_SEARCH_PATHS", indentParenthesisedList (headerPaths, 1));
  862. s.set ("USE_HEADERMAP", String (static_cast<bool> (config.exporter.settings.getProperty ("useHeaderMap")) ? "YES" : "NO"));
  863. auto frameworkSearchPaths = getFrameworkSearchPaths (config);
  864. if (! frameworkSearchPaths.isEmpty())
  865. s.set ("FRAMEWORK_SEARCH_PATHS", String ("(") + frameworkSearchPaths.joinIntoString (", ") + ", \"$(inherited)\")");
  866. s.set ("GCC_OPTIMIZATION_LEVEL", config.getGCCOptimisationFlag());
  867. if (shouldCreatePList())
  868. {
  869. s.set ("INFOPLIST_FILE", infoPlistFile.getFileName());
  870. if (owner.getPListPrefixHeaderString().isNotEmpty())
  871. s.set ("INFOPLIST_PREFIX_HEADER", owner.getPListPrefixHeaderString());
  872. s.set ("INFOPLIST_PREPROCESS", (owner.isPListPreprocessEnabled() ? String ("YES") : String ("NO")));
  873. auto plistDefs = parsePreprocessorDefs (config.getPListPreprocessorDefinitionsString());
  874. StringArray defsList;
  875. for (int i = 0; i < plistDefs.size(); ++i)
  876. {
  877. auto def = plistDefs.getAllKeys()[i];
  878. auto value = plistDefs.getAllValues()[i];
  879. if (value.isNotEmpty())
  880. def << "=" << value.replace ("\"", "\\\\\\\"");
  881. defsList.add ("\"" + def + "\"");
  882. }
  883. if (defsList.size() > 0)
  884. s.set ("INFOPLIST_PREPROCESSOR_DEFINITIONS", indentParenthesisedList (defsList, 1));
  885. }
  886. if (config.isLinkTimeOptimisationEnabled())
  887. s.set ("LLVM_LTO", "YES");
  888. if (config.isFastMathEnabled())
  889. s.set ("GCC_FAST_MATH", "YES");
  890. auto extraFlags = owner.replacePreprocessorTokens (config, owner.getExtraCompilerFlagsString()).trim();
  891. if (extraFlags.isNotEmpty())
  892. s.set ("OTHER_CPLUSPLUSFLAGS", extraFlags.quoted());
  893. auto installPath = getInstallPathForConfiguration (config);
  894. if (installPath.startsWith ("~"))
  895. installPath = installPath.replace ("~", "$(HOME)");
  896. if (installPath.isNotEmpty())
  897. {
  898. s.set ("INSTALL_PATH", installPath.quoted());
  899. if (type == Target::SharedCodeTarget)
  900. s.set ("SKIP_INSTALL", "YES");
  901. if (! owner.embeddedFrameworkIDs.isEmpty())
  902. s.set ("LD_RUNPATH_SEARCH_PATHS", "\"$(inherited) @executable_path/Frameworks @executable_path/../Frameworks\"");
  903. if (xcodeCopyToProductInstallPathAfterBuild)
  904. {
  905. s.set ("DEPLOYMENT_LOCATION", "YES");
  906. s.set ("DSTROOT", "/");
  907. }
  908. }
  909. if (getTargetFileType() == pluginBundle)
  910. {
  911. s.set ("LIBRARY_STYLE", "Bundle");
  912. s.set ("WRAPPER_EXTENSION", xcodeBundleExtension.substring (1));
  913. s.set ("GENERATE_PKGINFO_FILE", "YES");
  914. }
  915. if (xcodeOtherRezFlags.isNotEmpty())
  916. s.set ("OTHER_REZFLAGS", "\"" + xcodeOtherRezFlags + "\"");
  917. String configurationBuildDir ("$(PROJECT_DIR)/build/$(CONFIGURATION)");
  918. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  919. {
  920. // a target's position can either be defined via installPath + xcodeCopyToProductInstallPathAfterBuild
  921. // (= for audio plug-ins) or using a custom binary path (for everything else), but not both (= conflict!)
  922. jassert (! xcodeCopyToProductInstallPathAfterBuild);
  923. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  924. configurationBuildDir = sanitisePath (binaryPath.rebased (owner.projectFolder, owner.getTargetFolder(), RelativePath::buildTargetFolder)
  925. .toUnixStyle());
  926. }
  927. s.set ("CONFIGURATION_BUILD_DIR", addQuotesIfRequired (configurationBuildDir));
  928. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  929. if (owner.iOS)
  930. {
  931. s.set ("ASSETCATALOG_COMPILER_APPICON_NAME", "AppIcon");
  932. s.set ("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME", "LaunchImage");
  933. }
  934. else
  935. {
  936. String sdkRoot;
  937. s.set ("MACOSX_DEPLOYMENT_TARGET", getOSXDeploymentTarget (config, &sdkRoot));
  938. if (sdkRoot.isNotEmpty())
  939. s.set ("SDKROOT", sdkRoot);
  940. s.set ("MACOSX_DEPLOYMENT_TARGET_ppc", "10.4");
  941. s.set ("SDKROOT_ppc", "macosx10.5");
  942. }
  943. s.set ("GCC_VERSION", gccVersion);
  944. s.set ("CLANG_LINK_OBJC_RUNTIME", "NO");
  945. if (isUsingCodeSigning (config))
  946. {
  947. s.set (owner.iOS ? "\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\"" : "CODE_SIGN_IDENTITY",
  948. config.getCodeSignIdentityString().quoted());
  949. s.set ("PROVISIONING_PROFILE_SPECIFIER", "\"\"");
  950. }
  951. if (owner.getIosDevelopmentTeamIDString().isNotEmpty())
  952. s.set ("DEVELOPMENT_TEAM", owner.getIosDevelopmentTeamIDString());
  953. if (shouldAddEntitlements())
  954. s.set ("CODE_SIGN_ENTITLEMENTS", owner.getEntitlementsFileName().quoted());
  955. {
  956. auto cppStandard = owner.project.getCppStandardString();
  957. if (cppStandard == "latest")
  958. cppStandard = "17";
  959. s.set ("CLANG_CXX_LANGUAGE_STANDARD", (String (owner.shouldUseGNUExtensions() ? "gnu++"
  960. : "c++") + cppStandard).quoted());
  961. }
  962. s.set ("CLANG_CXX_LIBRARY", "\"libc++\"");
  963. s.set ("COMBINE_HIDPI_IMAGES", "YES");
  964. {
  965. StringArray linkerFlags, librarySearchPaths;
  966. getLinkerSettings (config, linkerFlags, librarySearchPaths);
  967. if (linkerFlags.size() > 0)
  968. s.set ("OTHER_LDFLAGS", linkerFlags.joinIntoString (" ").quoted());
  969. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  970. librarySearchPaths = getCleanedStringArray (librarySearchPaths);
  971. if (librarySearchPaths.size() > 0)
  972. {
  973. StringArray libPaths;
  974. libPaths.add ("\"$(inherited)\"");
  975. for (auto& p : librarySearchPaths)
  976. libPaths.add ("\"\\\"" + p + "\\\"\"");
  977. s.set ("LIBRARY_SEARCH_PATHS", indentParenthesisedList (libPaths, 1));
  978. }
  979. }
  980. StringPairArray defines;
  981. if (config.isDebug())
  982. {
  983. defines.set ("_DEBUG", "1");
  984. defines.set ("DEBUG", "1");
  985. s.set ("COPY_PHASE_STRIP", "NO");
  986. s.set ("GCC_DYNAMIC_NO_PIC", "NO");
  987. }
  988. else
  989. {
  990. defines.set ("_NDEBUG", "1");
  991. defines.set ("NDEBUG", "1");
  992. s.set ("GCC_GENERATE_DEBUGGING_SYMBOLS", "NO");
  993. s.set ("GCC_SYMBOLS_PRIVATE_EXTERN", "YES");
  994. s.set ("DEAD_CODE_STRIPPING", "YES");
  995. }
  996. if (type != Target::SharedCodeTarget && type != Target::StaticLibrary && type != Target::DynamicLibrary
  997. && config.isStripLocalSymbolsEnabled())
  998. {
  999. s.set ("STRIPFLAGS", "\"-x\"");
  1000. s.set ("DEPLOYMENT_POSTPROCESSING", "YES");
  1001. s.set ("SEPARATE_STRIP", "YES");
  1002. }
  1003. if (owner.isInAppPurchasesEnabled())
  1004. defines.set ("JUCE_IN_APP_PURCHASES", "1");
  1005. if (owner.isPushNotificationsEnabled())
  1006. defines.set ("JUCE_PUSH_NOTIFICATIONS", "1");
  1007. defines = mergePreprocessorDefs (defines, owner.getAllPreprocessorDefs (config, type));
  1008. StringArray defsList;
  1009. for (int i = 0; i < defines.size(); ++i)
  1010. {
  1011. auto def = defines.getAllKeys()[i];
  1012. auto value = defines.getAllValues()[i];
  1013. if (value.isNotEmpty())
  1014. def << "=" << value.replace ("\"", "\\\\\\\"");
  1015. defsList.add ("\"" + def + "\"");
  1016. }
  1017. s.set ("GCC_PREPROCESSOR_DEFINITIONS", indentParenthesisedList (defsList, 1));
  1018. StringArray customFlags;
  1019. customFlags.addTokens (config.getCustomXcodeFlagsString(), ",", "\"'");
  1020. customFlags.removeEmptyStrings();
  1021. for (auto flag : customFlags)
  1022. {
  1023. s.set (flag.upToFirstOccurrenceOf ("=", false, false).trim(),
  1024. flag.fromFirstOccurrenceOf ("=", false, false).trim().quoted());
  1025. }
  1026. return s;
  1027. }
  1028. String getInstallPathForConfiguration (const XcodeBuildConfiguration& config) const
  1029. {
  1030. switch (type)
  1031. {
  1032. case GUIApp: return "$(HOME)/Applications";
  1033. case ConsoleApp: return "/usr/bin";
  1034. case VSTPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getVSTBinaryLocationString() : String();
  1035. case VST3PlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getVST3BinaryLocationString() : String();
  1036. case AudioUnitPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getAUBinaryLocationString() : String();
  1037. case RTASPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getRTASBinaryLocationString() : String();
  1038. case AAXPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getAAXBinaryLocationString() : String();
  1039. case UnityPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getUnityPluginBinaryLocationString() : String();
  1040. case SharedCodeTarget: return owner.isiOS() ? "@executable_path/Frameworks" : "@executable_path/../Frameworks";
  1041. default: return {};
  1042. }
  1043. }
  1044. //==============================================================================
  1045. void getLinkerSettings (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  1046. {
  1047. if (getTargetFileType() == pluginBundle)
  1048. flags.add (owner.isiOS() ? "-bitcode_bundle" : "-bundle");
  1049. Array<RelativePath> extraLibs;
  1050. addExtraLibsForTargetType (config, extraLibs);
  1051. for (auto& lib : extraLibs)
  1052. {
  1053. flags.add (getLinkerFlagForLib (lib.getFileNameWithoutExtension()));
  1054. librarySearchPaths.add (owner.getSearchPathForStaticLibrary (lib));
  1055. }
  1056. if (owner.project.getProjectType().isAudioPlugin() && type != Target::SharedCodeTarget)
  1057. {
  1058. if (owner.getTargetOfType (Target::SharedCodeTarget) != nullptr)
  1059. {
  1060. auto productName = getStaticLibbedFilename (owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString()));
  1061. RelativePath sharedCodelib (productName, RelativePath::buildTargetFolder);
  1062. flags.add (getLinkerFlagForLib (sharedCodelib.getFileNameWithoutExtension()));
  1063. }
  1064. }
  1065. flags.add (owner.replacePreprocessorTokens (config, owner.getExtraLinkerFlagsString()));
  1066. flags.add (owner.getExternalLibraryFlags (config));
  1067. auto libs = owner.xcodeLibs;
  1068. libs.addArray (xcodeLibs);
  1069. for (auto& l : libs)
  1070. flags.add (getLinkerFlagForLib (l));
  1071. flags = getCleanedStringArray (flags);
  1072. }
  1073. //========================================================================== c
  1074. void writeInfoPlistFile() const
  1075. {
  1076. if (! shouldCreatePList())
  1077. return;
  1078. auto plist = parseXML (owner.getPListToMergeString());
  1079. if (plist == nullptr || ! plist->hasTagName ("plist"))
  1080. plist.reset (new XmlElement ("plist"));
  1081. auto* dict = plist->getChildByName ("dict");
  1082. if (dict == nullptr)
  1083. dict = plist->createNewChildElement ("dict");
  1084. if (owner.isMicrophonePermissionEnabled())
  1085. addPlistDictionaryKey (dict, "NSMicrophoneUsageDescription", owner.getMicrophonePermissionsTextString());
  1086. if (owner.isCameraPermissionEnabled())
  1087. addPlistDictionaryKey (dict, "NSCameraUsageDescription", owner.getCameraPermissionTextString());
  1088. if (owner.iOS)
  1089. {
  1090. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  1091. if (type != AudioUnitv3PlugIn)
  1092. addPlistDictionaryKeyBool (dict, "UIViewControllerBasedStatusBarAppearance", false);
  1093. }
  1094. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  1095. if (! owner.iOS) // (NB: on iOS this causes error ITMS-90032 during publishing)
  1096. addPlistDictionaryKey (dict, "CFBundleIconFile", owner.iconFile.exists() ? owner.iconFile.getFileName() : String());
  1097. addPlistDictionaryKey (dict, "CFBundleIdentifier", getBundleIdentifier());
  1098. addPlistDictionaryKey (dict, "CFBundleName", owner.projectName);
  1099. // needed by NSExtension on iOS
  1100. addPlistDictionaryKey (dict, "CFBundleDisplayName", owner.projectName);
  1101. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  1102. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  1103. addPlistDictionaryKey (dict, "CFBundleShortVersionString", owner.project.getVersionString());
  1104. addPlistDictionaryKey (dict, "CFBundleVersion", owner.project.getVersionString());
  1105. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", owner.project.getCompanyCopyrightString());
  1106. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  1107. auto documentExtensions = StringArray::fromTokens (replacePreprocessorDefs (owner.getAllPreprocessorDefs(), owner.settings ["documentExtensions"]),
  1108. ",", {});
  1109. documentExtensions.trim();
  1110. documentExtensions.removeEmptyStrings (true);
  1111. if (documentExtensions.size() > 0 && type != AudioUnitv3PlugIn)
  1112. {
  1113. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  1114. auto* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  1115. XmlElement* arrayTag = nullptr;
  1116. for (auto ex : documentExtensions)
  1117. {
  1118. if (ex.startsWithChar ('.'))
  1119. ex = ex.substring (1);
  1120. if (arrayTag == nullptr)
  1121. {
  1122. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  1123. arrayTag = dict2->createNewChildElement ("array");
  1124. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  1125. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  1126. addPlistDictionaryKey (dict2, "CFBundleTypeIconFile", "Icon");
  1127. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  1128. }
  1129. arrayTag->createNewChildElement ("string")->addTextElement (ex);
  1130. }
  1131. }
  1132. if (owner.isFileSharingEnabled() && type != AudioUnitv3PlugIn)
  1133. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  1134. if (owner.isDocumentBrowserEnabled())
  1135. addPlistDictionaryKeyBool (dict, "UISupportsDocumentBrowser", true);
  1136. if (owner.isStatusBarHidden() && type != AudioUnitv3PlugIn)
  1137. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  1138. if (owner.iOS)
  1139. {
  1140. if (type != AudioUnitv3PlugIn)
  1141. {
  1142. // Forcing full screen disables the split screen feature and prevents error ITMS-90475
  1143. addPlistDictionaryKeyBool (dict, "UIRequiresFullScreen", true);
  1144. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  1145. addIosScreenOrientations (dict);
  1146. addIosBackgroundModes (dict);
  1147. }
  1148. if (type == StandalonePlugIn && owner.getProject().shouldEnableIAA())
  1149. {
  1150. XmlElement audioComponentsPlistKey ("key");
  1151. audioComponentsPlistKey.addTextElement ("AudioComponents");
  1152. dict->addChildElement (new XmlElement (audioComponentsPlistKey));
  1153. XmlElement audioComponentsPlistEntry ("array");
  1154. auto* audioComponentsDict = audioComponentsPlistEntry.createNewChildElement ("dict");
  1155. addPlistDictionaryKey (audioComponentsDict, "name", owner.project.getIAAPluginName());
  1156. addPlistDictionaryKey (audioComponentsDict, "manufacturer", owner.project.getPluginManufacturerCodeString().substring (0, 4));
  1157. addPlistDictionaryKey (audioComponentsDict, "type", owner.project.getIAATypeCode());
  1158. addPlistDictionaryKey (audioComponentsDict, "subtype", owner.project.getPluginCodeString().substring (0, 4));
  1159. addPlistDictionaryKeyInt (audioComponentsDict, "version", owner.project.getVersionAsHexInteger());
  1160. dict->addChildElement (new XmlElement (audioComponentsPlistEntry));
  1161. }
  1162. }
  1163. for (auto& e : xcodeExtraPListEntries)
  1164. dict->addChildElement (new XmlElement (e));
  1165. MemoryOutputStream mo;
  1166. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1167. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  1168. }
  1169. //==============================================================================
  1170. void addIosScreenOrientations (XmlElement* dict) const
  1171. {
  1172. String screenOrientations[2] = { owner.getiPhoneScreenOrientationString(), owner.getiPadScreenOrientationString() };
  1173. String plistSuffix[2] = { "", "~ipad" };
  1174. auto orientationsAreTheSame = ( screenOrientations[0] == screenOrientations[1] );
  1175. for (int i = 0; i < (orientationsAreTheSame ? 1 : 2); ++i)
  1176. {
  1177. StringArray iOSOrientations;
  1178. if (screenOrientations[i].contains ("portrait")) { iOSOrientations.add ("UIInterfaceOrientationPortrait"); }
  1179. if (screenOrientations[i].contains ("landscape")) { iOSOrientations.add ("UIInterfaceOrientationLandscapeLeft"); iOSOrientations.add ("UIInterfaceOrientationLandscapeRight"); }
  1180. addArrayToPlist (dict, String ("UISupportedInterfaceOrientations") + plistSuffix[i], iOSOrientations);
  1181. }
  1182. }
  1183. //==============================================================================
  1184. void addIosBackgroundModes (XmlElement* dict) const
  1185. {
  1186. StringArray iosBackgroundModes;
  1187. if (owner.isBackgroundAudioEnabled()) iosBackgroundModes.add ("audio");
  1188. if (owner.isBackgroundBleEnabled()) iosBackgroundModes.add ("bluetooth-central");
  1189. if (owner.isPushNotificationsEnabled()) iosBackgroundModes.add ("remote-notification");
  1190. addArrayToPlist (dict, "UIBackgroundModes", iosBackgroundModes);
  1191. }
  1192. //==============================================================================
  1193. static void addArrayToPlist (XmlElement* dict, String arrayKey, const StringArray& arrayElements)
  1194. {
  1195. dict->createNewChildElement ("key")->addTextElement (arrayKey);
  1196. auto* plistStringArray = dict->createNewChildElement ("array");
  1197. for (auto& e : arrayElements)
  1198. plistStringArray->createNewChildElement ("string")->addTextElement (e);
  1199. }
  1200. //==============================================================================
  1201. void addShellScriptBuildPhase (const String& phaseName, const String& script)
  1202. {
  1203. if (script.trim().isNotEmpty())
  1204. {
  1205. auto& v = addBuildPhase ("PBXShellScriptBuildPhase", {});
  1206. v.setProperty (Ids::name, phaseName, nullptr);
  1207. v.setProperty ("shellPath", "/bin/sh", nullptr);
  1208. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  1209. .replace ("\"", "\\\"")
  1210. .replace ("\r\n", "\\n")
  1211. .replace ("\n", "\\n"), nullptr);
  1212. }
  1213. }
  1214. void addCopyFilesPhase (const String& phaseName, const StringArray& files, XcodeCopyFilesDestinationIDs dst)
  1215. {
  1216. auto& v = addBuildPhase ("PBXCopyFilesBuildPhase", files, phaseName);
  1217. v.setProperty ("dstPath", "", nullptr);
  1218. v.setProperty ("dstSubfolderSpec", (int) dst, nullptr);
  1219. }
  1220. //==============================================================================
  1221. void sanitiseAndEscapeSearchPaths (const BuildConfiguration& config, StringArray& paths) const
  1222. {
  1223. paths = getCleanedStringArray (paths);
  1224. for (auto& path : paths)
  1225. {
  1226. // Xcode 10 can't deal with search paths starting with "~" so we need to replace them here...
  1227. path = owner.replacePreprocessorTokens (config, sanitisePath (path));
  1228. if (path.containsChar (' '))
  1229. path = "\"\\\"" + path + "\\\"\""; // crazy double quotes required when there are spaces..
  1230. else
  1231. path = "\"" + path + "\"";
  1232. }
  1233. }
  1234. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1235. {
  1236. StringArray paths (owner.extraSearchPaths);
  1237. paths.addArray (config.getHeaderSearchPaths());
  1238. paths.addArray (getTargetExtraHeaderSearchPaths());
  1239. if (owner.project.getEnabledModules().isModuleEnabled ("juce_audio_plugin_client"))
  1240. {
  1241. // Needed to compile .r files
  1242. paths.add (owner.getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  1243. .rebased (owner.projectFolder, owner.getTargetFolder(), RelativePath::buildTargetFolder)
  1244. .toUnixStyle());
  1245. }
  1246. sanitiseAndEscapeSearchPaths (config, paths);
  1247. return paths;
  1248. }
  1249. StringArray getFrameworkSearchPaths (const BuildConfiguration& config) const
  1250. {
  1251. auto paths = getSearchPathsFromString (owner.getFrameworkSearchPathsString());
  1252. sanitiseAndEscapeSearchPaths (config, paths);
  1253. return paths;
  1254. }
  1255. private:
  1256. //==============================================================================
  1257. void addExtraAudioUnitTargetSettings()
  1258. {
  1259. xcodeOtherRezFlags = "-d ppc_$ppc -d i386_$i386 -d ppc64_$ppc64 -d x86_64_$x86_64"
  1260. " -I /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Versions/A/Headers"
  1261. " -I \\\"$(DEVELOPER_DIR)/Extras/CoreAudio/AudioUnits/AUPublic/AUBase\\\"";
  1262. xcodeFrameworks.addTokens ("AudioUnit CoreAudioKit", false);
  1263. XmlElement plistKey ("key");
  1264. plistKey.addTextElement ("AudioComponents");
  1265. XmlElement plistEntry ("array");
  1266. auto* dict = plistEntry.createNewChildElement ("dict");
  1267. auto pluginManufacturerCode = owner.project.getPluginManufacturerCodeString().substring (0, 4);
  1268. auto pluginSubType = owner.project.getPluginCodeString().substring (0, 4);
  1269. if (pluginManufacturerCode.toLowerCase() == pluginManufacturerCode)
  1270. {
  1271. throw SaveError ("AudioUnit plugin code identifiers invalid!\n\n"
  1272. "You have used only lower case letters in your AU plugin manufacturer identifier. "
  1273. "You must have at least one uppercase letter in your AU plugin manufacturer "
  1274. "identifier code.");
  1275. }
  1276. addPlistDictionaryKey (dict, "name", owner.project.getPluginManufacturerString()
  1277. + ": " + owner.project.getPluginNameString());
  1278. addPlistDictionaryKey (dict, "description", owner.project.getPluginDescriptionString());
  1279. addPlistDictionaryKey (dict, "factoryFunction", owner.project.getPluginAUExportPrefixString() + "Factory");
  1280. addPlistDictionaryKey (dict, "manufacturer", pluginManufacturerCode);
  1281. addPlistDictionaryKey (dict, "type", owner.project.getAUMainTypeString().removeCharacters ("'"));
  1282. addPlistDictionaryKey (dict, "subtype", pluginSubType);
  1283. addPlistDictionaryKeyInt (dict, "version", owner.project.getVersionAsHexInteger());
  1284. if (owner.project.isAUSandBoxSafe())
  1285. {
  1286. addPlistDictionaryKeyBool (dict, "sandboxSafe", true);
  1287. }
  1288. else
  1289. {
  1290. dict->createNewChildElement ("key")->addTextElement ("resourceUsage");
  1291. auto* resourceUsageDict = dict->createNewChildElement ("dict");
  1292. addPlistDictionaryKeyBool (resourceUsageDict, "network.client", true);
  1293. addPlistDictionaryKeyBool (resourceUsageDict, "temporary-exception.files.all.read-write", true);
  1294. }
  1295. xcodeExtraPListEntries.add (plistKey);
  1296. xcodeExtraPListEntries.add (plistEntry);
  1297. }
  1298. void addExtraAudioUnitv3PlugInTargetSettings()
  1299. {
  1300. if (owner.isiOS())
  1301. xcodeFrameworks.addTokens ("CoreAudioKit AVFoundation", false);
  1302. else
  1303. xcodeFrameworks.addTokens ("AudioUnit CoreAudioKit AVFoundation", false);
  1304. XmlElement plistKey ("key");
  1305. plistKey.addTextElement ("NSExtension");
  1306. XmlElement plistEntry ("dict");
  1307. addPlistDictionaryKey (&plistEntry, "NSExtensionPrincipalClass", owner.project.getPluginAUExportPrefixString() + "FactoryAUv3");
  1308. addPlistDictionaryKey (&plistEntry, "NSExtensionPointIdentifier", "com.apple.AudioUnit-UI");
  1309. plistEntry.createNewChildElement ("key")->addTextElement ("NSExtensionAttributes");
  1310. auto* dict = plistEntry.createNewChildElement ("dict");
  1311. dict->createNewChildElement ("key")->addTextElement ("AudioComponents");
  1312. auto* componentArray = dict->createNewChildElement ("array");
  1313. auto* componentDict = componentArray->createNewChildElement ("dict");
  1314. addPlistDictionaryKey (componentDict, "name", owner.project.getPluginManufacturerString()
  1315. + ": " + owner.project.getPluginNameString());
  1316. addPlistDictionaryKey (componentDict, "description", owner.project.getPluginDescriptionString());
  1317. addPlistDictionaryKey (componentDict, "factoryFunction",owner.project. getPluginAUExportPrefixString() + "FactoryAUv3");
  1318. addPlistDictionaryKey (componentDict, "manufacturer", owner.project.getPluginManufacturerCodeString().substring (0, 4));
  1319. addPlistDictionaryKey (componentDict, "type", owner.project.getAUMainTypeString().removeCharacters ("'"));
  1320. addPlistDictionaryKey (componentDict, "subtype", owner.project.getPluginCodeString().substring (0, 4));
  1321. addPlistDictionaryKeyInt (componentDict, "version", owner.project.getVersionAsHexInteger());
  1322. addPlistDictionaryKeyBool (componentDict, "sandboxSafe", true);
  1323. componentDict->createNewChildElement ("key")->addTextElement ("tags");
  1324. auto* tagsArray = componentDict->createNewChildElement ("array");
  1325. tagsArray->createNewChildElement ("string")
  1326. ->addTextElement (static_cast<bool> (owner.project.isPluginSynth()) ? "Synth" : "Effects");
  1327. xcodeExtraPListEntries.add (plistKey);
  1328. xcodeExtraPListEntries.add (plistEntry);
  1329. }
  1330. void addExtraLibsForTargetType (const BuildConfiguration& config, Array<RelativePath>& extraLibs) const
  1331. {
  1332. if (type == AAXPlugIn)
  1333. {
  1334. auto aaxLibsFolder = RelativePath (owner.getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  1335. String libraryPath (config.isDebug() ? "Debug" : "Release");
  1336. libraryPath += "/libAAXLibrary_libcpp.a";
  1337. extraLibs.add (aaxLibsFolder.getChildFile (libraryPath));
  1338. }
  1339. else if (type == RTASPlugIn)
  1340. {
  1341. RelativePath rtasFolder (owner.getRTASPathValue().toString(), RelativePath::projectFolder);
  1342. extraLibs.add (rtasFolder.getChildFile ("MacBag/Libs/Debug/libPluginLibrary.a"));
  1343. extraLibs.add (rtasFolder.getChildFile ("MacBag/Libs/Release/libPluginLibrary.a"));
  1344. }
  1345. }
  1346. StringArray getTargetExtraHeaderSearchPaths() const
  1347. {
  1348. StringArray targetExtraSearchPaths;
  1349. if (type == RTASPlugIn)
  1350. {
  1351. RelativePath rtasFolder (owner.getRTASPathValue().toString(), RelativePath::projectFolder);
  1352. targetExtraSearchPaths.add ("$(DEVELOPER_DIR)/Headers/FlatCarbon");
  1353. targetExtraSearchPaths.add ("$(SDKROOT)/Developer/Headers/FlatCarbon");
  1354. static const char* p[] = { "AlturaPorts/TDMPlugIns/PlugInLibrary/Controls",
  1355. "AlturaPorts/TDMPlugIns/PlugInLibrary/CoreClasses",
  1356. "AlturaPorts/TDMPlugIns/PlugInLibrary/DSPClasses",
  1357. "AlturaPorts/TDMPlugIns/PlugInLibrary/EffectClasses",
  1358. "AlturaPorts/TDMPlugIns/PlugInLibrary/MacBuild",
  1359. "AlturaPorts/TDMPlugIns/PlugInLibrary/Meters",
  1360. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses",
  1361. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses/Interfaces",
  1362. "AlturaPorts/TDMPlugIns/PlugInLibrary/RTASP_Adapt",
  1363. "AlturaPorts/TDMPlugIns/PlugInLibrary/Utilities",
  1364. "AlturaPorts/TDMPlugIns/PlugInLibrary/ViewClasses",
  1365. "AlturaPorts/TDMPlugIns/DSPManager/**",
  1366. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/Encryption",
  1367. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/GraphicsExtensions",
  1368. "AlturaPorts/TDMPlugIns/common/**",
  1369. "AlturaPorts/TDMPlugIns/common/PI_LibInterface",
  1370. "AlturaPorts/TDMPlugIns/PACEProtection/**",
  1371. "AlturaPorts/TDMPlugIns/SignalProcessing/**",
  1372. "AlturaPorts/OMS/Headers",
  1373. "AlturaPorts/Fic/Interfaces/**",
  1374. "AlturaPorts/Fic/Source/SignalNets",
  1375. "AlturaPorts/DSIPublicInterface/PublicHeaders",
  1376. "DAEWin/Include",
  1377. "AlturaPorts/DigiPublic/Interfaces",
  1378. "AlturaPorts/DigiPublic",
  1379. "AlturaPorts/NewFileLibs/DOA",
  1380. "AlturaPorts/NewFileLibs/Cmn",
  1381. "xplat/AVX/avx2/avx2sdk/inc",
  1382. "xplat/AVX/avx2/avx2sdk/utils" };
  1383. for (auto* path : p)
  1384. owner.addProjectPathToBuildPathList (targetExtraSearchPaths, rtasFolder.getChildFile (path));
  1385. }
  1386. return targetExtraSearchPaths;
  1387. }
  1388. String getOSXDeploymentTarget (const XcodeBuildConfiguration& config, String* sdkRoot = nullptr) const
  1389. {
  1390. auto sdk = config.getOSXSDKVersionString();
  1391. auto sdkCompat = config.getOSXDeploymentTargetString();
  1392. // The AUv3 target always needs to be at least 10.11
  1393. int oldestAllowedDeploymentTarget = (type == Target::AudioUnitv3PlugIn ? minimumAUv3SDKVersion
  1394. : oldestSDKVersion);
  1395. // if the user doesn't set it, then use the last known version that works well with JUCE
  1396. String deploymentTarget (osxVersionDefault);
  1397. for (int ver = oldestAllowedDeploymentTarget; ver <= currentSDKVersion; ++ver)
  1398. {
  1399. if (sdk.isNotEmpty() && (sdk == getSDKName (ver) && sdkRoot != nullptr)) *sdkRoot = String ("macosx10." + String (ver));
  1400. if (sdkCompat == getSDKName (ver)) deploymentTarget = "10." + String (ver);
  1401. }
  1402. return deploymentTarget;
  1403. }
  1404. bool isUsingCodeSigning (const XcodeBuildConfiguration& config) const
  1405. {
  1406. return (! config.isUsingDefaultCodeSignIdentity())
  1407. || owner.getIosDevelopmentTeamIDString().isNotEmpty();
  1408. }
  1409. //==============================================================================
  1410. const XcodeProjectExporter& owner;
  1411. Target& operator= (const Target&) = delete;
  1412. };
  1413. mutable StringArray xcodeFrameworks;
  1414. StringArray xcodeLibs;
  1415. private:
  1416. //==============================================================================
  1417. friend class CLionProjectExporter;
  1418. bool xcodeCanUseDwarf;
  1419. OwnedArray<XcodeTarget> targets;
  1420. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  1421. mutable StringArray resourceIDs, sourceIDs, targetIDs;
  1422. mutable StringArray frameworkFileIDs, embeddedFrameworkIDs, rezFileIDs, resourceFileRefs, subprojectFileIDs;
  1423. mutable Array<std::pair<String, String>> subprojectReferences;
  1424. mutable File menuNibFile, iconFile;
  1425. mutable StringArray buildProducts;
  1426. const bool iOS;
  1427. ValueWithDefault customPListValue, pListPrefixHeaderValue, pListPreprocessValue,
  1428. subprojectsValue,
  1429. extraFrameworksValue, frameworkSearchPathsValue, extraCustomFrameworksValue, embeddedFrameworksValue,
  1430. postbuildCommandValue, prebuildCommandValue,
  1431. duplicateAppExResourcesFolderValue, iosDeviceFamilyValue, iPhoneScreenOrientationValue,
  1432. iPadScreenOrientationValue, customXcodeResourceFoldersValue, customXcassetsFolderValue,
  1433. microphonePermissionNeededValue, microphonePermissionsTextValue, cameraPermissionNeededValue, cameraPermissionTextValue,
  1434. uiFileSharingEnabledValue, uiSupportsDocumentBrowserValue, uiStatusBarHiddenValue, documentExtensionsValue, iosInAppPurchasesValue,
  1435. iosBackgroundAudioValue, iosBackgroundBleValue, iosPushNotificationsValue, iosAppGroupsValue, iCloudPermissionsValue,
  1436. iosDevelopmentTeamIDValue, iosAppGroupsIDValue, keepCustomXcodeSchemesValue, useHeaderMapValue;
  1437. static String sanitisePath (const String& path)
  1438. {
  1439. if (path.startsWithChar ('~'))
  1440. return "$(HOME)" + path.substring (1);
  1441. return path;
  1442. }
  1443. static String addQuotesIfRequired (const String& s)
  1444. {
  1445. return s.containsAnyOf (" $") ? s.quoted() : s;
  1446. }
  1447. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRootString()).withFileExtension (".xcodeproj"); }
  1448. //==============================================================================
  1449. void createObjects() const
  1450. {
  1451. prepareTargets();
  1452. // Must be called before adding embedded frameworks, as we want to
  1453. // embed any frameworks found in subprojects.
  1454. addSubprojects();
  1455. addFrameworks();
  1456. addCustomFrameworks();
  1457. addEmbeddedFrameworks();
  1458. addCustomResourceFolders();
  1459. addPlistFileReferences();
  1460. if (iOS && ! projectType.isStaticLibrary())
  1461. addXcassets();
  1462. else
  1463. addNibFiles();
  1464. addIcons();
  1465. addBuildConfigurations();
  1466. addProjectConfigList (projectConfigs, createID ("__projList"));
  1467. {
  1468. StringArray topLevelGroupIDs;
  1469. addFilesAndGroupsToProject (topLevelGroupIDs);
  1470. addBuildPhases();
  1471. addExtraGroupsToProject (topLevelGroupIDs);
  1472. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  1473. }
  1474. addProjectObject();
  1475. removeMismatchedXcuserdata();
  1476. }
  1477. void prepareTargets() const
  1478. {
  1479. for (auto* target : targets)
  1480. {
  1481. if (target->type == XcodeTarget::AggregateTarget)
  1482. continue;
  1483. target->addMainBuildProduct();
  1484. auto targetName = target->getName();
  1485. auto fileID = createID (targetName + String ("__targetbuildref"));
  1486. auto fileRefID = createID (String ("__productFileID") + targetName);
  1487. auto* v = new ValueTree (fileID);
  1488. v->setProperty ("isa", "PBXBuildFile", nullptr);
  1489. v->setProperty ("fileRef", fileRefID, nullptr);
  1490. target->mainBuildProductID = fileID;
  1491. pbxBuildFiles.add (v);
  1492. target->addDependency();
  1493. }
  1494. }
  1495. void addPlistFileReferences() const
  1496. {
  1497. for (auto* target : targets)
  1498. {
  1499. if (target->type == XcodeTarget::AggregateTarget)
  1500. continue;
  1501. if (target->shouldCreatePList())
  1502. {
  1503. RelativePath plistPath (target->infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1504. addFileReference (plistPath.toUnixStyle());
  1505. resourceFileRefs.add (createFileRefID (plistPath));
  1506. }
  1507. }
  1508. }
  1509. void addNibFiles() const
  1510. {
  1511. MemoryOutputStream nib;
  1512. nib.write (BinaryData::RecentFilesMenuTemplate_nib, BinaryData::RecentFilesMenuTemplate_nibSize);
  1513. overwriteFileIfDifferentOrThrow (menuNibFile, nib);
  1514. RelativePath menuNibPath (menuNibFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1515. addFileReference (menuNibPath.toUnixStyle());
  1516. resourceIDs.add (addBuildFile (menuNibPath, false, false));
  1517. resourceFileRefs.add (createFileRefID (menuNibPath));
  1518. }
  1519. void addIcons() const
  1520. {
  1521. if (iconFile.exists())
  1522. {
  1523. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1524. addFileReference (iconPath.toUnixStyle());
  1525. resourceIDs.add (addBuildFile (iconPath, false, false));
  1526. resourceFileRefs.add (createFileRefID (iconPath));
  1527. }
  1528. }
  1529. void addBuildConfigurations() const
  1530. {
  1531. for (ConstConfigIterator config (*this); config.next();)
  1532. {
  1533. auto& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1534. StringArray settingsLines;
  1535. auto configSettings = getProjectSettings (xcodeConfig);
  1536. for (auto& key : configSettings.getAllKeys())
  1537. settingsLines.add (key + " = " + configSettings[key]);
  1538. addProjectConfig (config->getName(), settingsLines);
  1539. }
  1540. }
  1541. void addFilesAndGroupsToProject (StringArray& topLevelGroupIDs) const
  1542. {
  1543. auto entitlements = getEntitlements();
  1544. if (entitlements.size() > 0)
  1545. topLevelGroupIDs.add (addEntitlementsFile (entitlements));
  1546. for (auto& group : getAllGroups())
  1547. {
  1548. if (group.getNumChildren() > 0)
  1549. {
  1550. auto groupID = addProjectItem (group);
  1551. if (groupID.isNotEmpty())
  1552. topLevelGroupIDs.add (groupID);
  1553. }
  1554. }
  1555. }
  1556. void addExtraGroupsToProject (StringArray& topLevelGroupIDs) const
  1557. {
  1558. {
  1559. auto resourcesGroupID = createID ("__resources");
  1560. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  1561. topLevelGroupIDs.add (resourcesGroupID);
  1562. }
  1563. {
  1564. auto frameworksGroupID = createID ("__frameworks");
  1565. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  1566. topLevelGroupIDs.add (frameworksGroupID);
  1567. }
  1568. {
  1569. auto productsGroupID = createID ("__products");
  1570. addGroup (productsGroupID, "Products", buildProducts);
  1571. topLevelGroupIDs.add (productsGroupID);
  1572. }
  1573. if (! subprojectFileIDs.isEmpty())
  1574. {
  1575. auto subprojectLibrariesGroupID = createID ("__subprojects");
  1576. addGroup (subprojectLibrariesGroupID, "Subprojects", subprojectFileIDs);
  1577. topLevelGroupIDs.add (subprojectLibrariesGroupID);
  1578. }
  1579. }
  1580. void addBuildPhases() const
  1581. {
  1582. // add build phases
  1583. for (auto* target : targets)
  1584. {
  1585. if (target->type != XcodeTarget::AggregateTarget)
  1586. buildProducts.add (createID (String ("__productFileID") + String (target->getName())));
  1587. for (ConstConfigIterator config (*this); config.next();)
  1588. {
  1589. auto& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1590. auto configSettings = target->getTargetSettings (xcodeConfig);
  1591. StringArray settingsLines;
  1592. for (auto& key : configSettings.getAllKeys())
  1593. settingsLines.add (key + " = " + configSettings.getValue (key, "\"\""));
  1594. target->addTargetConfig (config->getName(), settingsLines);
  1595. }
  1596. addConfigList (*target, targetConfigs, createID (String ("__configList") + target->getName()));
  1597. target->addShellScriptBuildPhase ("Pre-build script", getPreBuildScript());
  1598. if (target->type != XcodeTarget::AggregateTarget)
  1599. {
  1600. auto skipAUv3 = (target->type == XcodeTarget::AudioUnitv3PlugIn && ! shouldDuplicateAppExResourcesFolder());
  1601. if (! projectType.isStaticLibrary() && target->type != XcodeTarget::SharedCodeTarget && ! skipAUv3)
  1602. target->addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  1603. auto rezFiles = rezFileIDs;
  1604. rezFiles.addArray (target->rezFileIDs);
  1605. if (rezFiles.size() > 0)
  1606. target->addBuildPhase ("PBXRezBuildPhase", rezFiles);
  1607. auto sourceFiles = target->sourceIDs;
  1608. if (target->type == XcodeTarget::SharedCodeTarget
  1609. || (! project.getProjectType().isAudioPlugin()))
  1610. sourceFiles.addArray (sourceIDs);
  1611. target->addBuildPhase ("PBXSourcesBuildPhase", sourceFiles);
  1612. if (! projectType.isStaticLibrary() && target->type != XcodeTarget::SharedCodeTarget)
  1613. target->addBuildPhase ("PBXFrameworksBuildPhase", target->frameworkIDs);
  1614. }
  1615. target->addShellScriptBuildPhase ("Post-build script", getPostBuildScript());
  1616. if (project.getProjectType().isAudioPlugin() && project.shouldBuildAUv3()
  1617. && project.shouldBuildStandalonePlugin() && target->type == XcodeTarget::StandalonePlugIn)
  1618. embedAppExtension();
  1619. if (project.getProjectType().isAudioPlugin() && project.shouldBuildUnityPlugin()
  1620. && target->type == XcodeTarget::UnityPlugIn)
  1621. embedUnityScript();
  1622. addTargetObject (*target);
  1623. }
  1624. }
  1625. void embedAppExtension() const
  1626. {
  1627. if (auto* standaloneTarget = getTargetOfType (XcodeTarget::StandalonePlugIn))
  1628. {
  1629. if (auto* auv3Target = getTargetOfType (XcodeTarget::AudioUnitv3PlugIn))
  1630. {
  1631. StringArray files;
  1632. files.add (auv3Target->mainBuildProductID);
  1633. standaloneTarget->addCopyFilesPhase ("Embed App Extensions", files, kPluginsFolder);
  1634. }
  1635. }
  1636. }
  1637. void embedUnityScript() const
  1638. {
  1639. if (auto* unityTarget = getTargetOfType (XcodeTarget::UnityPlugIn))
  1640. {
  1641. RelativePath scriptPath (getProject().getGeneratedCodeFolder().getChildFile (getProject().getUnityScriptName()),
  1642. getTargetFolder(),
  1643. RelativePath::buildTargetFolder);
  1644. auto path = scriptPath.toUnixStyle();
  1645. auto refID = addFileReference (path);
  1646. auto fileID = addBuildFile (path, refID, false, false);
  1647. resourceIDs.add (fileID);
  1648. resourceFileRefs.add (refID);
  1649. unityTarget->addCopyFilesPhase ("Embed Unity Script", fileID, kWrapperFolder);
  1650. }
  1651. }
  1652. static Image fixMacIconImageSize (Drawable& image)
  1653. {
  1654. const int validSizes[] = { 16, 32, 64, 128, 256, 512, 1024 };
  1655. auto w = image.getWidth();
  1656. auto h = image.getHeight();
  1657. int bestSize = 16;
  1658. for (int size : validSizes)
  1659. {
  1660. if (w == h && w == size)
  1661. {
  1662. bestSize = w;
  1663. break;
  1664. }
  1665. if (jmax (w, h) > size)
  1666. bestSize = size;
  1667. }
  1668. return rescaleImageForIcon (image, bestSize);
  1669. }
  1670. //==============================================================================
  1671. XcodeTarget* getTargetOfType (ProjectType::Target::Type type) const
  1672. {
  1673. for (auto& target : targets)
  1674. if (target->type == type)
  1675. return target;
  1676. return nullptr;
  1677. }
  1678. void addTargetObject (XcodeTarget& target) const
  1679. {
  1680. auto targetName = target.getName();
  1681. auto targetID = target.getID();
  1682. auto* v = new ValueTree (targetID);
  1683. v->setProperty ("isa", target.type == XcodeTarget::AggregateTarget ? "PBXAggregateTarget" : "PBXNativeTarget", nullptr);
  1684. v->setProperty ("buildConfigurationList", createID (String ("__configList") + targetName), nullptr);
  1685. v->setProperty ("buildPhases", indentParenthesisedList (target.buildPhaseIDs), nullptr);
  1686. v->setProperty ("buildRules", "( )", nullptr);
  1687. v->setProperty ("dependencies", indentParenthesisedList (getTargetDependencies (target)), nullptr);
  1688. v->setProperty (Ids::name, target.getXcodeSchemeName(), nullptr);
  1689. v->setProperty ("productName", projectName, nullptr);
  1690. if (target.type != XcodeTarget::AggregateTarget)
  1691. {
  1692. v->setProperty ("productReference", createID (String ("__productFileID") + targetName), nullptr);
  1693. jassert (target.xcodeProductType.isNotEmpty());
  1694. v->setProperty ("productType", target.xcodeProductType, nullptr);
  1695. }
  1696. targetIDs.add (targetID);
  1697. misc.add (v);
  1698. }
  1699. StringArray getTargetDependencies (const XcodeTarget& target) const
  1700. {
  1701. StringArray dependencies;
  1702. if (project.getProjectType().isAudioPlugin())
  1703. {
  1704. if (target.type == XcodeTarget::StandalonePlugIn) // depends on AUv3 and shared code
  1705. {
  1706. if (auto* auv3Target = getTargetOfType (XcodeTarget::AudioUnitv3PlugIn))
  1707. dependencies.add (auv3Target->getDependencyID());
  1708. if (auto* sharedCodeTarget = getTargetOfType (XcodeTarget::SharedCodeTarget))
  1709. dependencies.add (sharedCodeTarget->getDependencyID());
  1710. }
  1711. else if (target.type == XcodeTarget::AggregateTarget) // depends on all other targets
  1712. {
  1713. for (int i = 1; i < targets.size(); ++i)
  1714. dependencies.add (targets[i]->getDependencyID());
  1715. }
  1716. else if (target.type != XcodeTarget::SharedCodeTarget) // shared code doesn't depend on anything; all other targets depend only on the shared code
  1717. {
  1718. if (auto* sharedCodeTarget = getTargetOfType (XcodeTarget::SharedCodeTarget))
  1719. dependencies.add (sharedCodeTarget->getDependencyID());
  1720. }
  1721. }
  1722. return dependencies;
  1723. }
  1724. static void writeIconData (MemoryOutputStream& out, const Image& image, const char* type)
  1725. {
  1726. MemoryOutputStream pngData;
  1727. PNGImageFormat pngFormat;
  1728. pngFormat.writeImageToStream (image, pngData);
  1729. out.write (type, 4);
  1730. out.writeIntBigEndian (8 + (int) pngData.getDataSize());
  1731. out << pngData;
  1732. }
  1733. void writeIcnsFile (const OwnedArray<Drawable>& images, OutputStream& out) const
  1734. {
  1735. MemoryOutputStream data;
  1736. auto smallest = std::numeric_limits<int>::max();
  1737. Drawable* smallestImage = nullptr;
  1738. for (int i = 0; i < images.size(); ++i)
  1739. {
  1740. auto image = fixMacIconImageSize (*images.getUnchecked (i));
  1741. jassert (image.getWidth() == image.getHeight());
  1742. if (image.getWidth() < smallest)
  1743. {
  1744. smallest = image.getWidth();
  1745. smallestImage = images.getUnchecked(i);
  1746. }
  1747. switch (image.getWidth())
  1748. {
  1749. case 16: writeIconData (data, image, "icp4"); break;
  1750. case 32: writeIconData (data, image, "icp5"); break;
  1751. case 64: writeIconData (data, image, "icp6"); break;
  1752. case 128: writeIconData (data, image, "ic07"); break;
  1753. case 256: writeIconData (data, image, "ic08"); break;
  1754. case 512: writeIconData (data, image, "ic09"); break;
  1755. case 1024: writeIconData (data, image, "ic10"); break;
  1756. default: break;
  1757. }
  1758. }
  1759. jassert (data.getDataSize() > 0); // no suitable sized images?
  1760. // If you only supply a 1024 image, the file doesn't work on 10.8, so we need
  1761. // to force a smaller one in there too..
  1762. if (smallest > 512 && smallestImage != nullptr)
  1763. writeIconData (data, rescaleImageForIcon (*smallestImage, 512), "ic09");
  1764. out.write ("icns", 4);
  1765. out.writeIntBigEndian ((int) data.getDataSize() + 8);
  1766. out << data;
  1767. }
  1768. void getIconImages (OwnedArray<Drawable>& images) const
  1769. {
  1770. std::unique_ptr<Drawable> bigIcon (getBigIcon());
  1771. if (bigIcon != nullptr)
  1772. images.add (bigIcon.release());
  1773. std::unique_ptr<Drawable> smallIcon (getSmallIcon());
  1774. if (smallIcon != nullptr)
  1775. images.add (smallIcon.release());
  1776. }
  1777. void createiOSIconFiles (File appIconSet) const
  1778. {
  1779. OwnedArray<Drawable> images;
  1780. getIconImages (images);
  1781. if (images.size() > 0)
  1782. {
  1783. for (auto& type : getiOSAppIconTypes())
  1784. {
  1785. auto image = rescaleImageForIcon (*images.getFirst(), type.size);
  1786. if (image.hasAlphaChannel())
  1787. {
  1788. Image background (Image::RGB, image.getWidth(), image.getHeight(), false);
  1789. Graphics g (background);
  1790. g.fillAll (Colours::white);
  1791. g.drawImageWithin (image, 0, 0, image.getWidth(), image.getHeight(),
  1792. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize);
  1793. image = background;
  1794. }
  1795. MemoryOutputStream pngData;
  1796. PNGImageFormat pngFormat;
  1797. pngFormat.writeImageToStream (image, pngData);
  1798. overwriteFileIfDifferentOrThrow (appIconSet.getChildFile (type.filename), pngData);
  1799. }
  1800. }
  1801. }
  1802. void createIconFile() const
  1803. {
  1804. OwnedArray<Drawable> images;
  1805. getIconImages (images);
  1806. if (images.size() > 0)
  1807. {
  1808. MemoryOutputStream mo;
  1809. writeIcnsFile (images, mo);
  1810. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  1811. overwriteFileIfDifferentOrThrow (iconFile, mo);
  1812. }
  1813. }
  1814. void writeInfoPlistFiles() const
  1815. {
  1816. for (auto& target : targets)
  1817. target->writeInfoPlistFile();
  1818. }
  1819. // Delete .rsrc files in folder but don't follow sym-links
  1820. void deleteRsrcFiles (const File& folder) const
  1821. {
  1822. for (DirectoryIterator di (folder, false, "*", File::findFilesAndDirectories); di.next();)
  1823. {
  1824. auto& entry = di.getFile();
  1825. if (! entry.isSymbolicLink())
  1826. {
  1827. if (entry.existsAsFile() && entry.getFileExtension().toLowerCase() == ".rsrc")
  1828. entry.deleteFile();
  1829. else if (entry.isDirectory())
  1830. deleteRsrcFiles (entry);
  1831. }
  1832. }
  1833. }
  1834. static String getLinkerFlagForLib (String library)
  1835. {
  1836. if (library.substring (0, 3) == "lib")
  1837. library = library.substring (3);
  1838. return "-l" + library.replace (" ", "\\\\ ").upToLastOccurrenceOf (".", false, false);
  1839. }
  1840. String getSearchPathForStaticLibrary (const RelativePath& library) const
  1841. {
  1842. auto searchPath = library.toUnixStyle().upToLastOccurrenceOf ("/", false, false);
  1843. if (! library.isAbsolute())
  1844. {
  1845. auto srcRoot = rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle();
  1846. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  1847. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  1848. searchPath = srcRoot + searchPath;
  1849. }
  1850. return sanitisePath (searchPath);
  1851. }
  1852. StringPairArray getProjectSettings (const XcodeBuildConfiguration& config) const
  1853. {
  1854. StringPairArray s;
  1855. s.set ("ALWAYS_SEARCH_USER_PATHS", "NO");
  1856. s.set ("ENABLE_STRICT_OBJC_MSGSEND", "YES");
  1857. s.set ("GCC_C_LANGUAGE_STANDARD", "c11");
  1858. s.set ("GCC_NO_COMMON_BLOCKS", "YES");
  1859. s.set ("GCC_MODEL_TUNING", "G5");
  1860. s.set ("GCC_WARN_ABOUT_RETURN_TYPE", "YES");
  1861. s.set ("GCC_WARN_CHECK_SWITCH_STATEMENTS", "YES");
  1862. s.set ("GCC_WARN_UNUSED_VARIABLE", "YES");
  1863. s.set ("GCC_WARN_MISSING_PARENTHESES", "YES");
  1864. s.set ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR", "YES");
  1865. s.set ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF", "YES");
  1866. s.set ("GCC_WARN_64_TO_32_BIT_CONVERSION", "YES");
  1867. s.set ("GCC_WARN_UNDECLARED_SELECTOR", "YES");
  1868. s.set ("GCC_WARN_UNINITIALIZED_AUTOS", "YES");
  1869. s.set ("GCC_WARN_UNUSED_FUNCTION", "YES");
  1870. s.set ("CLANG_ENABLE_OBJC_WEAK", "YES");
  1871. s.set ("CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING", "YES");
  1872. s.set ("CLANG_WARN_BOOL_CONVERSION", "YES");
  1873. s.set ("CLANG_WARN_COMMA", "YES");
  1874. s.set ("CLANG_WARN_CONSTANT_CONVERSION", "YES");
  1875. s.set ("CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS", "YES");
  1876. s.set ("CLANG_WARN_EMPTY_BODY", "YES");
  1877. s.set ("CLANG_WARN_ENUM_CONVERSION", "YES");
  1878. s.set ("CLANG_WARN_INFINITE_RECURSION", "YES");
  1879. s.set ("CLANG_WARN_INT_CONVERSION", "YES");
  1880. s.set ("CLANG_WARN_NON_LITERAL_NULL_CONVERSION", "YES");
  1881. s.set ("CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF", "YES");
  1882. s.set ("CLANG_WARN_OBJC_LITERAL_CONVERSION", "YES");
  1883. s.set ("CLANG_WARN_RANGE_LOOP_ANALYSIS", "YES");
  1884. s.set ("CLANG_WARN_STRICT_PROTOTYPES", "YES");
  1885. s.set ("CLANG_WARN_SUSPICIOUS_MOVE", "YES");
  1886. s.set ("CLANG_WARN_UNREACHABLE_CODE", "YES");
  1887. s.set ("CLANG_WARN__DUPLICATE_METHOD_MATCH", "YES");
  1888. s.set ("WARNING_CFLAGS", "-Wreorder");
  1889. if (projectType.isStaticLibrary())
  1890. {
  1891. s.set ("GCC_INLINES_ARE_PRIVATE_EXTERN", "NO");
  1892. s.set ("GCC_SYMBOLS_PRIVATE_EXTERN", "NO");
  1893. }
  1894. else
  1895. {
  1896. s.set ("GCC_INLINES_ARE_PRIVATE_EXTERN", "YES");
  1897. }
  1898. if (config.isDebug())
  1899. {
  1900. s.set ("ENABLE_TESTABILITY", "YES");
  1901. if (config.getOSXArchitectureString() == osxArch_Default)
  1902. s.set ("ONLY_ACTIVE_ARCH", "YES");
  1903. }
  1904. if (iOS)
  1905. {
  1906. s.set ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\"", config.getCodeSignIdentityString().quoted());
  1907. s.set ("SDKROOT", "iphoneos");
  1908. s.set ("TARGETED_DEVICE_FAMILY", getDeviceFamilyString().quoted());
  1909. s.set ("IPHONEOS_DEPLOYMENT_TARGET", config.getiOSDeploymentTargetString());
  1910. }
  1911. else
  1912. {
  1913. if (! config.isUsingDefaultCodeSignIdentity() || getIosDevelopmentTeamIDString().isNotEmpty())
  1914. s.set ("CODE_SIGN_IDENTITY", config.getCodeSignIdentityString().quoted());
  1915. }
  1916. s.set ("ZERO_LINK", "NO");
  1917. if (xcodeCanUseDwarf)
  1918. s.set ("DEBUG_INFORMATION_FORMAT", "\"dwarf\"");
  1919. s.set ("PRODUCT_NAME", replacePreprocessorTokens (config, config.getTargetBinaryNameString()).quoted());
  1920. return s;
  1921. }
  1922. void addFrameworks() const
  1923. {
  1924. if (! projectType.isStaticLibrary())
  1925. {
  1926. if (isInAppPurchasesEnabled())
  1927. xcodeFrameworks.addIfNotAlreadyThere ("StoreKit");
  1928. if (iOS && isPushNotificationsEnabled())
  1929. xcodeFrameworks.addIfNotAlreadyThere ("UserNotifications");
  1930. if (isiOS() && project.getConfigFlag ("JUCE_USE_CAMERA").get())
  1931. xcodeFrameworks.addIfNotAlreadyThere ("ImageIO");
  1932. xcodeFrameworks.addTokens (getExtraFrameworksString(), ",;", "\"'");
  1933. xcodeFrameworks.trim();
  1934. auto s = xcodeFrameworks;
  1935. for (auto& target : targets)
  1936. s.addArray (target->xcodeFrameworks);
  1937. if (! project.getConfigFlag ("JUCE_QUICKTIME").get())
  1938. s.removeString ("QuickTime");
  1939. s.trim();
  1940. s.removeDuplicates (true);
  1941. s.sort (true);
  1942. for (auto& framework : s)
  1943. {
  1944. auto frameworkID = addFramework (framework);
  1945. // find all the targets that are referring to this object
  1946. for (auto& target : targets)
  1947. {
  1948. if (xcodeFrameworks.contains (framework) || target->xcodeFrameworks.contains (framework))
  1949. {
  1950. target->frameworkIDs.add (frameworkID);
  1951. target->frameworkNames.add (framework);
  1952. }
  1953. }
  1954. }
  1955. }
  1956. }
  1957. void addCustomFrameworks() const
  1958. {
  1959. StringArray customFrameworks;
  1960. customFrameworks.addTokens (getExtraCustomFrameworksString(), true);
  1961. customFrameworks.trim();
  1962. for (auto& framework : customFrameworks)
  1963. {
  1964. auto frameworkID = addCustomFramework (framework);
  1965. for (auto& target : targets)
  1966. {
  1967. target->frameworkIDs.add (frameworkID);
  1968. target->frameworkNames.add (framework);
  1969. }
  1970. }
  1971. }
  1972. void addEmbeddedFrameworks() const
  1973. {
  1974. StringArray frameworks;
  1975. frameworks.addTokens (getEmbeddedFrameworksString(), true);
  1976. frameworks.trim();
  1977. for (auto& framework : frameworks)
  1978. {
  1979. auto frameworkID = addEmbeddedFramework (framework);
  1980. embeddedFrameworkIDs.add (frameworkID);
  1981. for (auto& target : targets)
  1982. {
  1983. target->frameworkIDs.add (frameworkID);
  1984. target->frameworkNames.add (framework);
  1985. }
  1986. }
  1987. if (! embeddedFrameworkIDs.isEmpty())
  1988. for (auto& target : targets)
  1989. target->addCopyFilesPhase ("Embed Frameworks", embeddedFrameworkIDs, kFrameworksFolder);
  1990. }
  1991. void addCustomResourceFolders() const
  1992. {
  1993. StringArray folders;
  1994. folders.addTokens (getCustomResourceFoldersString(), ":", "");
  1995. folders.trim();
  1996. folders.removeEmptyStrings();
  1997. for (auto& crf : folders)
  1998. addCustomResourceFolder (crf);
  1999. }
  2000. void addSubprojects() const
  2001. {
  2002. auto subprojectLines = StringArray::fromLines (getSubprojectsString());
  2003. subprojectLines.removeEmptyStrings (true);
  2004. Array<std::pair<String, StringArray>> subprojects;
  2005. for (auto& line : subprojectLines)
  2006. {
  2007. String subprojectName (line.upToFirstOccurrenceOf (":", false, false));
  2008. StringArray requestedBuildProducts (StringArray::fromTokens (line.fromFirstOccurrenceOf (":", false, false), ",;|", "\"'"));
  2009. requestedBuildProducts.trim();
  2010. subprojects.add ({ subprojectName, requestedBuildProducts });
  2011. }
  2012. for (const auto& subprojectInfo : subprojects)
  2013. {
  2014. String subprojectPath (subprojectInfo.first);
  2015. if (! subprojectPath.endsWith (".xcodeproj"))
  2016. subprojectPath += ".xcodeproj";
  2017. File subprojectFile;
  2018. if (File::isAbsolutePath (subprojectPath))
  2019. {
  2020. subprojectFile = subprojectPath;
  2021. }
  2022. else
  2023. {
  2024. subprojectFile = getProject().getProjectFolder().getChildFile (subprojectPath);
  2025. RelativePath p (subprojectPath, RelativePath::projectFolder);
  2026. subprojectPath = p.rebased (getProject().getProjectFolder(), getTargetFolder(), RelativePath::buildTargetFolder).toUnixStyle();
  2027. }
  2028. if (! subprojectFile.isDirectory())
  2029. continue;
  2030. auto availableBuildProducts = XcodeProjectParser::parseBuildProducts (subprojectFile);
  2031. // If no build products have been specified then we'll take everything
  2032. if (! subprojectInfo.second.isEmpty())
  2033. {
  2034. auto newEnd = std::remove_if (availableBuildProducts.begin(), availableBuildProducts.end(),
  2035. [&subprojectInfo](const std::pair<String, String> &item)
  2036. {
  2037. return ! subprojectInfo.second.contains (item.first);
  2038. });
  2039. availableBuildProducts.erase (newEnd, availableBuildProducts.end());
  2040. }
  2041. if (availableBuildProducts.empty())
  2042. continue;
  2043. auto subprojectFileType = getFileType (RelativePath (subprojectPath, RelativePath::projectFolder));
  2044. auto subprojectFileID = addFileOrFolderReference (subprojectPath, "<group>", subprojectFileType);
  2045. subprojectFileIDs.add (subprojectFileID);
  2046. StringArray proxyIDs;
  2047. for (auto& buildProduct : availableBuildProducts)
  2048. {
  2049. auto buildProductFileType = getFileType (RelativePath (buildProduct.second, RelativePath::projectFolder));
  2050. auto containerID = addContainerItemProxy (subprojectFileID, buildProduct.first);
  2051. auto proxyID = addReferenceProxy (containerID, buildProduct.second, buildProductFileType);
  2052. proxyIDs.add (proxyID);
  2053. if (buildProductFileType == "archive.ar" || buildProductFileType == "wrapper.framework")
  2054. {
  2055. auto buildFileID = addBuildFile (buildProduct.second, proxyID, false, true);
  2056. for (auto& target : targets)
  2057. target->frameworkIDs.add (buildFileID);
  2058. if (buildProductFileType == "wrapper.framework")
  2059. {
  2060. auto fileID = createID (buildProduct.second + "buildref");
  2061. auto* v = new ValueTree (fileID);
  2062. v->setProperty ("isa", "PBXBuildFile", nullptr);
  2063. v->setProperty ("fileRef", proxyID, nullptr);
  2064. v->setProperty ("settings", "{ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }", nullptr);
  2065. pbxBuildFiles.add (v);
  2066. embeddedFrameworkIDs.add (fileID);
  2067. }
  2068. }
  2069. }
  2070. auto productGroupID = createFileRefID (subprojectPath + "_products");
  2071. addGroup (productGroupID, "Products", proxyIDs);
  2072. subprojectReferences.add ({ productGroupID, subprojectFileID });
  2073. }
  2074. }
  2075. void addXcassets() const
  2076. {
  2077. auto customXcassetsPath = getCustomXcassetsFolderString();
  2078. if (customXcassetsPath.isEmpty())
  2079. createXcassetsFolderFromIcons();
  2080. else
  2081. addCustomResourceFolder (customXcassetsPath, "folder.assetcatalog");
  2082. }
  2083. void addCustomResourceFolder (String folderPathRelativeToProjectFolder, const String fileType = "folder") const
  2084. {
  2085. auto folderPath = RelativePath (folderPathRelativeToProjectFolder, RelativePath::projectFolder)
  2086. .rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  2087. .toUnixStyle();
  2088. auto fileRefID = createFileRefID (folderPath);
  2089. addFileOrFolderReference (folderPath, "<group>", fileType);
  2090. resourceIDs.add (addBuildFile (folderPath, fileRefID, false, false));
  2091. resourceFileRefs.add (createFileRefID (folderPath));
  2092. }
  2093. //==============================================================================
  2094. void writeProjectFile (OutputStream& output) const
  2095. {
  2096. output << "// !$*UTF8*$!\n{\n"
  2097. "\tarchiveVersion = 1;\n"
  2098. "\tclasses = {\n\t};\n"
  2099. "\tobjectVersion = 46;\n"
  2100. "\tobjects = {\n";
  2101. Array<ValueTree*> objects;
  2102. objects.addArray (pbxBuildFiles);
  2103. objects.addArray (pbxFileReferences);
  2104. objects.addArray (pbxGroups);
  2105. objects.addArray (targetConfigs);
  2106. objects.addArray (projectConfigs);
  2107. objects.addArray (misc);
  2108. for (auto* o : objects)
  2109. {
  2110. output << "\t\t" << o->getType().toString() << " = {\n";
  2111. for (int j = 0; j < o->getNumProperties(); ++j)
  2112. {
  2113. auto propertyName = o->getPropertyName(j);
  2114. auto val = o->getProperty (propertyName).toString();
  2115. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n\\#%^`*")
  2116. && ! (val.trimStart().startsWithChar ('(')
  2117. || val.trimStart().startsWithChar ('{'))))
  2118. val = "\"" + val + "\"";
  2119. output << "\t\t\t" << propertyName.toString() << " = " << val << ";\n";
  2120. }
  2121. output << "\t\t};\n";
  2122. }
  2123. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  2124. }
  2125. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings, XcodeTarget* xcodeTarget = nullptr) const
  2126. {
  2127. auto fileID = createID (path + "buildref");
  2128. if (addToSourceBuildPhase)
  2129. {
  2130. if (xcodeTarget != nullptr)
  2131. xcodeTarget->sourceIDs.add (fileID);
  2132. else
  2133. sourceIDs.add (fileID);
  2134. }
  2135. auto* v = new ValueTree (fileID);
  2136. v->setProperty ("isa", "PBXBuildFile", nullptr);
  2137. v->setProperty ("fileRef", fileRefID, nullptr);
  2138. if (inhibitWarnings)
  2139. v->setProperty ("settings", "{ COMPILER_FLAGS = \"-w\"; }", nullptr);
  2140. pbxBuildFiles.add (v);
  2141. return fileID;
  2142. }
  2143. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings, XcodeTarget* xcodeTarget = nullptr) const
  2144. {
  2145. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings, xcodeTarget);
  2146. }
  2147. String addFileReference (String pathString) const
  2148. {
  2149. String sourceTree ("SOURCE_ROOT");
  2150. RelativePath path (pathString, RelativePath::unknown);
  2151. if (pathString.startsWith ("${"))
  2152. {
  2153. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  2154. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  2155. }
  2156. else if (path.isAbsolute())
  2157. {
  2158. sourceTree = "<absolute>";
  2159. }
  2160. auto fileType = getFileType (path);
  2161. return addFileOrFolderReference (pathString, sourceTree, fileType);
  2162. }
  2163. void checkAndAddFileReference (std::unique_ptr<ValueTree> v) const
  2164. {
  2165. auto existing = pbxFileReferences.indexOfSorted (*this, v.get());
  2166. if (existing >= 0)
  2167. {
  2168. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  2169. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  2170. }
  2171. else
  2172. {
  2173. pbxFileReferences.addSorted (*this, v.release());
  2174. }
  2175. }
  2176. String addFileOrFolderReference (const String& pathString, String sourceTree, String fileType) const
  2177. {
  2178. auto fileRefID = createFileRefID (pathString);
  2179. std::unique_ptr<ValueTree> v (new ValueTree (fileRefID));
  2180. v->setProperty ("isa", "PBXFileReference", nullptr);
  2181. v->setProperty ("lastKnownFileType", fileType, nullptr);
  2182. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  2183. v->setProperty ("path", pathString, nullptr);
  2184. v->setProperty ("sourceTree", sourceTree, nullptr);
  2185. checkAndAddFileReference (std::move (v));
  2186. return fileRefID;
  2187. }
  2188. String addContainerItemProxy (const String& subprojectID, const String& itemName) const
  2189. {
  2190. auto uniqueString = subprojectID + "_" + itemName;
  2191. auto fileRefID = createFileRefID (uniqueString);
  2192. std::unique_ptr<ValueTree> v (new ValueTree (fileRefID));
  2193. v->setProperty ("isa", "PBXContainerItemProxy", nullptr);
  2194. v->setProperty ("containerPortal", subprojectID, nullptr);
  2195. v->setProperty ("proxyType", 2, nullptr);
  2196. v->setProperty ("remoteGlobalIDString", createFileRefID (uniqueString + "_global"), nullptr);
  2197. v->setProperty ("remoteInfo", itemName, nullptr);
  2198. checkAndAddFileReference (std::move (v));
  2199. return fileRefID;
  2200. }
  2201. String addReferenceProxy (const String& containerItemID, const String& proxyPath, const String& fileType) const
  2202. {
  2203. auto fileRefID = createFileRefID (containerItemID + "_" + proxyPath);
  2204. std::unique_ptr<ValueTree> v (new ValueTree (fileRefID));
  2205. v->setProperty ("isa", "PBXReferenceProxy", nullptr);
  2206. v->setProperty ("fileType", fileType, nullptr);
  2207. v->setProperty ("path", proxyPath, nullptr);
  2208. v->setProperty ("remoteRef", containerItemID, nullptr);
  2209. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  2210. checkAndAddFileReference (std::move (v));
  2211. return fileRefID;
  2212. }
  2213. public:
  2214. static int compareElements (const ValueTree* first, const ValueTree* second)
  2215. {
  2216. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  2217. }
  2218. private:
  2219. static String getFileType (const RelativePath& file)
  2220. {
  2221. if (file.hasFileExtension (cppFileExtensions)) return "sourcecode.cpp.cpp";
  2222. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  2223. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  2224. if (file.hasFileExtension (".c")) return "sourcecode.c.c";
  2225. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  2226. if (file.hasFileExtension (asmFileExtensions)) return "sourcecode.c.asm";
  2227. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  2228. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  2229. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  2230. if (file.hasFileExtension ("html;htm")) return "text.html";
  2231. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  2232. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  2233. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  2234. if (file.hasFileExtension ("entitlements")) return "text.plist.xml";
  2235. if (file.hasFileExtension ("app")) return "wrapper.application";
  2236. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  2237. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  2238. if (file.hasFileExtension ("a")) return "archive.ar";
  2239. if (file.hasFileExtension ("xcassets")) return "folder.assetcatalog";
  2240. return "file" + file.getFileExtension();
  2241. }
  2242. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources,
  2243. bool shouldBeAddedToXcodeResources, bool inhibitWarnings, XcodeTarget* xcodeTarget) const
  2244. {
  2245. auto pathAsString = path.toUnixStyle();
  2246. auto refID = addFileReference (path.toUnixStyle());
  2247. if (shouldBeCompiled)
  2248. {
  2249. addBuildFile (pathAsString, refID, true, inhibitWarnings, xcodeTarget);
  2250. }
  2251. else if (! shouldBeAddedToBinaryResources || shouldBeAddedToXcodeResources)
  2252. {
  2253. auto fileType = getFileType (path);
  2254. if (shouldBeAddedToXcodeResources)
  2255. {
  2256. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  2257. resourceFileRefs.add (refID);
  2258. }
  2259. }
  2260. return refID;
  2261. }
  2262. String addRezFile (const Project::Item& projectItem, const RelativePath& path) const
  2263. {
  2264. auto pathAsString = path.toUnixStyle();
  2265. auto refID = addFileReference (path.toUnixStyle());
  2266. if (projectItem.isModuleCode())
  2267. {
  2268. if (auto* xcodeTarget = getTargetOfType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), false)))
  2269. {
  2270. auto rezFileID = addBuildFile (pathAsString, refID, false, false, xcodeTarget);
  2271. xcodeTarget->rezFileIDs.add (rezFileID);
  2272. return refID;
  2273. }
  2274. }
  2275. return {};
  2276. }
  2277. String getEntitlementsFileName() const
  2278. {
  2279. return project.getProjectFilenameRootString() + String (".entitlements");
  2280. }
  2281. StringPairArray getEntitlements() const
  2282. {
  2283. StringPairArray entitlements;
  2284. if (project.getProjectType().isAudioPlugin())
  2285. {
  2286. if (isiOS())
  2287. {
  2288. if (project.shouldEnableIAA())
  2289. entitlements.set ("inter-app-audio", "<true/>");
  2290. }
  2291. else
  2292. {
  2293. entitlements.set ("com.apple.security.app-sandbox", "<true/>");
  2294. }
  2295. }
  2296. else
  2297. {
  2298. if (isPushNotificationsEnabled())
  2299. entitlements.set (isiOS() ? "aps-environment"
  2300. : "com.apple.developer.aps-environment",
  2301. "<string>development</string>");
  2302. }
  2303. if (isAppGroupsEnabled())
  2304. {
  2305. auto appGroups = StringArray::fromTokens (getAppGroupIdString(), ";", { });
  2306. auto groups = String ("<array>");
  2307. for (auto group : appGroups)
  2308. groups += "\n\t\t<string>" + group.trim() + "</string>";
  2309. groups += "\n\t</array>";
  2310. entitlements.set ("com.apple.security.application-groups", groups);
  2311. }
  2312. if (isiOS() && isiCloudPermissionsEnabled())
  2313. {
  2314. entitlements.set ("com.apple.developer.icloud-container-identifiers",
  2315. "<array>\n"
  2316. " <string>iCloud.$(CFBundleIdentifier)</string>\n"
  2317. " </array>");
  2318. entitlements.set ("com.apple.developer.icloud-services",
  2319. "<array>\n"
  2320. " <string>CloudDocuments</string>\n"
  2321. " </array>");
  2322. entitlements.set ("com.apple.developer.ubiquity-container-identifiers",
  2323. "<array>\n"
  2324. " <string>iCloud.$(CFBundleIdentifier)</string>\n"
  2325. " </array>");
  2326. }
  2327. return entitlements;
  2328. }
  2329. String addEntitlementsFile (StringPairArray entitlements) const
  2330. {
  2331. String content =
  2332. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2333. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  2334. "<plist version=\"1.0\">\n"
  2335. "<dict>\n";
  2336. auto keys = entitlements.getAllKeys();
  2337. for (auto& key : keys)
  2338. {
  2339. content += "\t<key>" + key + "</key>\n"
  2340. "\t" + entitlements[key] + "\n";
  2341. }
  2342. content += "</dict>\n"
  2343. "</plist>\n";
  2344. auto entitlementsFile = getTargetFolder().getChildFile (getEntitlementsFileName());
  2345. overwriteFileIfDifferentOrThrow (entitlementsFile, content);
  2346. RelativePath plistPath (entitlementsFile, getTargetFolder(), RelativePath::buildTargetFolder);
  2347. return addFile (plistPath, false, false, false, false, nullptr);
  2348. }
  2349. String addProjectItem (const Project::Item& projectItem) const
  2350. {
  2351. if (modulesGroup != nullptr && projectItem.getParent() == *modulesGroup)
  2352. return addFileReference (rebaseFromProjectFolderToBuildTarget (getModuleFolderRelativeToProject (projectItem.getName())).toUnixStyle());
  2353. if (projectItem.isGroup())
  2354. {
  2355. StringArray childIDs;
  2356. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  2357. {
  2358. auto child = projectItem.getChild (i);
  2359. auto childID = addProjectItem (child);
  2360. if (childID.isNotEmpty() && ! child.shouldBeAddedToXcodeResources())
  2361. childIDs.add (childID);
  2362. }
  2363. if (childIDs.isEmpty())
  2364. return {};
  2365. return addGroup (projectItem, childIDs);
  2366. }
  2367. if (projectItem.shouldBeAddedToTargetProject())
  2368. {
  2369. auto itemPath = projectItem.getFilePath();
  2370. RelativePath path;
  2371. if (itemPath.startsWith ("${"))
  2372. path = RelativePath (itemPath, RelativePath::unknown);
  2373. else
  2374. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  2375. if (path.hasFileExtension (".r"))
  2376. return addRezFile (projectItem, path);
  2377. XcodeTarget* xcodeTarget = nullptr;
  2378. if (projectItem.isModuleCode() && projectItem.shouldBeCompiled())
  2379. xcodeTarget = getTargetOfType (project.getTargetTypeFromFilePath (projectItem.getFile(), false));
  2380. return addFile (path, projectItem.shouldBeCompiled(),
  2381. projectItem.shouldBeAddedToBinaryResources(),
  2382. projectItem.shouldBeAddedToXcodeResources(),
  2383. projectItem.shouldInhibitWarnings(),
  2384. xcodeTarget);
  2385. }
  2386. return {};
  2387. }
  2388. String addFramework (const String& frameworkName) const
  2389. {
  2390. auto path = frameworkName;
  2391. auto isRelativePath = path.startsWith ("../");
  2392. if (! File::isAbsolutePath (path) && ! isRelativePath)
  2393. path = "System/Library/Frameworks/" + path;
  2394. if (! path.endsWithIgnoreCase (".framework"))
  2395. path << ".framework";
  2396. auto fileRefID = createFileRefID (path);
  2397. addFileReference (((File::isAbsolutePath (frameworkName) || isRelativePath) ? "" : "${SDKROOT}/") + path);
  2398. frameworkFileIDs.add (fileRefID);
  2399. return addBuildFile (path, fileRefID, false, false);
  2400. }
  2401. String addCustomFramework (String frameworkPath) const
  2402. {
  2403. if (! frameworkPath.endsWithIgnoreCase (".framework"))
  2404. frameworkPath << ".framework";
  2405. auto fileRefID = createFileRefID (frameworkPath);
  2406. auto fileType = getFileType (RelativePath (frameworkPath, RelativePath::projectFolder));
  2407. addFileOrFolderReference (frameworkPath, "<group>", fileType);
  2408. frameworkFileIDs.add (fileRefID);
  2409. return addBuildFile (frameworkPath, fileRefID, false, false);
  2410. }
  2411. String addEmbeddedFramework (const String& path) const
  2412. {
  2413. auto fileRefID = createFileRefID (path);
  2414. auto fileType = getFileType (RelativePath (path, RelativePath::projectFolder));
  2415. addFileOrFolderReference (path, "<group>", fileType);
  2416. auto fileID = createID (path + "buildref");
  2417. auto* v = new ValueTree (fileID);
  2418. v->setProperty ("isa", "PBXBuildFile", nullptr);
  2419. v->setProperty ("fileRef", fileRefID, nullptr);
  2420. v->setProperty ("settings", "{ ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }", nullptr);
  2421. pbxBuildFiles.add (v);
  2422. frameworkFileIDs.add (fileRefID);
  2423. return fileID;
  2424. }
  2425. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  2426. {
  2427. auto* v = new ValueTree (groupID);
  2428. v->setProperty ("isa", "PBXGroup", nullptr);
  2429. v->setProperty ("children", indentParenthesisedList (childIDs), nullptr);
  2430. v->setProperty (Ids::name, groupName, nullptr);
  2431. v->setProperty ("sourceTree", "<group>", nullptr);
  2432. pbxGroups.add (v);
  2433. }
  2434. String addGroup (const Project::Item& item, StringArray& childIDs) const
  2435. {
  2436. auto groupName = item.getName();
  2437. auto groupID = getIDForGroup (item);
  2438. addGroup (groupID, groupName, childIDs);
  2439. return groupID;
  2440. }
  2441. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  2442. {
  2443. auto* v = new ValueTree (createID ("projectconfigid_" + configName));
  2444. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  2445. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  2446. v->setProperty (Ids::name, configName, nullptr);
  2447. projectConfigs.add (v);
  2448. }
  2449. void addConfigList (XcodeTarget& target, const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  2450. {
  2451. auto* v = new ValueTree (listID);
  2452. v->setProperty ("isa", "XCConfigurationList", nullptr);
  2453. v->setProperty ("buildConfigurations", indentParenthesisedList (target.configIDs), nullptr);
  2454. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  2455. if (auto* first = configsToUse.getFirst())
  2456. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  2457. misc.add (v);
  2458. }
  2459. void addProjectConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  2460. {
  2461. StringArray configIDs;
  2462. for (auto* c : configsToUse)
  2463. configIDs.add (c->getType().toString());
  2464. auto* v = new ValueTree (listID);
  2465. v->setProperty ("isa", "XCConfigurationList", nullptr);
  2466. v->setProperty ("buildConfigurations", indentParenthesisedList (configIDs), nullptr);
  2467. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  2468. if (auto* first = configsToUse.getFirst())
  2469. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  2470. misc.add (v);
  2471. }
  2472. void addProjectObject() const
  2473. {
  2474. auto* v = new ValueTree (createID ("__root"));
  2475. v->setProperty ("isa", "PBXProject", nullptr);
  2476. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  2477. v->setProperty ("attributes", getProjectObjectAttributes(), nullptr);
  2478. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  2479. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  2480. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  2481. v->setProperty ("projectDirPath", "\"\"", nullptr);
  2482. if (! subprojectReferences.isEmpty())
  2483. {
  2484. StringArray projectReferences;
  2485. for (auto& reference : subprojectReferences)
  2486. projectReferences.add (indentBracedList ({ "ProductGroup = " + reference.first, "ProjectRef = " + reference.second }, 1));
  2487. v->setProperty ("projectReferences", indentParenthesisedList (projectReferences), nullptr);
  2488. }
  2489. v->setProperty ("projectRoot", "\"\"", nullptr);
  2490. auto targetString = "(" + targetIDs.joinIntoString (", ") + ")";
  2491. v->setProperty ("targets", targetString, nullptr);
  2492. misc.add (v);
  2493. }
  2494. //==============================================================================
  2495. void removeMismatchedXcuserdata() const
  2496. {
  2497. if (settings ["keepCustomXcodeSchemes"])
  2498. return;
  2499. auto xcuserdata = getProjectBundle().getChildFile ("xcuserdata");
  2500. if (! xcuserdata.exists())
  2501. return;
  2502. if (! xcuserdataMatchesTargets (xcuserdata))
  2503. {
  2504. xcuserdata.deleteRecursively();
  2505. getProjectBundle().getChildFile ("project.xcworkspace").deleteRecursively();
  2506. }
  2507. }
  2508. bool xcuserdataMatchesTargets (const File& xcuserdata) const
  2509. {
  2510. for (auto& plist : xcuserdata.findChildFiles (File::findFiles, true, "xcschememanagement.plist"))
  2511. if (! xcschemeManagementPlistMatchesTargets (plist))
  2512. return false;
  2513. return true;
  2514. }
  2515. static StringArray parseNamesOfTargetsFromPlist (const XmlElement& dictXML)
  2516. {
  2517. forEachXmlChildElementWithTagName (dictXML, schemesKey, "key")
  2518. {
  2519. if (schemesKey->getAllSubText().trim().equalsIgnoreCase ("SchemeUserState"))
  2520. {
  2521. if (auto* dict = schemesKey->getNextElement())
  2522. {
  2523. if (dict->hasTagName ("dict"))
  2524. {
  2525. StringArray names;
  2526. forEachXmlChildElementWithTagName (*dict, key, "key")
  2527. names.add (key->getAllSubText().upToLastOccurrenceOf (".xcscheme", false, false).trim());
  2528. names.sort (false);
  2529. return names;
  2530. }
  2531. }
  2532. }
  2533. }
  2534. return {};
  2535. }
  2536. StringArray getNamesOfTargets() const
  2537. {
  2538. StringArray names;
  2539. for (auto& target : targets)
  2540. names.add (target->getXcodeSchemeName());
  2541. names.sort (false);
  2542. return names;
  2543. }
  2544. bool xcschemeManagementPlistMatchesTargets (const File& plist) const
  2545. {
  2546. if (auto xml = parseXML (plist))
  2547. if (auto* dict = xml->getChildByName ("dict"))
  2548. return parseNamesOfTargetsFromPlist (*dict) == getNamesOfTargets();
  2549. return false;
  2550. }
  2551. //==============================================================================
  2552. struct AppIconType
  2553. {
  2554. const char* idiom;
  2555. const char* sizeString;
  2556. const char* filename;
  2557. const char* scale;
  2558. int size;
  2559. };
  2560. static Array<AppIconType> getiOSAppIconTypes()
  2561. {
  2562. AppIconType types[] =
  2563. {
  2564. { "iphone", "20x20", "Icon-Notification-20@2x.png", "2x", 40 },
  2565. { "iphone", "20x20", "Icon-Notification-20@3x.png", "3x", 60 },
  2566. { "iphone", "29x29", "Icon-29.png", "1x", 29 },
  2567. { "iphone", "29x29", "Icon-29@2x.png", "2x", 58 },
  2568. { "iphone", "29x29", "Icon-29@3x.png", "3x", 87 },
  2569. { "iphone", "40x40", "Icon-Spotlight-40@2x.png", "2x", 80 },
  2570. { "iphone", "40x40", "Icon-Spotlight-40@3x.png", "3x", 120 },
  2571. { "iphone", "57x57", "Icon.png", "1x", 57 },
  2572. { "iphone", "57x57", "Icon@2x.png", "2x", 114 },
  2573. { "iphone", "60x60", "Icon-60@2x.png", "2x", 120 },
  2574. { "iphone", "60x60", "Icon-@3x.png", "3x", 180 },
  2575. { "ipad", "20x20", "Icon-Notifications-20.png", "1x", 20 },
  2576. { "ipad", "20x20", "Icon-Notifications-20@2x.png", "2x", 40 },
  2577. { "ipad", "29x29", "Icon-Small-1.png", "1x", 29 },
  2578. { "ipad", "29x29", "Icon-Small@2x-1.png", "2x", 58 },
  2579. { "ipad", "40x40", "Icon-Spotlight-40.png", "1x", 40 },
  2580. { "ipad", "40x40", "Icon-Spotlight-40@2x-1.png", "2x", 80 },
  2581. { "ipad", "50x50", "Icon-Small-50.png", "1x", 50 },
  2582. { "ipad", "50x50", "Icon-Small-50@2x.png", "2x", 100 },
  2583. { "ipad", "72x72", "Icon-72.png", "1x", 72 },
  2584. { "ipad", "72x72", "Icon-72@2x.png", "2x", 144 },
  2585. { "ipad", "76x76", "Icon-76.png", "1x", 76 },
  2586. { "ipad", "76x76", "Icon-76@2x.png", "2x", 152 },
  2587. { "ipad", "83.5x83.5", "Icon-83.5@2x.png", "2x", 167 },
  2588. { "ios-marketing", "1024x1024", "Icon-AppStore-1024.png", "1x", 1024 }
  2589. };
  2590. return Array<AppIconType> (types, numElementsInArray (types));
  2591. }
  2592. static String getiOSAppIconContents()
  2593. {
  2594. var images;
  2595. for (auto& type : getiOSAppIconTypes())
  2596. {
  2597. DynamicObject::Ptr d (new DynamicObject());
  2598. d->setProperty ("idiom", type.idiom);
  2599. d->setProperty ("size", type.sizeString);
  2600. d->setProperty ("filename", type.filename);
  2601. d->setProperty ("scale", type.scale);
  2602. images.append (var (d.get()));
  2603. }
  2604. return getiOSAssetContents (images);
  2605. }
  2606. String getProjectObjectAttributes() const
  2607. {
  2608. String attributes;
  2609. attributes << "{ LastUpgradeCheck = 0930; "
  2610. << "ORGANIZATIONNAME = " << getProject().getCompanyNameString().quoted()
  2611. <<"; ";
  2612. if (projectType.isGUIApplication() || projectType.isAudioPlugin())
  2613. {
  2614. attributes << "TargetAttributes = { ";
  2615. for (auto& target : targets)
  2616. attributes << target->getTargetAttributes();
  2617. attributes << " }; ";
  2618. }
  2619. attributes << "}";
  2620. return attributes;
  2621. }
  2622. //==============================================================================
  2623. struct ImageType
  2624. {
  2625. const char* orientation;
  2626. const char* idiom;
  2627. const char* subtype;
  2628. const char* extent;
  2629. const char* scale;
  2630. const char* filename;
  2631. int width;
  2632. int height;
  2633. };
  2634. static Array<ImageType> getiOSLaunchImageTypes()
  2635. {
  2636. ImageType types[] =
  2637. {
  2638. { "portrait", "iphone", nullptr, "full-screen", "2x", "LaunchImage-iphone-2x.png", 640, 960 },
  2639. { "portrait", "iphone", "retina4", "full-screen", "2x", "LaunchImage-iphone-retina4.png", 640, 1136 },
  2640. { "portrait", "ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-portrait-1x.png", 768, 1024 },
  2641. { "landscape","ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-landscape-1x.png", 1024, 768 },
  2642. { "portrait", "ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-portrait-2x.png", 1536, 2048 },
  2643. { "landscape","ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-landscape-2x.png", 2048, 1536 }
  2644. };
  2645. return Array<ImageType> (types, numElementsInArray (types));
  2646. }
  2647. static String getiOSLaunchImageContents()
  2648. {
  2649. var images;
  2650. for (auto& type : getiOSLaunchImageTypes())
  2651. {
  2652. DynamicObject::Ptr d (new DynamicObject());
  2653. d->setProperty ("orientation", type.orientation);
  2654. d->setProperty ("idiom", type.idiom);
  2655. d->setProperty ("extent", type.extent);
  2656. d->setProperty ("minimum-system-version", "7.0");
  2657. d->setProperty ("scale", type.scale);
  2658. d->setProperty ("filename", type.filename);
  2659. if (type.subtype != nullptr)
  2660. d->setProperty ("subtype", type.subtype);
  2661. images.append (var (d.get()));
  2662. }
  2663. return getiOSAssetContents (images);
  2664. }
  2665. static void createiOSLaunchImageFiles (const File& launchImageSet)
  2666. {
  2667. for (auto& type : getiOSLaunchImageTypes())
  2668. {
  2669. Image image (Image::ARGB, type.width, type.height, true); // (empty black image)
  2670. image.clear (image.getBounds(), Colours::black);
  2671. MemoryOutputStream pngData;
  2672. PNGImageFormat pngFormat;
  2673. pngFormat.writeImageToStream (image, pngData);
  2674. overwriteFileIfDifferentOrThrow (launchImageSet.getChildFile (type.filename), pngData);
  2675. }
  2676. }
  2677. //==============================================================================
  2678. static String getiOSAssetContents (var images)
  2679. {
  2680. DynamicObject::Ptr v (new DynamicObject());
  2681. var info (new DynamicObject());
  2682. info.getDynamicObject()->setProperty ("version", 1);
  2683. info.getDynamicObject()->setProperty ("author", "xcode");
  2684. v->setProperty ("images", images);
  2685. v->setProperty ("info", info);
  2686. return JSON::toString (var (v.get()));
  2687. }
  2688. void createXcassetsFolderFromIcons() const
  2689. {
  2690. auto assets = getTargetFolder().getChildFile (project.getProjectFilenameRootString())
  2691. .getChildFile ("Images.xcassets");
  2692. auto iconSet = assets.getChildFile ("AppIcon.appiconset");
  2693. auto launchImage = assets.getChildFile ("LaunchImage.launchimage");
  2694. overwriteFileIfDifferentOrThrow (iconSet.getChildFile ("Contents.json"), getiOSAppIconContents());
  2695. createiOSIconFiles (iconSet);
  2696. overwriteFileIfDifferentOrThrow (launchImage.getChildFile ("Contents.json"), getiOSLaunchImageContents());
  2697. createiOSLaunchImageFiles (launchImage);
  2698. RelativePath assetsPath (assets, getTargetFolder(), RelativePath::buildTargetFolder);
  2699. addFileReference (assetsPath.toUnixStyle());
  2700. resourceIDs.add (addBuildFile (assetsPath, false, false));
  2701. resourceFileRefs.add (createFileRefID (assetsPath));
  2702. }
  2703. //==============================================================================
  2704. static String indentBracedList (const StringArray& list, int depth = 0) { return indentList (list, '{', '}', ";", depth, true); }
  2705. static String indentParenthesisedList (const StringArray& list, int depth = 0) { return indentList (list, '(', ')', ",", depth, false); }
  2706. static String indentList (StringArray list, char openBracket, char closeBracket, const String& separator, int extraTabs, bool shouldSort)
  2707. {
  2708. if (list.size() == 0)
  2709. return openBracket + String (" ") + closeBracket;
  2710. auto tabs = "\n" + String::repeatedString ("\t", extraTabs + 4);
  2711. if (shouldSort)
  2712. list.sort (true);
  2713. return openBracket + tabs + list.joinIntoString (separator + tabs) + separator
  2714. + "\n" + String::repeatedString ("\t", extraTabs + 3) + closeBracket;
  2715. }
  2716. String createID (String rootString) const
  2717. {
  2718. if (rootString.startsWith ("${"))
  2719. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  2720. rootString += project.getProjectUIDString();
  2721. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  2722. }
  2723. String createFileRefID (const RelativePath& path) const { return createFileRefID (path.toUnixStyle()); }
  2724. String createFileRefID (const String& path) const { return createID ("__fileref_" + path); }
  2725. String getIDForGroup (const Project::Item& item) const { return createID (item.getID()); }
  2726. bool shouldFileBeCompiledByDefault (const RelativePath& file) const override
  2727. {
  2728. return file.hasFileExtension (sourceFileExtensions);
  2729. }
  2730. static String getOSXVersionName (int version)
  2731. {
  2732. jassert (version >= 4);
  2733. return "10." + String (version);
  2734. }
  2735. static String getSDKName (int version)
  2736. {
  2737. return getOSXVersionName (version) + " SDK";
  2738. }
  2739. JUCE_DECLARE_NON_COPYABLE (XcodeProjectExporter)
  2740. };