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.

3761 lines
181KB

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