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.

3220 lines
157KB

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