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.

3734 lines
179KB

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