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.

3225 lines
157KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  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", "Landsscape 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;
  828. StringArray frameworkNames;
  829. String dependencyID, 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. void addDependency()
  887. {
  888. jassert (dependencyID.isEmpty());
  889. dependencyID = owner.createID (String ("__dependency") + getName());
  890. auto* v = new ValueTree (dependencyID);
  891. v->setProperty ("isa", "PBXTargetDependency", nullptr);
  892. v->setProperty ("target", getID(), nullptr);
  893. owner.misc.add (v);
  894. }
  895. String getDependencyID() const
  896. {
  897. jassert (dependencyID.isNotEmpty());
  898. return dependencyID;
  899. }
  900. //==============================================================================
  901. void addTargetConfig (const String& configName, const StringArray& buildSettings)
  902. {
  903. auto configID = owner.createID (String ("targetconfigid_") + getName() + String ("_") + configName);
  904. auto* v = new ValueTree (configID);
  905. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  906. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  907. v->setProperty (Ids::name, configName, nullptr);
  908. configIDs.add (configID);
  909. owner.targetConfigs.add (v);
  910. }
  911. //==============================================================================
  912. String getTargetAttributes() const
  913. {
  914. auto attributes = getID() + " = { ";
  915. auto developmentTeamID = owner.getDevelopmentTeamIDString();
  916. if (developmentTeamID.isNotEmpty())
  917. {
  918. attributes << "DevelopmentTeam = " << developmentTeamID << "; ";
  919. attributes << "ProvisioningStyle = Automatic; ";
  920. }
  921. auto appGroupsEnabled = (owner.iOS && owner.isAppGroupsEnabled()) ? 1 : 0;
  922. auto inAppPurchasesEnabled = owner.isInAppPurchasesEnabled() ? 1 : 0;
  923. auto interAppAudioEnabled = (owner.iOS
  924. && type == Target::StandalonePlugIn
  925. && owner.getProject().shouldEnableIAA()) ? 1 : 0;
  926. auto pushNotificationsEnabled = owner.isPushNotificationsEnabled() ? 1 : 0;
  927. auto sandboxEnabled = ((type == Target::AudioUnitv3PlugIn) || owner.isAppSandboxEnabled()) ? 1 : 0;
  928. auto hardendedRuntimeEnabled = owner.isHardenedRuntimeEnabled() ? 1 : 0;
  929. attributes << "SystemCapabilities = {";
  930. attributes << "com.apple.ApplicationGroups.iOS = { enabled = " << appGroupsEnabled << "; }; ";
  931. attributes << "com.apple.InAppPurchase = { enabled = " << inAppPurchasesEnabled << "; }; ";
  932. attributes << "com.apple.InterAppAudio = { enabled = " << interAppAudioEnabled << "; }; ";
  933. attributes << "com.apple.Push = { enabled = " << pushNotificationsEnabled << "; }; ";
  934. attributes << "com.apple.Sandbox = { enabled = " << sandboxEnabled << "; }; ";
  935. attributes << "com.apple.HardenedRuntime = { enabled = " << hardendedRuntimeEnabled << "; }; ";
  936. if (owner.iOS && owner.isiCloudPermissionsEnabled())
  937. attributes << "com.apple.iCloud = { enabled = 1; }; ";
  938. attributes << "}; };";
  939. return attributes;
  940. }
  941. //==============================================================================
  942. ValueTree& addBuildPhase (const String& buildPhaseType, const StringArray& fileIds, const StringRef humanReadableName = StringRef())
  943. {
  944. auto buildPhaseName = buildPhaseType + "_" + getName() + "_" + (humanReadableName.isNotEmpty() ? String (humanReadableName) : String ("resbuildphase"));
  945. auto buildPhaseId (owner.createID (buildPhaseName));
  946. int n = 0;
  947. while (buildPhaseIDs.contains (buildPhaseId))
  948. buildPhaseId = owner.createID (buildPhaseName + String (++n));
  949. buildPhaseIDs.add (buildPhaseId);
  950. auto* v = new ValueTree (buildPhaseId);
  951. v->setProperty ("isa", buildPhaseType, nullptr);
  952. v->setProperty ("buildActionMask", "2147483647", nullptr);
  953. v->setProperty ("files", indentParenthesisedList (fileIds), nullptr);
  954. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  955. if (humanReadableName.isNotEmpty())
  956. v->setProperty ("name", String (humanReadableName), nullptr);
  957. owner.misc.add (v);
  958. return *v;
  959. }
  960. bool shouldCreatePList() const
  961. {
  962. auto fileType = getTargetFileType();
  963. return (fileType == executable && type != ConsoleApp) || fileType == pluginBundle || fileType == macOSAppex;
  964. }
  965. //==============================================================================
  966. bool shouldAddEntitlements() const
  967. {
  968. if (owner.isPushNotificationsEnabled()
  969. || owner.isAppGroupsEnabled()
  970. || owner.isAppSandboxEnabled()
  971. || owner.isHardenedRuntimeEnabled()
  972. || (owner.isiOS() && owner.isiCloudPermissionsEnabled()))
  973. return true;
  974. if (owner.project.isAudioPluginProject()
  975. && ((owner.isOSX() && type == Target::AudioUnitv3PlugIn)
  976. || (owner.isiOS() && type == Target::StandalonePlugIn && owner.getProject().shouldEnableIAA())))
  977. return true;
  978. return false;
  979. }
  980. String getBundleIdentifier() const
  981. {
  982. auto exporterBundleIdentifier = owner.exporterBundleIdentifierValue.get().toString();
  983. auto bundleIdentifier = exporterBundleIdentifier.isNotEmpty() ? exporterBundleIdentifier
  984. : owner.project.getBundleIdentifierString();
  985. if (xcodeBundleIDSubPath.isNotEmpty())
  986. {
  987. auto bundleIdSegments = StringArray::fromTokens (bundleIdentifier, ".", StringRef());
  988. jassert (bundleIdSegments.size() > 0);
  989. bundleIdentifier += String (".") + bundleIdSegments[bundleIdSegments.size() - 1] + xcodeBundleIDSubPath;
  990. }
  991. return bundleIdentifier;
  992. }
  993. StringPairArray getConfigPreprocessorDefs (const XcodeBuildConfiguration& config) const
  994. {
  995. StringPairArray defines;
  996. if (config.isDebug())
  997. {
  998. defines.set ("_DEBUG", "1");
  999. defines.set ("DEBUG", "1");
  1000. }
  1001. else
  1002. {
  1003. defines.set ("_NDEBUG", "1");
  1004. defines.set ("NDEBUG", "1");
  1005. }
  1006. if (owner.isInAppPurchasesEnabled())
  1007. defines.set ("JUCE_IN_APP_PURCHASES", "1");
  1008. if (owner.iOS && owner.isContentSharingEnabled())
  1009. defines.set ("JUCE_CONTENT_SHARING", "1");
  1010. if (owner.isPushNotificationsEnabled())
  1011. defines.set ("JUCE_PUSH_NOTIFICATIONS", "1");
  1012. return mergePreprocessorDefs (defines, owner.getAllPreprocessorDefs (config, type));
  1013. }
  1014. //==============================================================================
  1015. StringPairArray getTargetSettings (const XcodeBuildConfiguration& config) const
  1016. {
  1017. StringPairArray s;
  1018. if (type == AggregateTarget && ! owner.isiOS())
  1019. {
  1020. // the aggregate target needs to have the deployment target set for
  1021. // pre-/post-build scripts
  1022. s.set ("MACOSX_DEPLOYMENT_TARGET", getOSXDeploymentTarget (config.getOSXDeploymentTargetString()));
  1023. s.set ("SDKROOT", getOSXSDKVersion (config.getOSXSDKVersionString()));
  1024. return s;
  1025. }
  1026. s.set ("PRODUCT_NAME", owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString (type == UnityPlugIn)).quoted());
  1027. s.set ("PRODUCT_BUNDLE_IDENTIFIER", getBundleIdentifier());
  1028. auto arch = (! owner.isiOS() && type == Target::AudioUnitv3PlugIn) ? osxArch_64Bit
  1029. : config.getOSXArchitectureString();
  1030. if (arch == osxArch_Native) s.set ("ARCHS", "\"$(NATIVE_ARCH_ACTUAL)\"");
  1031. else if (arch == osxArch_32BitUniversal) s.set ("ARCHS", "\"$(ARCHS_STANDARD_32_BIT)\"");
  1032. else if (arch == osxArch_64BitUniversal) s.set ("ARCHS", "\"$(ARCHS_STANDARD_32_64_BIT)\"");
  1033. else if (arch == osxArch_64Bit) s.set ("ARCHS", "\"$(ARCHS_STANDARD_64_BIT)\"");
  1034. StringArray headerPaths (getHeaderSearchPaths (config));
  1035. headerPaths.add ("\"$(inherited)\"");
  1036. s.set ("HEADER_SEARCH_PATHS", indentParenthesisedList (headerPaths, 1));
  1037. s.set ("USE_HEADERMAP", String (static_cast<bool> (config.exporter.settings.getProperty ("useHeaderMap")) ? "YES" : "NO"));
  1038. auto frameworkSearchPaths = getFrameworkSearchPaths (config);
  1039. if (! frameworkSearchPaths.isEmpty())
  1040. s.set ("FRAMEWORK_SEARCH_PATHS", String ("(") + frameworkSearchPaths.joinIntoString (", ") + ", \"$(inherited)\")");
  1041. s.set ("GCC_OPTIMIZATION_LEVEL", config.getGCCOptimisationFlag());
  1042. if (shouldCreatePList())
  1043. {
  1044. s.set ("INFOPLIST_FILE", infoPlistFile.getFileName());
  1045. if (owner.getPListPrefixHeaderString().isNotEmpty())
  1046. s.set ("INFOPLIST_PREFIX_HEADER", owner.getPListPrefixHeaderString());
  1047. s.set ("INFOPLIST_PREPROCESS", (owner.isPListPreprocessEnabled() ? String ("YES") : String ("NO")));
  1048. auto plistDefs = parsePreprocessorDefs (config.getPListPreprocessorDefinitionsString());
  1049. StringArray defsList;
  1050. for (int i = 0; i < plistDefs.size(); ++i)
  1051. {
  1052. auto def = plistDefs.getAllKeys()[i];
  1053. auto value = plistDefs.getAllValues()[i];
  1054. if (value.isNotEmpty())
  1055. def << "=" << value.replace ("\"", "\\\\\\\"");
  1056. defsList.add ("\"" + def + "\"");
  1057. }
  1058. if (defsList.size() > 0)
  1059. s.set ("INFOPLIST_PREPROCESSOR_DEFINITIONS", indentParenthesisedList (defsList, 1));
  1060. }
  1061. if (config.isLinkTimeOptimisationEnabled())
  1062. s.set ("LLVM_LTO", "YES");
  1063. if (config.isFastMathEnabled())
  1064. s.set ("GCC_FAST_MATH", "YES");
  1065. auto flags = (config.getRecommendedCompilerWarningFlags().joinIntoString (" ")
  1066. + " " + owner.getExtraCompilerFlagsString()).trim();
  1067. flags = owner.replacePreprocessorTokens (config, flags);
  1068. if (flags.isNotEmpty())
  1069. s.set ("OTHER_CPLUSPLUSFLAGS", flags.quoted());
  1070. auto installPath = getInstallPathForConfiguration (config);
  1071. if (installPath.startsWith ("~"))
  1072. installPath = installPath.replace ("~", "$(HOME)");
  1073. if (installPath.isNotEmpty())
  1074. {
  1075. s.set ("INSTALL_PATH", installPath.quoted());
  1076. if (type == Target::SharedCodeTarget)
  1077. s.set ("SKIP_INSTALL", "YES");
  1078. if (! owner.embeddedFrameworkIDs.isEmpty())
  1079. s.set ("LD_RUNPATH_SEARCH_PATHS", "\"$(inherited) @executable_path/Frameworks @executable_path/../Frameworks\"");
  1080. if (xcodeCopyToProductInstallPathAfterBuild)
  1081. {
  1082. s.set ("DEPLOYMENT_LOCATION", "YES");
  1083. s.set ("DSTROOT", "/");
  1084. }
  1085. }
  1086. if (getTargetFileType() == pluginBundle)
  1087. {
  1088. s.set ("LIBRARY_STYLE", "Bundle");
  1089. s.set ("WRAPPER_EXTENSION", xcodeBundleExtension.substring (1));
  1090. s.set ("GENERATE_PKGINFO_FILE", "YES");
  1091. }
  1092. if (xcodeOtherRezFlags.isNotEmpty())
  1093. s.set ("OTHER_REZFLAGS", "\"" + xcodeOtherRezFlags + "\"");
  1094. String configurationBuildDir ("$(PROJECT_DIR)/build/$(CONFIGURATION)");
  1095. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  1096. {
  1097. // a target's position can either be defined via installPath + xcodeCopyToProductInstallPathAfterBuild
  1098. // (= for audio plug-ins) or using a custom binary path (for everything else), but not both (= conflict!)
  1099. jassert (! xcodeCopyToProductInstallPathAfterBuild);
  1100. build_tools::RelativePath binaryPath (config.getTargetBinaryRelativePathString(),
  1101. build_tools::RelativePath::projectFolder);
  1102. configurationBuildDir = sanitisePath (binaryPath.rebased (owner.projectFolder,
  1103. owner.getTargetFolder(),
  1104. build_tools::RelativePath::buildTargetFolder)
  1105. .toUnixStyle());
  1106. }
  1107. s.set ("CONFIGURATION_BUILD_DIR", addQuotesIfRequired (configurationBuildDir));
  1108. if (owner.isHardenedRuntimeEnabled())
  1109. s.set ("ENABLE_HARDENED_RUNTIME", "YES");
  1110. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  1111. if (owner.iOS)
  1112. {
  1113. s.set ("ASSETCATALOG_COMPILER_APPICON_NAME", "AppIcon");
  1114. if (! owner.shouldAddStoryboardToProject())
  1115. s.set ("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME", "LaunchImage");
  1116. }
  1117. else
  1118. {
  1119. s.set ("MACOSX_DEPLOYMENT_TARGET", getOSXDeploymentTarget (config.getOSXDeploymentTargetString()));
  1120. }
  1121. s.set ("GCC_VERSION", gccVersion);
  1122. s.set ("CLANG_LINK_OBJC_RUNTIME", "NO");
  1123. auto codeSigningIdentity = owner.getCodeSigningIdentity (config);
  1124. s.set (owner.iOS ? "\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\"" : "CODE_SIGN_IDENTITY",
  1125. codeSigningIdentity.quoted());
  1126. if (codeSigningIdentity.isNotEmpty())
  1127. s.set ("PROVISIONING_PROFILE_SPECIFIER", "\"\"");
  1128. if (owner.getDevelopmentTeamIDString().isNotEmpty())
  1129. s.set ("DEVELOPMENT_TEAM", owner.getDevelopmentTeamIDString());
  1130. if (shouldAddEntitlements())
  1131. s.set ("CODE_SIGN_ENTITLEMENTS", getEntitlementsFilename().quoted());
  1132. {
  1133. auto cppStandard = owner.project.getCppStandardString();
  1134. if (cppStandard == "latest")
  1135. cppStandard = "17";
  1136. s.set ("CLANG_CXX_LANGUAGE_STANDARD", (String (owner.shouldUseGNUExtensions() ? "gnu++"
  1137. : "c++") + cppStandard).quoted());
  1138. }
  1139. s.set ("CLANG_CXX_LIBRARY", "\"libc++\"");
  1140. s.set ("COMBINE_HIDPI_IMAGES", "YES");
  1141. {
  1142. StringArray linkerFlags, librarySearchPaths;
  1143. getLinkerSettings (config, linkerFlags, librarySearchPaths);
  1144. if (linkerFlags.size() > 0)
  1145. s.set ("OTHER_LDFLAGS", linkerFlags.joinIntoString (" ").quoted());
  1146. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  1147. librarySearchPaths = getCleanedStringArray (librarySearchPaths);
  1148. if (librarySearchPaths.size() > 0)
  1149. {
  1150. StringArray libPaths;
  1151. libPaths.add ("\"$(inherited)\"");
  1152. for (auto& p : librarySearchPaths)
  1153. libPaths.add ("\"\\\"" + p + "\\\"\"");
  1154. s.set ("LIBRARY_SEARCH_PATHS", indentParenthesisedList (libPaths, 1));
  1155. }
  1156. }
  1157. if (config.isDebug())
  1158. {
  1159. s.set ("COPY_PHASE_STRIP", "NO");
  1160. s.set ("GCC_DYNAMIC_NO_PIC", "NO");
  1161. }
  1162. else
  1163. {
  1164. s.set ("GCC_GENERATE_DEBUGGING_SYMBOLS", "NO");
  1165. s.set ("DEAD_CODE_STRIPPING", "YES");
  1166. }
  1167. if (type != Target::SharedCodeTarget && type != Target::StaticLibrary && type != Target::DynamicLibrary
  1168. && config.isStripLocalSymbolsEnabled())
  1169. {
  1170. s.set ("STRIPFLAGS", "\"-x\"");
  1171. s.set ("DEPLOYMENT_POSTPROCESSING", "YES");
  1172. s.set ("SEPARATE_STRIP", "YES");
  1173. }
  1174. StringArray defsList;
  1175. const auto defines = getConfigPreprocessorDefs (config);
  1176. for (int i = 0; i < defines.size(); ++i)
  1177. {
  1178. auto def = defines.getAllKeys()[i];
  1179. auto value = defines.getAllValues()[i];
  1180. if (value.isNotEmpty())
  1181. def << "=" << value.replace ("\"", "\\\\\\\"").replace (" ", "\\\\ ");
  1182. defsList.add ("\"" + def + "\"");
  1183. }
  1184. s.set ("GCC_PREPROCESSOR_DEFINITIONS", indentParenthesisedList (defsList, 1));
  1185. StringArray customFlags;
  1186. customFlags.addTokens (config.getCustomXcodeFlagsString(), ",", "\"'");
  1187. customFlags.removeEmptyStrings();
  1188. for (auto flag : customFlags)
  1189. {
  1190. s.set (flag.upToFirstOccurrenceOf ("=", false, false).trim(),
  1191. flag.fromFirstOccurrenceOf ("=", false, false).trim().quoted());
  1192. }
  1193. return s;
  1194. }
  1195. String getInstallPathForConfiguration (const XcodeBuildConfiguration& config) const
  1196. {
  1197. switch (type)
  1198. {
  1199. case GUIApp: return "$(HOME)/Applications";
  1200. case ConsoleApp: return "/usr/bin";
  1201. case VSTPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getVSTBinaryLocationString() : String();
  1202. case VST3PlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getVST3BinaryLocationString() : String();
  1203. case AudioUnitPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getAUBinaryLocationString() : String();
  1204. case RTASPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getRTASBinaryLocationString() : String();
  1205. case AAXPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getAAXBinaryLocationString() : String();
  1206. case UnityPlugIn: return config.isPluginBinaryCopyStepEnabled() ? config.getUnityPluginBinaryLocationString() : String();
  1207. case SharedCodeTarget: return owner.isiOS() ? "@executable_path/Frameworks" : "@executable_path/../Frameworks";
  1208. case StaticLibrary:
  1209. case DynamicLibrary:
  1210. case AudioUnitv3PlugIn:
  1211. case StandalonePlugIn:
  1212. case AggregateTarget:
  1213. case unspecified:
  1214. default: return {};
  1215. }
  1216. }
  1217. //==============================================================================
  1218. void getLinkerSettings (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  1219. {
  1220. if (getTargetFileType() == pluginBundle)
  1221. flags.add (owner.isiOS() ? "-bitcode_bundle" : "-bundle");
  1222. if (type != Target::SharedCodeTarget)
  1223. {
  1224. Array<build_tools::RelativePath> extraLibs;
  1225. addExtraLibsForTargetType (config, extraLibs);
  1226. for (auto& lib : extraLibs)
  1227. {
  1228. flags.add (getLinkerFlagForLib (lib.getFileNameWithoutExtension()));
  1229. librarySearchPaths.add (owner.getSearchPathForStaticLibrary (lib));
  1230. }
  1231. if (owner.project.isAudioPluginProject())
  1232. {
  1233. if (owner.getTargetOfType (Target::SharedCodeTarget) != nullptr)
  1234. {
  1235. auto productName = getStaticLibbedFilename (owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString()));
  1236. build_tools::RelativePath sharedCodelib (productName, build_tools::RelativePath::buildTargetFolder);
  1237. flags.add (getLinkerFlagForLib (sharedCodelib.getFileNameWithoutExtension()));
  1238. }
  1239. }
  1240. flags.add (owner.getExternalLibraryFlags (config));
  1241. auto libs = owner.xcodeLibs;
  1242. libs.addArray (xcodeLibs);
  1243. for (auto& l : libs)
  1244. flags.add (getLinkerFlagForLib (l));
  1245. }
  1246. flags.add (owner.replacePreprocessorTokens (config, owner.getExtraLinkerFlagsString()));
  1247. flags = getCleanedStringArray (flags);
  1248. }
  1249. //==========================================================================
  1250. void writeInfoPlistFile() const
  1251. {
  1252. if (! shouldCreatePList())
  1253. return;
  1254. build_tools::PlistOptions options;
  1255. options.type = type;
  1256. options.executableName = "${EXECUTABLE_NAME}";
  1257. options.bundleIdentifier = getBundleIdentifier();
  1258. options.plistToMerge = owner.getPListToMergeString();
  1259. options.iOS = owner.iOS;
  1260. options.microphonePermissionEnabled = owner.isMicrophonePermissionEnabled();
  1261. options.microphonePermissionText = owner.getMicrophonePermissionsTextString();
  1262. options.cameraPermissionEnabled = owner.isCameraPermissionEnabled();
  1263. options.cameraPermissionText = owner.getCameraPermissionTextString();
  1264. options.bluetoothPermissionEnabled = owner.isBluetoothPermissionEnabled();
  1265. options.bluetoothPermissionText = owner.getBluetoothPermissionTextString();
  1266. options.sendAppleEventsPermissionEnabled = owner.isSendAppleEventsPermissionEnabled();
  1267. options.sendAppleEventsPermissionText = owner.getSendAppleEventsPermissionTextString();
  1268. options.shouldAddStoryboardToProject = owner.shouldAddStoryboardToProject();
  1269. options.iconFile = owner.iconFile;
  1270. options.projectName = owner.projectName;
  1271. options.version = owner.project.getVersionString();
  1272. options.companyCopyright = owner.project.getCompanyCopyrightString();
  1273. options.allPreprocessorDefs = owner.getAllPreprocessorDefs();
  1274. options.documentExtensions = owner.getDocumentExtensionsString();
  1275. options.fileSharingEnabled = owner.isFileSharingEnabled();
  1276. options.documentBrowserEnabled = owner.isDocumentBrowserEnabled();
  1277. options.statusBarHidden = owner.isStatusBarHidden();
  1278. options.backgroundAudioEnabled = owner.isBackgroundAudioEnabled();
  1279. options.backgroundBleEnabled = owner.isBackgroundBleEnabled();
  1280. options.pushNotificationsEnabled = owner.isPushNotificationsEnabled();
  1281. options.enableIAA = owner.project.shouldEnableIAA();
  1282. options.IAAPluginName = owner.project.getIAAPluginName();
  1283. options.pluginManufacturerCode = owner.project.getPluginManufacturerCodeString();
  1284. options.IAATypeCode = owner.project.getIAATypeCode();
  1285. options.pluginCode = owner.project.getPluginCodeString();
  1286. options.versionAsHex = owner.project.getVersionAsHexInteger();
  1287. options.iPhoneScreenOrientations = owner.getiPhoneScreenOrientations();
  1288. options.iPadScreenOrientations = owner.getiPadScreenOrientations();
  1289. options.storyboardName = [&]
  1290. {
  1291. const auto customLaunchStoryboard = owner.getCustomLaunchStoryboardString();
  1292. if (customLaunchStoryboard.isEmpty())
  1293. return owner.getDefaultLaunchStoryboardName();
  1294. return customLaunchStoryboard.fromLastOccurrenceOf ("/", false, false)
  1295. .upToLastOccurrenceOf (".storyboard", false, false);
  1296. }();
  1297. options.pluginName = owner.project.getPluginNameString();
  1298. options.pluginManufacturer = owner.project.getPluginManufacturerString();
  1299. options.pluginDescription = owner.project.getPluginDescriptionString();
  1300. options.pluginAUExportPrefix = owner.project.getPluginAUExportPrefixString();
  1301. options.auMainType = owner.project.getAUMainTypeString();
  1302. options.isAuSandboxSafe = owner.project.isAUSandBoxSafe();
  1303. options.isPluginSynth = owner.project.isPluginSynth();
  1304. options.write (infoPlistFile);
  1305. }
  1306. //==============================================================================
  1307. void addShellScriptBuildPhase (const String& phaseName, const String& script)
  1308. {
  1309. if (script.trim().isNotEmpty())
  1310. {
  1311. auto& v = addBuildPhase ("PBXShellScriptBuildPhase", {});
  1312. v.setProperty (Ids::name, phaseName, nullptr);
  1313. v.setProperty ("shellPath", "/bin/sh", nullptr);
  1314. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  1315. .replace ("\"", "\\\"")
  1316. .replace ("\r\n", "\\n")
  1317. .replace ("\n", "\\n"), nullptr);
  1318. }
  1319. }
  1320. void addCopyFilesPhase (const String& phaseName, const StringArray& files, XcodeCopyFilesDestinationIDs dst)
  1321. {
  1322. auto& v = addBuildPhase ("PBXCopyFilesBuildPhase", files, phaseName);
  1323. v.setProperty ("dstPath", "", nullptr);
  1324. v.setProperty ("dstSubfolderSpec", (int) dst, nullptr);
  1325. }
  1326. //==============================================================================
  1327. void sanitiseAndEscapeSearchPaths (const BuildConfiguration& config, StringArray& paths) const
  1328. {
  1329. paths = getCleanedStringArray (paths);
  1330. for (auto& path : paths)
  1331. {
  1332. // Xcode 10 can't deal with search paths starting with "~" so we need to replace them here...
  1333. path = owner.replacePreprocessorTokens (config, sanitisePath (path));
  1334. if (path.containsChar (' '))
  1335. path = "\"\\\"" + path + "\\\"\""; // crazy double quotes required when there are spaces..
  1336. else
  1337. path = "\"" + path + "\"";
  1338. }
  1339. }
  1340. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1341. {
  1342. StringArray paths (owner.extraSearchPaths);
  1343. paths.addArray (config.getHeaderSearchPaths());
  1344. paths.addArray (getTargetExtraHeaderSearchPaths());
  1345. if (owner.project.getEnabledModules().isModuleEnabled ("juce_audio_plugin_client"))
  1346. {
  1347. // Needed to compile .r files
  1348. paths.add (owner.getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  1349. .rebased (owner.projectFolder, owner.getTargetFolder(), build_tools::RelativePath::buildTargetFolder)
  1350. .toUnixStyle());
  1351. }
  1352. sanitiseAndEscapeSearchPaths (config, paths);
  1353. return paths;
  1354. }
  1355. StringArray getFrameworkSearchPaths (const BuildConfiguration& config) const
  1356. {
  1357. auto paths = getSearchPathsFromString (owner.getFrameworkSearchPathsString());
  1358. sanitiseAndEscapeSearchPaths (config, paths);
  1359. return paths;
  1360. }
  1361. private:
  1362. //==============================================================================
  1363. void addExtraAudioUnitTargetSettings()
  1364. {
  1365. xcodeOtherRezFlags = "-d ppc_$ppc -d i386_$i386 -d ppc64_$ppc64 -d x86_64_$x86_64"
  1366. " -I /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Versions/A/Headers"
  1367. " -I \\\"$(DEVELOPER_DIR)/Extras/CoreAudio/AudioUnits/AUPublic/AUBase\\\""
  1368. " -I \\\"$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioUnit.framework/Headers\\\"";
  1369. xcodeFrameworks.addArray ({ "AudioUnit", "CoreAudioKit" });
  1370. }
  1371. void addExtraAudioUnitv3PlugInTargetSettings()
  1372. {
  1373. xcodeFrameworks.addArray ({ "AVFoundation", "CoreAudioKit" });
  1374. if (owner.isOSX())
  1375. xcodeFrameworks.add ("AudioUnit");
  1376. }
  1377. void addExtraLibsForTargetType (const BuildConfiguration& config, Array<build_tools::RelativePath>& extraLibs) const
  1378. {
  1379. if (type == AAXPlugIn)
  1380. {
  1381. auto aaxLibsFolder = build_tools::RelativePath (owner.getAAXPathString(), build_tools::RelativePath::projectFolder).getChildFile ("Libs");
  1382. String libraryPath (config.isDebug() ? "Debug" : "Release");
  1383. libraryPath += "/libAAXLibrary_libcpp.a";
  1384. extraLibs.add (aaxLibsFolder.getChildFile (libraryPath));
  1385. }
  1386. else if (type == RTASPlugIn)
  1387. {
  1388. build_tools::RelativePath rtasFolder (owner.getRTASPathString(), build_tools::RelativePath::projectFolder);
  1389. extraLibs.add (rtasFolder.getChildFile ("MacBag/Libs/Debug/libPluginLibrary.a"));
  1390. extraLibs.add (rtasFolder.getChildFile ("MacBag/Libs/Release/libPluginLibrary.a"));
  1391. }
  1392. }
  1393. StringArray getTargetExtraHeaderSearchPaths() const
  1394. {
  1395. StringArray targetExtraSearchPaths;
  1396. if (type == RTASPlugIn)
  1397. {
  1398. build_tools::RelativePath rtasFolder (owner.getRTASPathString(), build_tools::RelativePath::projectFolder);
  1399. targetExtraSearchPaths.add ("$(DEVELOPER_DIR)/Headers/FlatCarbon");
  1400. targetExtraSearchPaths.add ("$(SDKROOT)/Developer/Headers/FlatCarbon");
  1401. static const char* p[] = { "AlturaPorts/TDMPlugIns/PlugInLibrary/Controls",
  1402. "AlturaPorts/TDMPlugIns/PlugInLibrary/CoreClasses",
  1403. "AlturaPorts/TDMPlugIns/PlugInLibrary/DSPClasses",
  1404. "AlturaPorts/TDMPlugIns/PlugInLibrary/EffectClasses",
  1405. "AlturaPorts/TDMPlugIns/PlugInLibrary/MacBuild",
  1406. "AlturaPorts/TDMPlugIns/PlugInLibrary/Meters",
  1407. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses",
  1408. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses/Interfaces",
  1409. "AlturaPorts/TDMPlugIns/PlugInLibrary/RTASP_Adapt",
  1410. "AlturaPorts/TDMPlugIns/PlugInLibrary/Utilities",
  1411. "AlturaPorts/TDMPlugIns/PlugInLibrary/ViewClasses",
  1412. "AlturaPorts/TDMPlugIns/DSPManager/**",
  1413. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/Encryption",
  1414. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/GraphicsExtensions",
  1415. "AlturaPorts/TDMPlugIns/common/**",
  1416. "AlturaPorts/TDMPlugIns/common/PI_LibInterface",
  1417. "AlturaPorts/TDMPlugIns/PACEProtection/**",
  1418. "AlturaPorts/TDMPlugIns/SignalProcessing/**",
  1419. "AlturaPorts/OMS/Headers",
  1420. "AlturaPorts/Fic/Interfaces/**",
  1421. "AlturaPorts/Fic/Source/SignalNets",
  1422. "AlturaPorts/DSIPublicInterface/PublicHeaders",
  1423. "DAEWin/Include",
  1424. "AlturaPorts/DigiPublic/Interfaces",
  1425. "AlturaPorts/DigiPublic",
  1426. "AlturaPorts/NewFileLibs/DOA",
  1427. "AlturaPorts/NewFileLibs/Cmn",
  1428. "xplat/AVX/avx2/avx2sdk/inc",
  1429. "xplat/AVX/avx2/avx2sdk/utils" };
  1430. for (auto* path : p)
  1431. owner.addProjectPathToBuildPathList (targetExtraSearchPaths, rtasFolder.getChildFile (path));
  1432. }
  1433. return targetExtraSearchPaths;
  1434. }
  1435. String getOSXDeploymentTarget (const String& deploymentTarget) const
  1436. {
  1437. auto minVersion = (type == Target::AudioUnitv3PlugIn ? minimumAUv3SDKVersion : oldestDeploymentTarget);
  1438. for (int v = minVersion; v <= currentSDKVersion; ++v)
  1439. if (deploymentTarget == getSDKDisplayName (v))
  1440. return getVersionName (v);
  1441. return getVersionName (minVersion);
  1442. }
  1443. //==============================================================================
  1444. const XcodeProjectExporter& owner;
  1445. Target& operator= (const Target&) = delete;
  1446. };
  1447. mutable StringArray xcodeFrameworks;
  1448. StringArray xcodeLibs;
  1449. private:
  1450. //==============================================================================
  1451. friend class CLionProjectExporter;
  1452. bool xcodeCanUseDwarf;
  1453. OwnedArray<XcodeTarget> targets;
  1454. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  1455. mutable StringArray resourceIDs, sourceIDs, targetIDs;
  1456. mutable StringArray frameworkFileIDs, embeddedFrameworkIDs, rezFileIDs, resourceFileRefs, subprojectFileIDs;
  1457. mutable Array<std::pair<String, String>> subprojectReferences;
  1458. mutable File menuNibFile, iconFile;
  1459. mutable StringArray buildProducts;
  1460. const bool iOS;
  1461. ValueWithDefault customPListValue, pListPrefixHeaderValue, pListPreprocessValue,
  1462. subprojectsValue,
  1463. extraFrameworksValue, frameworkSearchPathsValue, extraCustomFrameworksValue, embeddedFrameworksValue,
  1464. postbuildCommandValue, prebuildCommandValue,
  1465. duplicateAppExResourcesFolderValue, iosDeviceFamilyValue, iPhoneScreenOrientationValue,
  1466. iPadScreenOrientationValue, customXcodeResourceFoldersValue, customXcassetsFolderValue,
  1467. appSandboxValue, appSandboxInheritanceValue, appSandboxOptionsValue,
  1468. hardenedRuntimeValue, hardenedRuntimeOptionsValue,
  1469. microphonePermissionNeededValue, microphonePermissionsTextValue,
  1470. cameraPermissionNeededValue, cameraPermissionTextValue,
  1471. iosBluetoothPermissionNeededValue, iosBluetoothPermissionTextValue,
  1472. sendAppleEventsPermissionNeededValue, sendAppleEventsPermissionTextValue,
  1473. uiFileSharingEnabledValue, uiSupportsDocumentBrowserValue, uiStatusBarHiddenValue, documentExtensionsValue, iosInAppPurchasesValue,
  1474. iosContentSharingValue, iosBackgroundAudioValue, iosBackgroundBleValue, iosPushNotificationsValue, iosAppGroupsValue, iCloudPermissionsValue,
  1475. iosDevelopmentTeamIDValue, iosAppGroupsIDValue, keepCustomXcodeSchemesValue, useHeaderMapValue, customLaunchStoryboardValue,
  1476. exporterBundleIdentifierValue;
  1477. static String sanitisePath (const String& path)
  1478. {
  1479. if (path.startsWithChar ('~'))
  1480. return "$(HOME)" + path.substring (1);
  1481. return path;
  1482. }
  1483. static String addQuotesIfRequired (const String& s)
  1484. {
  1485. return s.containsAnyOf (" $") ? s.quoted() : s;
  1486. }
  1487. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRootString()).withFileExtension (".xcodeproj"); }
  1488. //==============================================================================
  1489. void createObjects() const
  1490. {
  1491. prepareTargets();
  1492. // Must be called before adding embedded frameworks, as we want to
  1493. // embed any frameworks found in subprojects.
  1494. addSubprojects();
  1495. addFrameworks();
  1496. addCustomFrameworks();
  1497. addEmbeddedFrameworks();
  1498. addCustomResourceFolders();
  1499. addPlistFileReferences();
  1500. if (iOS && ! projectType.isStaticLibrary())
  1501. {
  1502. addXcassets();
  1503. if (shouldAddStoryboardToProject())
  1504. {
  1505. auto customLaunchStoryboard = getCustomLaunchStoryboardString();
  1506. if (customLaunchStoryboard.isEmpty())
  1507. writeDefaultLaunchStoryboardFile();
  1508. else if (getProject().getProjectFolder().getChildFile (customLaunchStoryboard).existsAsFile())
  1509. addLaunchStoryboardFileReference (build_tools::RelativePath (customLaunchStoryboard, build_tools::RelativePath::projectFolder)
  1510. .rebased (getProject().getProjectFolder(), getTargetFolder(), build_tools::RelativePath::buildTargetFolder)
  1511. .toUnixStyle());
  1512. }
  1513. }
  1514. else
  1515. {
  1516. addNibFiles();
  1517. }
  1518. addIcons();
  1519. addBuildConfigurations();
  1520. addProjectConfigList (projectConfigs, createID ("__projList"));
  1521. {
  1522. StringArray topLevelGroupIDs;
  1523. addFilesAndGroupsToProject (topLevelGroupIDs);
  1524. addBuildPhases();
  1525. addExtraGroupsToProject (topLevelGroupIDs);
  1526. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  1527. }
  1528. addProjectObject();
  1529. removeMismatchedXcuserdata();
  1530. }
  1531. void prepareTargets() const
  1532. {
  1533. for (auto* target : targets)
  1534. {
  1535. if (target->type == XcodeTarget::AggregateTarget)
  1536. continue;
  1537. target->addMainBuildProduct();
  1538. auto targetName = target->getName();
  1539. auto fileID = createID (targetName + String ("__targetbuildref"));
  1540. auto fileRefID = createID (String ("__productFileID") + targetName);
  1541. auto* v = new ValueTree (fileID);
  1542. v->setProperty ("isa", "PBXBuildFile", nullptr);
  1543. v->setProperty ("fileRef", fileRefID, nullptr);
  1544. target->mainBuildProductID = fileID;
  1545. pbxBuildFiles.add (v);
  1546. target->addDependency();
  1547. }
  1548. }
  1549. void addPlistFileReferences() const
  1550. {
  1551. for (auto* target : targets)
  1552. {
  1553. if (target->type == XcodeTarget::AggregateTarget)
  1554. continue;
  1555. if (target->shouldCreatePList())
  1556. {
  1557. build_tools::RelativePath plistPath (target->infoPlistFile, getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  1558. addFileReference (plistPath.toUnixStyle());
  1559. resourceFileRefs.add (createFileRefID (plistPath));
  1560. }
  1561. }
  1562. }
  1563. void addNibFiles() const
  1564. {
  1565. build_tools::writeStreamToFile (menuNibFile, [&] (MemoryOutputStream& mo)
  1566. {
  1567. mo.write (BinaryData::RecentFilesMenuTemplate_nib, BinaryData::RecentFilesMenuTemplate_nibSize);
  1568. });
  1569. build_tools::RelativePath menuNibPath (menuNibFile, getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  1570. addFileReference (menuNibPath.toUnixStyle());
  1571. resourceIDs.add (addBuildFile (menuNibPath, false, false));
  1572. resourceFileRefs.add (createFileRefID (menuNibPath));
  1573. }
  1574. void addIcons() const
  1575. {
  1576. if (iconFile.exists())
  1577. {
  1578. build_tools::RelativePath iconPath (iconFile, getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  1579. addFileReference (iconPath.toUnixStyle());
  1580. resourceIDs.add (addBuildFile (iconPath, false, false));
  1581. resourceFileRefs.add (createFileRefID (iconPath));
  1582. }
  1583. }
  1584. void addBuildConfigurations() const
  1585. {
  1586. for (ConstConfigIterator config (*this); config.next();)
  1587. {
  1588. auto& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1589. StringArray settingsLines;
  1590. auto configSettings = getProjectSettings (xcodeConfig);
  1591. for (auto& key : configSettings.getAllKeys())
  1592. settingsLines.add (key + " = " + configSettings[key]);
  1593. addProjectConfig (config->getName(), settingsLines);
  1594. }
  1595. }
  1596. void addFilesAndGroupsToProject (StringArray& topLevelGroupIDs) const
  1597. {
  1598. for (auto* target : targets)
  1599. if (target->shouldAddEntitlements())
  1600. addEntitlementsFile (*target);
  1601. for (auto& group : getAllGroups())
  1602. {
  1603. if (group.getNumChildren() > 0)
  1604. {
  1605. auto groupID = addProjectItem (group);
  1606. if (groupID.isNotEmpty())
  1607. topLevelGroupIDs.add (groupID);
  1608. }
  1609. }
  1610. }
  1611. void addExtraGroupsToProject (StringArray& topLevelGroupIDs) const
  1612. {
  1613. {
  1614. auto resourcesGroupID = createID ("__resources");
  1615. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  1616. topLevelGroupIDs.add (resourcesGroupID);
  1617. }
  1618. {
  1619. auto frameworksGroupID = createID ("__frameworks");
  1620. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  1621. topLevelGroupIDs.add (frameworksGroupID);
  1622. }
  1623. {
  1624. auto productsGroupID = createID ("__products");
  1625. addGroup (productsGroupID, "Products", buildProducts);
  1626. topLevelGroupIDs.add (productsGroupID);
  1627. }
  1628. if (! subprojectFileIDs.isEmpty())
  1629. {
  1630. auto subprojectLibrariesGroupID = createID ("__subprojects");
  1631. addGroup (subprojectLibrariesGroupID, "Subprojects", subprojectFileIDs);
  1632. topLevelGroupIDs.add (subprojectLibrariesGroupID);
  1633. }
  1634. }
  1635. void addBuildPhases() const
  1636. {
  1637. // add build phases
  1638. for (auto* target : targets)
  1639. {
  1640. if (target->type != XcodeTarget::AggregateTarget)
  1641. buildProducts.add (createID (String ("__productFileID") + String (target->getName())));
  1642. for (ConstConfigIterator config (*this); config.next();)
  1643. {
  1644. auto& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1645. auto configSettings = target->getTargetSettings (xcodeConfig);
  1646. StringArray settingsLines;
  1647. for (auto& key : configSettings.getAllKeys())
  1648. settingsLines.add (key + " = " + configSettings.getValue (key, "\"\""));
  1649. target->addTargetConfig (config->getName(), settingsLines);
  1650. }
  1651. addConfigList (*target, targetConfigs, createID (String ("__configList") + target->getName()));
  1652. target->addShellScriptBuildPhase ("Pre-build script", getPreBuildScript());
  1653. if (target->type != XcodeTarget::AggregateTarget)
  1654. {
  1655. auto skipAUv3 = (target->type == XcodeTarget::AudioUnitv3PlugIn && ! shouldDuplicateAppExResourcesFolder());
  1656. if (! projectType.isStaticLibrary() && target->type != XcodeTarget::SharedCodeTarget && ! skipAUv3)
  1657. target->addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  1658. auto rezFiles = rezFileIDs;
  1659. rezFiles.addArray (target->rezFileIDs);
  1660. if (rezFiles.size() > 0)
  1661. target->addBuildPhase ("PBXRezBuildPhase", rezFiles);
  1662. auto sourceFiles = target->sourceIDs;
  1663. if (target->type == XcodeTarget::SharedCodeTarget
  1664. || (! project.isAudioPluginProject()))
  1665. sourceFiles.addArray (sourceIDs);
  1666. target->addBuildPhase ("PBXSourcesBuildPhase", sourceFiles);
  1667. if (! projectType.isStaticLibrary() && target->type != XcodeTarget::SharedCodeTarget)
  1668. target->addBuildPhase ("PBXFrameworksBuildPhase", target->frameworkIDs);
  1669. }
  1670. target->addShellScriptBuildPhase ("Post-build script", getPostBuildScript());
  1671. if (project.isAudioPluginProject() && project.shouldBuildAUv3()
  1672. && project.shouldBuildStandalonePlugin() && target->type == XcodeTarget::StandalonePlugIn)
  1673. embedAppExtension();
  1674. if (project.isAudioPluginProject() && project.shouldBuildUnityPlugin()
  1675. && target->type == XcodeTarget::UnityPlugIn)
  1676. embedUnityScript();
  1677. addTargetObject (*target);
  1678. }
  1679. }
  1680. void embedAppExtension() const
  1681. {
  1682. if (auto* standaloneTarget = getTargetOfType (XcodeTarget::StandalonePlugIn))
  1683. {
  1684. if (auto* auv3Target = getTargetOfType (XcodeTarget::AudioUnitv3PlugIn))
  1685. {
  1686. StringArray files;
  1687. files.add (auv3Target->mainBuildProductID);
  1688. standaloneTarget->addCopyFilesPhase ("Embed App Extensions", files, kPluginsFolder);
  1689. }
  1690. }
  1691. }
  1692. void embedUnityScript() const
  1693. {
  1694. if (auto* unityTarget = getTargetOfType (XcodeTarget::UnityPlugIn))
  1695. {
  1696. build_tools::RelativePath scriptPath (getProject().getGeneratedCodeFolder().getChildFile (getProject().getUnityScriptName()),
  1697. getTargetFolder(),
  1698. build_tools::RelativePath::buildTargetFolder);
  1699. auto path = scriptPath.toUnixStyle();
  1700. auto refID = addFileReference (path);
  1701. auto fileID = addBuildFile (path, refID, false, false);
  1702. resourceIDs.add (fileID);
  1703. resourceFileRefs.add (refID);
  1704. unityTarget->addCopyFilesPhase ("Embed Unity Script", fileID, kResourcesFolder);
  1705. }
  1706. }
  1707. //==============================================================================
  1708. XcodeTarget* getTargetOfType (build_tools::ProjectType::Target::Type type) const
  1709. {
  1710. for (auto& target : targets)
  1711. if (target->type == type)
  1712. return target;
  1713. return nullptr;
  1714. }
  1715. void addTargetObject (XcodeTarget& target) const
  1716. {
  1717. auto targetName = target.getName();
  1718. auto targetID = target.getID();
  1719. auto* v = new ValueTree (targetID);
  1720. v->setProperty ("isa", target.type == XcodeTarget::AggregateTarget ? "PBXAggregateTarget" : "PBXNativeTarget", nullptr);
  1721. v->setProperty ("buildConfigurationList", createID (String ("__configList") + targetName), nullptr);
  1722. v->setProperty ("buildPhases", indentParenthesisedList (target.buildPhaseIDs), nullptr);
  1723. v->setProperty ("buildRules", "( )", nullptr);
  1724. v->setProperty ("dependencies", indentParenthesisedList (getTargetDependencies (target)), nullptr);
  1725. v->setProperty (Ids::name, target.getXcodeSchemeName(), nullptr);
  1726. v->setProperty ("productName", projectName, nullptr);
  1727. if (target.type != XcodeTarget::AggregateTarget)
  1728. {
  1729. v->setProperty ("productReference", createID (String ("__productFileID") + targetName), nullptr);
  1730. jassert (target.xcodeProductType.isNotEmpty());
  1731. v->setProperty ("productType", target.xcodeProductType, nullptr);
  1732. }
  1733. targetIDs.add (targetID);
  1734. misc.add (v);
  1735. }
  1736. StringArray getTargetDependencies (const XcodeTarget& target) const
  1737. {
  1738. StringArray dependencies;
  1739. if (project.isAudioPluginProject())
  1740. {
  1741. if (target.type == XcodeTarget::StandalonePlugIn) // depends on AUv3 and shared code
  1742. {
  1743. if (auto* auv3Target = getTargetOfType (XcodeTarget::AudioUnitv3PlugIn))
  1744. dependencies.add (auv3Target->getDependencyID());
  1745. if (auto* sharedCodeTarget = getTargetOfType (XcodeTarget::SharedCodeTarget))
  1746. dependencies.add (sharedCodeTarget->getDependencyID());
  1747. }
  1748. else if (target.type == XcodeTarget::AggregateTarget) // depends on all other targets
  1749. {
  1750. for (int i = 1; i < targets.size(); ++i)
  1751. dependencies.add (targets[i]->getDependencyID());
  1752. }
  1753. else if (target.type != XcodeTarget::SharedCodeTarget) // shared code doesn't depend on anything; all other targets depend only on the shared code
  1754. {
  1755. if (auto* sharedCodeTarget = getTargetOfType (XcodeTarget::SharedCodeTarget))
  1756. dependencies.add (sharedCodeTarget->getDependencyID());
  1757. }
  1758. }
  1759. return dependencies;
  1760. }
  1761. void createIconFile() const
  1762. {
  1763. const auto icons = getIcons();
  1764. if (! build_tools::asArray (icons).isEmpty())
  1765. {
  1766. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  1767. build_tools::writeMacIcon (icons, iconFile);
  1768. }
  1769. }
  1770. void writeWorkspaceSettings() const
  1771. {
  1772. const auto settingsFile = getProjectBundle().getChildFile ("project.xcworkspace")
  1773. .getChildFile ("xcshareddata")
  1774. .getChildFile ("WorkspaceSettings.xcsettings");
  1775. build_tools::writeStreamToFile (settingsFile, [] (MemoryOutputStream& mo)
  1776. {
  1777. mo.setNewLineString ("\n");
  1778. mo << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << newLine
  1779. << "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" << newLine
  1780. << "<plist version=\"1.0\">" << newLine
  1781. << "<dict>" << newLine
  1782. << "\t" << "<key>BuildSystemType</key>" << newLine
  1783. << "\t" << "<string>Original</string>" << newLine
  1784. << "</dict>" << newLine
  1785. << "</plist>" << newLine;
  1786. });
  1787. }
  1788. void writeInfoPlistFiles() const
  1789. {
  1790. for (auto& target : targets)
  1791. target->writeInfoPlistFile();
  1792. }
  1793. // Delete .rsrc files in folder but don't follow sym-links
  1794. void deleteRsrcFiles (const File& folder) const
  1795. {
  1796. for (const auto& di : RangedDirectoryIterator (folder, false, "*", File::findFilesAndDirectories))
  1797. {
  1798. const auto& entry = di.getFile();
  1799. if (! entry.isSymbolicLink())
  1800. {
  1801. if (entry.existsAsFile() && entry.getFileExtension().toLowerCase() == ".rsrc")
  1802. entry.deleteFile();
  1803. else if (entry.isDirectory())
  1804. deleteRsrcFiles (entry);
  1805. }
  1806. }
  1807. }
  1808. static String getLinkerFlagForLib (String library)
  1809. {
  1810. if (library.substring (0, 3) == "lib")
  1811. library = library.substring (3);
  1812. return "-l" + library.replace (" ", "\\\\ ").replace ("\"", "\\\\\"").replace ("\'", "\\\\\'").upToLastOccurrenceOf (".", false, false);
  1813. }
  1814. String getSearchPathForStaticLibrary (const build_tools::RelativePath& library) const
  1815. {
  1816. auto searchPath = library.toUnixStyle().upToLastOccurrenceOf ("/", false, false);
  1817. if (! library.isAbsolute())
  1818. {
  1819. auto srcRoot = rebaseFromProjectFolderToBuildTarget (build_tools::RelativePath (".", build_tools::RelativePath::projectFolder)).toUnixStyle();
  1820. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  1821. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  1822. searchPath = srcRoot + searchPath;
  1823. }
  1824. return sanitisePath (searchPath);
  1825. }
  1826. String getCodeSigningIdentity (const XcodeBuildConfiguration& config) const
  1827. {
  1828. auto identity = config.getCodeSignIdentityString();
  1829. if (identity.isEmpty() && getDevelopmentTeamIDString().isNotEmpty())
  1830. return iOS ? "iPhone Developer" : "Mac Developer";
  1831. return identity;
  1832. }
  1833. StringPairArray getProjectSettings (const XcodeBuildConfiguration& config) const
  1834. {
  1835. StringPairArray s;
  1836. s.set ("ALWAYS_SEARCH_USER_PATHS", "NO");
  1837. s.set ("ENABLE_STRICT_OBJC_MSGSEND", "YES");
  1838. s.set ("GCC_C_LANGUAGE_STANDARD", "c11");
  1839. s.set ("GCC_NO_COMMON_BLOCKS", "YES");
  1840. s.set ("GCC_MODEL_TUNING", "G5");
  1841. s.set ("GCC_WARN_ABOUT_RETURN_TYPE", "YES");
  1842. s.set ("GCC_WARN_CHECK_SWITCH_STATEMENTS", "YES");
  1843. s.set ("GCC_WARN_UNUSED_VARIABLE", "YES");
  1844. s.set ("GCC_WARN_MISSING_PARENTHESES", "YES");
  1845. s.set ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR", "YES");
  1846. s.set ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF", "YES");
  1847. s.set ("GCC_WARN_64_TO_32_BIT_CONVERSION", "YES");
  1848. s.set ("GCC_WARN_UNDECLARED_SELECTOR", "YES");
  1849. s.set ("GCC_WARN_UNINITIALIZED_AUTOS", "YES");
  1850. s.set ("GCC_WARN_UNUSED_FUNCTION", "YES");
  1851. s.set ("CLANG_ENABLE_OBJC_WEAK", "YES");
  1852. s.set ("CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING", "YES");
  1853. s.set ("CLANG_WARN_BOOL_CONVERSION", "YES");
  1854. s.set ("CLANG_WARN_COMMA", "YES");
  1855. s.set ("CLANG_WARN_CONSTANT_CONVERSION", "YES");
  1856. s.set ("CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS", "YES");
  1857. s.set ("CLANG_WARN_EMPTY_BODY", "YES");
  1858. s.set ("CLANG_WARN_ENUM_CONVERSION", "YES");
  1859. s.set ("CLANG_WARN_INFINITE_RECURSION", "YES");
  1860. s.set ("CLANG_WARN_INT_CONVERSION", "YES");
  1861. s.set ("CLANG_WARN_NON_LITERAL_NULL_CONVERSION", "YES");
  1862. s.set ("CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF", "YES");
  1863. s.set ("CLANG_WARN_OBJC_LITERAL_CONVERSION", "YES");
  1864. s.set ("CLANG_WARN_RANGE_LOOP_ANALYSIS", "YES");
  1865. s.set ("CLANG_WARN_STRICT_PROTOTYPES", "YES");
  1866. s.set ("CLANG_WARN_SUSPICIOUS_MOVE", "YES");
  1867. s.set ("CLANG_WARN_UNREACHABLE_CODE", "YES");
  1868. s.set ("CLANG_WARN__DUPLICATE_METHOD_MATCH", "YES");
  1869. s.set ("WARNING_CFLAGS", "\"-Wreorder\"");
  1870. s.set ("GCC_INLINES_ARE_PRIVATE_EXTERN", projectType.isStaticLibrary() ? "NO" : "YES");
  1871. // GCC_SYMBOLS_PRIVATE_EXTERN only takes effect if ENABLE_TESTABILITY is off
  1872. s.set ("ENABLE_TESTABILITY", "NO");
  1873. s.set ("GCC_SYMBOLS_PRIVATE_EXTERN", "YES");
  1874. if (config.isDebug())
  1875. {
  1876. if (config.getOSXArchitectureString() == osxArch_Default)
  1877. s.set ("ONLY_ACTIVE_ARCH", "YES");
  1878. }
  1879. s.set (iOS ? "\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\"" : "CODE_SIGN_IDENTITY",
  1880. getCodeSigningIdentity (config).quoted());
  1881. if (iOS)
  1882. {
  1883. s.set ("SDKROOT", "iphoneos");
  1884. s.set ("TARGETED_DEVICE_FAMILY", getDeviceFamilyString().quoted());
  1885. s.set ("IPHONEOS_DEPLOYMENT_TARGET", config.getiOSDeploymentTargetString());
  1886. }
  1887. else
  1888. {
  1889. s.set ("SDKROOT", getOSXSDKVersion (config.getOSXSDKVersionString()));
  1890. }
  1891. s.set ("ZERO_LINK", "NO");
  1892. if (xcodeCanUseDwarf)
  1893. s.set ("DEBUG_INFORMATION_FORMAT", "dwarf");
  1894. s.set ("PRODUCT_NAME", replacePreprocessorTokens (config, config.getTargetBinaryNameString()).quoted());
  1895. return s;
  1896. }
  1897. void addFrameworks() const
  1898. {
  1899. if (! projectType.isStaticLibrary())
  1900. {
  1901. if (isInAppPurchasesEnabled())
  1902. xcodeFrameworks.addIfNotAlreadyThere ("StoreKit");
  1903. if (iOS && isPushNotificationsEnabled())
  1904. xcodeFrameworks.addIfNotAlreadyThere ("UserNotifications");
  1905. if (iOS
  1906. && project.getEnabledModules().isModuleEnabled ("juce_video")
  1907. && project.isConfigFlagEnabled ("JUCE_USE_CAMERA", false))
  1908. {
  1909. xcodeFrameworks.addIfNotAlreadyThere ("ImageIO");
  1910. }
  1911. xcodeFrameworks.addTokens (getExtraFrameworksString(), ",;", "\"'");
  1912. xcodeFrameworks.trim();
  1913. auto s = xcodeFrameworks;
  1914. for (auto& target : targets)
  1915. s.addArray (target->xcodeFrameworks);
  1916. if (! project.getConfigFlag ("JUCE_QUICKTIME").get())
  1917. s.removeString ("QuickTime");
  1918. s.trim();
  1919. s.removeDuplicates (true);
  1920. s.sort (true);
  1921. // When building against the 10.15 SDK we need to make sure the
  1922. // AudioUnit framework is linked before the AudioToolbox framework.
  1923. auto audioUnitIndex = s.indexOf ("AudioUnit", false, 1);
  1924. if (audioUnitIndex != -1)
  1925. {
  1926. s.remove (audioUnitIndex);
  1927. s.insert (0, "AudioUnit");
  1928. }
  1929. for (auto& framework : s)
  1930. {
  1931. auto frameworkID = addFramework (framework);
  1932. // find all the targets that are referring to this object
  1933. for (auto& target : targets)
  1934. {
  1935. if (xcodeFrameworks.contains (framework) || target->xcodeFrameworks.contains (framework))
  1936. {
  1937. target->frameworkIDs.add (frameworkID);
  1938. target->frameworkNames.add (framework);
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. void addCustomFrameworks() const
  1945. {
  1946. StringArray customFrameworks;
  1947. customFrameworks.addTokens (getExtraCustomFrameworksString(), true);
  1948. customFrameworks.trim();
  1949. for (auto& framework : customFrameworks)
  1950. {
  1951. auto frameworkID = addCustomFramework (framework);
  1952. for (auto& target : targets)
  1953. {
  1954. target->frameworkIDs.add (frameworkID);
  1955. target->frameworkNames.add (framework);
  1956. }
  1957. }
  1958. }
  1959. void addEmbeddedFrameworks() const
  1960. {
  1961. StringArray frameworks;
  1962. frameworks.addTokens (getEmbeddedFrameworksString(), true);
  1963. frameworks.trim();
  1964. for (auto& framework : frameworks)
  1965. {
  1966. auto frameworkID = addEmbeddedFramework (framework);
  1967. embeddedFrameworkIDs.add (frameworkID);
  1968. for (auto& target : targets)
  1969. {
  1970. target->frameworkIDs.add (frameworkID);
  1971. target->frameworkNames.add (framework);
  1972. }
  1973. }
  1974. if (! embeddedFrameworkIDs.isEmpty())
  1975. for (auto& target : targets)
  1976. target->addCopyFilesPhase ("Embed Frameworks", embeddedFrameworkIDs, kFrameworksFolder);
  1977. }
  1978. void addCustomResourceFolders() const
  1979. {
  1980. StringArray folders;
  1981. folders.addTokens (getCustomResourceFoldersString(), ":", "");
  1982. folders.trim();
  1983. folders.removeEmptyStrings();
  1984. for (auto& crf : folders)
  1985. addCustomResourceFolder (crf);
  1986. }
  1987. void addSubprojects() const
  1988. {
  1989. auto subprojectLines = StringArray::fromLines (getSubprojectsString());
  1990. subprojectLines.removeEmptyStrings (true);
  1991. Array<std::pair<String, StringArray>> subprojects;
  1992. for (auto& line : subprojectLines)
  1993. {
  1994. String subprojectName (line.upToFirstOccurrenceOf (":", false, false));
  1995. StringArray requestedBuildProducts (StringArray::fromTokens (line.fromFirstOccurrenceOf (":", false, false), ",;|", "\"'"));
  1996. requestedBuildProducts.trim();
  1997. subprojects.add ({ subprojectName, requestedBuildProducts });
  1998. }
  1999. for (const auto& subprojectInfo : subprojects)
  2000. {
  2001. String subprojectPath (subprojectInfo.first);
  2002. if (! subprojectPath.endsWith (".xcodeproj"))
  2003. subprojectPath += ".xcodeproj";
  2004. File subprojectFile = File::isAbsolutePath (subprojectPath) ? subprojectPath
  2005. : getTargetFolder().getChildFile (subprojectPath);
  2006. if (! subprojectFile.isDirectory())
  2007. continue;
  2008. auto availableBuildProducts = XcodeProjectParser::parseBuildProducts (subprojectFile);
  2009. // If no build products have been specified then we'll take everything
  2010. if (! subprojectInfo.second.isEmpty())
  2011. {
  2012. auto newEnd = std::remove_if (availableBuildProducts.begin(), availableBuildProducts.end(),
  2013. [&subprojectInfo](const std::pair<String, String> &item)
  2014. {
  2015. return ! subprojectInfo.second.contains (item.first);
  2016. });
  2017. availableBuildProducts.erase (newEnd, availableBuildProducts.end());
  2018. }
  2019. if (availableBuildProducts.empty())
  2020. continue;
  2021. auto subprojectFileType = getFileType (build_tools::RelativePath (subprojectFile.getFullPathName(), build_tools::RelativePath::buildTargetFolder));
  2022. auto subprojectFileID = addFileOrFolderReference (subprojectFile.getFullPathName(), "<group>", subprojectFileType);
  2023. subprojectFileIDs.add (subprojectFileID);
  2024. StringArray proxyIDs;
  2025. for (auto& buildProduct : availableBuildProducts)
  2026. {
  2027. auto buildProductFileType = getFileType (build_tools::RelativePath (buildProduct.second, build_tools::RelativePath::projectFolder));
  2028. auto containerID = addContainerItemProxy (subprojectFileID, buildProduct.first);
  2029. auto proxyID = addReferenceProxy (containerID, buildProduct.second, buildProductFileType);
  2030. proxyIDs.add (proxyID);
  2031. if (buildProductFileType == "archive.ar" || buildProductFileType == "wrapper.framework")
  2032. {
  2033. auto buildFileID = addBuildFile (buildProduct.second, proxyID, false, true);
  2034. for (auto& target : targets)
  2035. target->frameworkIDs.add (buildFileID);
  2036. if (buildProductFileType == "wrapper.framework")
  2037. {
  2038. auto fileID = createID (buildProduct.second + "buildref");
  2039. auto* v = new ValueTree (fileID);
  2040. v->setProperty ("isa", "PBXBuildFile", nullptr);
  2041. v->setProperty ("fileRef", proxyID, nullptr);
  2042. v->setProperty ("settings", "{ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }", nullptr);
  2043. pbxBuildFiles.add (v);
  2044. embeddedFrameworkIDs.add (fileID);
  2045. }
  2046. }
  2047. }
  2048. auto productGroupID = createFileRefID (subprojectFile.getFullPathName() + "_products");
  2049. addGroup (productGroupID, "Products", proxyIDs);
  2050. subprojectReferences.add ({ productGroupID, subprojectFileID });
  2051. }
  2052. }
  2053. void addXcassets() const
  2054. {
  2055. auto customXcassetsPath = getCustomXcassetsFolderString();
  2056. if (customXcassetsPath.isEmpty())
  2057. addDefaultXcassetsFolders();
  2058. else
  2059. addCustomResourceFolder (customXcassetsPath, "folder.assetcatalog");
  2060. }
  2061. void addCustomResourceFolder (String folderPathRelativeToProjectFolder, const String fileType = "folder") const
  2062. {
  2063. auto folderPath = build_tools::RelativePath (folderPathRelativeToProjectFolder, build_tools::RelativePath::projectFolder)
  2064. .rebased (projectFolder, getTargetFolder(), build_tools::RelativePath::buildTargetFolder)
  2065. .toUnixStyle();
  2066. auto fileRefID = createFileRefID (folderPath);
  2067. addFileOrFolderReference (folderPath, "<group>", fileType);
  2068. resourceIDs.add (addBuildFile (folderPath, fileRefID, false, false));
  2069. resourceFileRefs.add (createFileRefID (folderPath));
  2070. }
  2071. //==============================================================================
  2072. void writeProjectFile (OutputStream& output) const
  2073. {
  2074. output << "// !$*UTF8*$!\n{\n"
  2075. "\tarchiveVersion = 1;\n"
  2076. "\tclasses = {\n\t};\n"
  2077. "\tobjectVersion = 46;\n"
  2078. "\tobjects = {\n";
  2079. Array<ValueTree*> objects;
  2080. objects.addArray (pbxBuildFiles);
  2081. objects.addArray (pbxFileReferences);
  2082. objects.addArray (pbxGroups);
  2083. objects.addArray (targetConfigs);
  2084. objects.addArray (projectConfigs);
  2085. objects.addArray (misc);
  2086. for (auto* o : objects)
  2087. {
  2088. output << "\t\t" << o->getType().toString() << " = {\n";
  2089. for (int j = 0; j < o->getNumProperties(); ++j)
  2090. {
  2091. auto propertyName = o->getPropertyName(j);
  2092. auto val = o->getProperty (propertyName).toString();
  2093. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n\\#%^`*")
  2094. && ! (val.trimStart().startsWithChar ('(')
  2095. || val.trimStart().startsWithChar ('{'))))
  2096. val = "\"" + val + "\"";
  2097. output << "\t\t\t" << propertyName.toString() << " = " << val << ";\n";
  2098. }
  2099. output << "\t\t};\n";
  2100. }
  2101. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  2102. }
  2103. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings,
  2104. XcodeTarget* xcodeTarget = nullptr, String compilerFlags = {}) const
  2105. {
  2106. auto fileID = createID (path + "buildref");
  2107. if (addToSourceBuildPhase)
  2108. {
  2109. if (xcodeTarget != nullptr)
  2110. xcodeTarget->sourceIDs.add (fileID);
  2111. else
  2112. sourceIDs.add (fileID);
  2113. }
  2114. auto* v = new ValueTree (fileID);
  2115. v->setProperty ("isa", "PBXBuildFile", nullptr);
  2116. v->setProperty ("fileRef", fileRefID, nullptr);
  2117. if (inhibitWarnings)
  2118. compilerFlags += " -w";
  2119. if (compilerFlags.isNotEmpty())
  2120. v->setProperty ("settings", "{ COMPILER_FLAGS = \"" + compilerFlags.trim() + "\"; }", nullptr);
  2121. pbxBuildFiles.add (v);
  2122. return fileID;
  2123. }
  2124. String addBuildFile (const build_tools::RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings, XcodeTarget* xcodeTarget = nullptr) const
  2125. {
  2126. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings, xcodeTarget);
  2127. }
  2128. String addFileReference (String pathString) const
  2129. {
  2130. String sourceTree ("SOURCE_ROOT");
  2131. build_tools::RelativePath path (pathString, build_tools::RelativePath::unknown);
  2132. if (pathString.startsWith ("${"))
  2133. {
  2134. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  2135. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  2136. }
  2137. else if (path.isAbsolute())
  2138. {
  2139. sourceTree = "<absolute>";
  2140. }
  2141. auto fileType = getFileType (path);
  2142. return addFileOrFolderReference (pathString, sourceTree, fileType);
  2143. }
  2144. void checkAndAddFileReference (std::unique_ptr<ValueTree> v) const
  2145. {
  2146. auto existing = pbxFileReferences.indexOfSorted (*this, v.get());
  2147. if (existing >= 0)
  2148. {
  2149. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  2150. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  2151. }
  2152. else
  2153. {
  2154. pbxFileReferences.addSorted (*this, v.release());
  2155. }
  2156. }
  2157. String addFileOrFolderReference (const String& pathString, String sourceTree, String fileType) const
  2158. {
  2159. auto fileRefID = createFileRefID (pathString);
  2160. std::unique_ptr<ValueTree> v (new ValueTree (fileRefID));
  2161. v->setProperty ("isa", "PBXFileReference", nullptr);
  2162. v->setProperty ("lastKnownFileType", fileType, nullptr);
  2163. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  2164. v->setProperty ("path", pathString, nullptr);
  2165. v->setProperty ("sourceTree", sourceTree, nullptr);
  2166. checkAndAddFileReference (std::move (v));
  2167. return fileRefID;
  2168. }
  2169. String addContainerItemProxy (const String& subprojectID, const String& itemName) const
  2170. {
  2171. auto uniqueString = subprojectID + "_" + itemName;
  2172. auto fileRefID = createFileRefID (uniqueString);
  2173. std::unique_ptr<ValueTree> v (new ValueTree (fileRefID));
  2174. v->setProperty ("isa", "PBXContainerItemProxy", nullptr);
  2175. v->setProperty ("containerPortal", subprojectID, nullptr);
  2176. v->setProperty ("proxyType", 2, nullptr);
  2177. v->setProperty ("remoteGlobalIDString", createFileRefID (uniqueString + "_global"), nullptr);
  2178. v->setProperty ("remoteInfo", itemName, nullptr);
  2179. checkAndAddFileReference (std::move (v));
  2180. return fileRefID;
  2181. }
  2182. String addReferenceProxy (const String& containerItemID, const String& proxyPath, const String& fileType) const
  2183. {
  2184. auto fileRefID = createFileRefID (containerItemID + "_" + proxyPath);
  2185. std::unique_ptr<ValueTree> v (new ValueTree (fileRefID));
  2186. v->setProperty ("isa", "PBXReferenceProxy", nullptr);
  2187. v->setProperty ("fileType", fileType, nullptr);
  2188. v->setProperty ("path", proxyPath, nullptr);
  2189. v->setProperty ("remoteRef", containerItemID, nullptr);
  2190. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  2191. checkAndAddFileReference (std::move (v));
  2192. return fileRefID;
  2193. }
  2194. public:
  2195. static int compareElements (const ValueTree* first, const ValueTree* second)
  2196. {
  2197. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  2198. }
  2199. private:
  2200. static String getFileType (const build_tools::RelativePath& file)
  2201. {
  2202. if (file.hasFileExtension (cppFileExtensions)) return "sourcecode.cpp.cpp";
  2203. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  2204. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  2205. if (file.hasFileExtension (".c")) return "sourcecode.c.c";
  2206. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  2207. if (file.hasFileExtension (asmFileExtensions)) return "sourcecode.c.asm";
  2208. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  2209. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  2210. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  2211. if (file.hasFileExtension ("html;htm")) return "text.html";
  2212. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  2213. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  2214. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  2215. if (file.hasFileExtension ("entitlements")) return "text.plist.xml";
  2216. if (file.hasFileExtension ("app")) return "wrapper.application";
  2217. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  2218. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  2219. if (file.hasFileExtension ("a")) return "archive.ar";
  2220. if (file.hasFileExtension ("xcassets")) return "folder.assetcatalog";
  2221. return "file" + file.getFileExtension();
  2222. }
  2223. String addFile (const build_tools::RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources,
  2224. bool shouldBeAddedToXcodeResources, bool inhibitWarnings, XcodeTarget* xcodeTarget, const String& compilerFlags) const
  2225. {
  2226. auto pathAsString = path.toUnixStyle();
  2227. auto refID = addFileReference (path.toUnixStyle());
  2228. if (shouldBeCompiled)
  2229. {
  2230. addBuildFile (pathAsString, refID, true, inhibitWarnings, xcodeTarget, compilerFlags);
  2231. }
  2232. else if (! shouldBeAddedToBinaryResources || shouldBeAddedToXcodeResources)
  2233. {
  2234. auto fileType = getFileType (path);
  2235. if (shouldBeAddedToXcodeResources)
  2236. {
  2237. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  2238. resourceFileRefs.add (refID);
  2239. }
  2240. }
  2241. return refID;
  2242. }
  2243. String addRezFile (const Project::Item& projectItem, const build_tools::RelativePath& path) const
  2244. {
  2245. auto pathAsString = path.toUnixStyle();
  2246. auto refID = addFileReference (path.toUnixStyle());
  2247. if (projectItem.isModuleCode())
  2248. {
  2249. if (auto* xcodeTarget = getTargetOfType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), false)))
  2250. {
  2251. auto rezFileID = addBuildFile (pathAsString, refID, false, false, xcodeTarget);
  2252. xcodeTarget->rezFileIDs.add (rezFileID);
  2253. return refID;
  2254. }
  2255. }
  2256. return {};
  2257. }
  2258. void addEntitlementsFile (XcodeTarget& target) const
  2259. {
  2260. build_tools::EntitlementOptions options;
  2261. options.type = target.type;
  2262. options.isiOS = isiOS();
  2263. options.isAudioPluginProject = project.isAudioPluginProject();
  2264. options.shouldEnableIAA = project.shouldEnableIAA();
  2265. options.isiCloudPermissionsEnabled = isiCloudPermissionsEnabled();
  2266. options.isPushNotificationsEnabled = isPushNotificationsEnabled();
  2267. options.isAppGroupsEnabled = isAppGroupsEnabled();
  2268. options.isHardenedRuntimeEnabled = isHardenedRuntimeEnabled();
  2269. options.isAppSandboxEnabled = isAppSandboxEnabled();
  2270. options.isAppSandboxInhertianceEnabled = isAppSandboxInhertianceEnabled();
  2271. options.appGroupIdString = getAppGroupIdString();
  2272. options.hardenedRuntimeOptions = getHardenedRuntimeOptions();
  2273. options.appSandboxOptions = getAppSandboxOptions();
  2274. const auto entitlementsFile = getTargetFolder().getChildFile (target.getEntitlementsFilename());
  2275. build_tools::overwriteFileIfDifferentOrThrow (entitlementsFile, options.getEntitlementsFileContent());
  2276. build_tools::RelativePath entitlementsPath (entitlementsFile, getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  2277. addFile (entitlementsPath, false, false, false, false, nullptr, {});
  2278. }
  2279. String addProjectItem (const Project::Item& projectItem) const
  2280. {
  2281. if (modulesGroup != nullptr && projectItem.getParent() == *modulesGroup)
  2282. return addFileReference (rebaseFromProjectFolderToBuildTarget (getModuleFolderRelativeToProject (projectItem.getName())).toUnixStyle());
  2283. if (projectItem.isGroup())
  2284. {
  2285. StringArray childIDs;
  2286. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  2287. {
  2288. auto child = projectItem.getChild (i);
  2289. auto childID = addProjectItem (child);
  2290. if (childID.isNotEmpty() && ! child.shouldBeAddedToXcodeResources())
  2291. childIDs.add (childID);
  2292. }
  2293. if (childIDs.isEmpty())
  2294. return {};
  2295. return addGroup (projectItem, childIDs);
  2296. }
  2297. if (projectItem.shouldBeAddedToTargetProject() && projectItem.shouldBeAddedToTargetExporter (*this))
  2298. {
  2299. auto itemPath = projectItem.getFilePath();
  2300. build_tools::RelativePath path;
  2301. if (itemPath.startsWith ("${"))
  2302. path = build_tools::RelativePath (itemPath, build_tools::RelativePath::unknown);
  2303. else
  2304. path = build_tools::RelativePath (projectItem.getFile(), getTargetFolder(), build_tools::RelativePath::buildTargetFolder);
  2305. if (path.hasFileExtension (".r"))
  2306. return addRezFile (projectItem, path);
  2307. XcodeTarget* xcodeTarget = nullptr;
  2308. if (projectItem.isModuleCode() && projectItem.shouldBeCompiled())
  2309. xcodeTarget = getTargetOfType (project.getTargetTypeFromFilePath (projectItem.getFile(), false));
  2310. return addFile (path, projectItem.shouldBeCompiled(),
  2311. projectItem.shouldBeAddedToBinaryResources(),
  2312. projectItem.shouldBeAddedToXcodeResources(),
  2313. projectItem.shouldInhibitWarnings(),
  2314. xcodeTarget,
  2315. compilerFlagSchemesMap[projectItem.getCompilerFlagSchemeString()].get());
  2316. }
  2317. return {};
  2318. }
  2319. String addFramework (const String& frameworkName) const
  2320. {
  2321. auto path = frameworkName;
  2322. auto isRelativePath = path.startsWith ("../");
  2323. if (! File::isAbsolutePath (path) && ! isRelativePath)
  2324. path = "System/Library/Frameworks/" + path;
  2325. if (! path.endsWithIgnoreCase (".framework"))
  2326. path << ".framework";
  2327. auto fileRefID = createFileRefID (path);
  2328. addFileReference (((File::isAbsolutePath (frameworkName) || isRelativePath) ? "" : "${SDKROOT}/") + path);
  2329. frameworkFileIDs.add (fileRefID);
  2330. return addBuildFile (path, fileRefID, false, false);
  2331. }
  2332. String addCustomFramework (String frameworkPath) const
  2333. {
  2334. if (! frameworkPath.endsWithIgnoreCase (".framework"))
  2335. frameworkPath << ".framework";
  2336. auto fileRefID = createFileRefID (frameworkPath);
  2337. auto fileType = getFileType (build_tools::RelativePath (frameworkPath, build_tools::RelativePath::projectFolder));
  2338. addFileOrFolderReference (frameworkPath, "<group>", fileType);
  2339. frameworkFileIDs.add (fileRefID);
  2340. return addBuildFile (frameworkPath, fileRefID, false, false);
  2341. }
  2342. String addEmbeddedFramework (const String& path) const
  2343. {
  2344. auto fileRefID = createFileRefID (path);
  2345. auto fileType = getFileType (build_tools::RelativePath (path, build_tools::RelativePath::projectFolder));
  2346. addFileOrFolderReference (path, "<group>", fileType);
  2347. auto fileID = createID (path + "buildref");
  2348. auto* v = new ValueTree (fileID);
  2349. v->setProperty ("isa", "PBXBuildFile", nullptr);
  2350. v->setProperty ("fileRef", fileRefID, nullptr);
  2351. v->setProperty ("settings", "{ ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }", nullptr);
  2352. pbxBuildFiles.add (v);
  2353. frameworkFileIDs.add (fileRefID);
  2354. return fileID;
  2355. }
  2356. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  2357. {
  2358. auto* v = new ValueTree (groupID);
  2359. v->setProperty ("isa", "PBXGroup", nullptr);
  2360. v->setProperty ("children", indentParenthesisedList (childIDs), nullptr);
  2361. v->setProperty (Ids::name, groupName, nullptr);
  2362. v->setProperty ("sourceTree", "<group>", nullptr);
  2363. pbxGroups.add (v);
  2364. }
  2365. String addGroup (const Project::Item& item, StringArray& childIDs) const
  2366. {
  2367. auto groupName = item.getName();
  2368. auto groupID = getIDForGroup (item);
  2369. addGroup (groupID, groupName, childIDs);
  2370. return groupID;
  2371. }
  2372. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  2373. {
  2374. auto* v = new ValueTree (createID ("projectconfigid_" + configName));
  2375. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  2376. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  2377. v->setProperty (Ids::name, configName, nullptr);
  2378. projectConfigs.add (v);
  2379. }
  2380. void addConfigList (XcodeTarget& target, const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  2381. {
  2382. auto* v = new ValueTree (listID);
  2383. v->setProperty ("isa", "XCConfigurationList", nullptr);
  2384. v->setProperty ("buildConfigurations", indentParenthesisedList (target.configIDs), nullptr);
  2385. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  2386. if (auto* first = configsToUse.getFirst())
  2387. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  2388. misc.add (v);
  2389. }
  2390. void addProjectConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  2391. {
  2392. StringArray configIDs;
  2393. for (auto* c : configsToUse)
  2394. configIDs.add (c->getType().toString());
  2395. auto* v = new ValueTree (listID);
  2396. v->setProperty ("isa", "XCConfigurationList", nullptr);
  2397. v->setProperty ("buildConfigurations", indentParenthesisedList (configIDs), nullptr);
  2398. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  2399. if (auto* first = configsToUse.getFirst())
  2400. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  2401. misc.add (v);
  2402. }
  2403. void addProjectObject() const
  2404. {
  2405. auto* v = new ValueTree (createID ("__root"));
  2406. v->setProperty ("isa", "PBXProject", nullptr);
  2407. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  2408. v->setProperty ("attributes", getProjectObjectAttributes(), nullptr);
  2409. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  2410. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  2411. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  2412. v->setProperty ("projectDirPath", "\"\"", nullptr);
  2413. if (! subprojectReferences.isEmpty())
  2414. {
  2415. StringArray projectReferences;
  2416. for (auto& reference : subprojectReferences)
  2417. projectReferences.add (indentBracedList ({ "ProductGroup = " + reference.first, "ProjectRef = " + reference.second }, 1));
  2418. v->setProperty ("projectReferences", indentParenthesisedList (projectReferences), nullptr);
  2419. }
  2420. v->setProperty ("projectRoot", "\"\"", nullptr);
  2421. auto targetString = "(" + targetIDs.joinIntoString (", ") + ")";
  2422. v->setProperty ("targets", targetString, nullptr);
  2423. v->setProperty ("knownRegions", "(en, Base)", nullptr);
  2424. misc.add (v);
  2425. }
  2426. //==============================================================================
  2427. void removeMismatchedXcuserdata() const
  2428. {
  2429. if (shouldKeepCustomXcodeSchemes())
  2430. return;
  2431. auto xcuserdata = getProjectBundle().getChildFile ("xcuserdata");
  2432. if (! xcuserdata.exists())
  2433. return;
  2434. if (! xcuserdataMatchesTargets (xcuserdata))
  2435. {
  2436. xcuserdata.deleteRecursively();
  2437. getProjectBundle().getChildFile ("xcshareddata").getChildFile ("xcschemes").deleteRecursively();
  2438. getProjectBundle().getChildFile ("project.xcworkspace").deleteRecursively();
  2439. }
  2440. }
  2441. bool xcuserdataMatchesTargets (const File& xcuserdata) const
  2442. {
  2443. for (auto& plist : xcuserdata.findChildFiles (File::findFiles, true, "xcschememanagement.plist"))
  2444. if (! xcschemeManagementPlistMatchesTargets (plist))
  2445. return false;
  2446. return true;
  2447. }
  2448. static StringArray parseNamesOfTargetsFromPlist (const XmlElement& dictXML)
  2449. {
  2450. forEachXmlChildElementWithTagName (dictXML, schemesKey, "key")
  2451. {
  2452. if (schemesKey->getAllSubText().trim().equalsIgnoreCase ("SchemeUserState"))
  2453. {
  2454. if (auto* dict = schemesKey->getNextElement())
  2455. {
  2456. if (dict->hasTagName ("dict"))
  2457. {
  2458. StringArray names;
  2459. forEachXmlChildElementWithTagName (*dict, key, "key")
  2460. names.add (key->getAllSubText().upToLastOccurrenceOf (".xcscheme", false, false).trim());
  2461. names.sort (false);
  2462. return names;
  2463. }
  2464. }
  2465. }
  2466. }
  2467. return {};
  2468. }
  2469. StringArray getNamesOfTargets() const
  2470. {
  2471. StringArray names;
  2472. for (auto& target : targets)
  2473. names.add (target->getXcodeSchemeName());
  2474. names.sort (false);
  2475. return names;
  2476. }
  2477. bool xcschemeManagementPlistMatchesTargets (const File& plist) const
  2478. {
  2479. if (auto xml = parseXML (plist))
  2480. if (auto* dict = xml->getChildByName ("dict"))
  2481. return parseNamesOfTargetsFromPlist (*dict) == getNamesOfTargets();
  2482. return false;
  2483. }
  2484. String getProjectObjectAttributes() const
  2485. {
  2486. String attributes;
  2487. attributes << "{ LastUpgradeCheck = 1100; "
  2488. << "ORGANIZATIONNAME = " << getProject().getCompanyNameString().quoted()
  2489. <<"; ";
  2490. if (projectType.isGUIApplication() || projectType.isAudioPlugin())
  2491. {
  2492. attributes << "TargetAttributes = { ";
  2493. for (auto& target : targets)
  2494. attributes << target->getTargetAttributes();
  2495. attributes << " }; ";
  2496. }
  2497. attributes << "}";
  2498. return attributes;
  2499. }
  2500. //==============================================================================
  2501. void writeDefaultLaunchStoryboardFile() const
  2502. {
  2503. const auto storyboardFile = getTargetFolder().getChildFile (getDefaultLaunchStoryboardName() + ".storyboard");
  2504. build_tools::writeStreamToFile (storyboardFile, [&] (MemoryOutputStream& mo)
  2505. {
  2506. mo << String (BinaryData::LaunchScreen_storyboard);
  2507. });
  2508. addLaunchStoryboardFileReference (build_tools::RelativePath (storyboardFile,
  2509. getTargetFolder(),
  2510. build_tools::RelativePath::buildTargetFolder).toUnixStyle());
  2511. }
  2512. void addLaunchStoryboardFileReference (const String& relativePath) const
  2513. {
  2514. auto refID = addFileReference (relativePath);
  2515. auto fileID = addBuildFile (relativePath, refID, false, false);
  2516. resourceIDs.add (fileID);
  2517. resourceFileRefs.add (refID);
  2518. }
  2519. void addDefaultXcassetsFolders() const
  2520. {
  2521. const auto assetsPath = build_tools::createXcassetsFolderFromIcons (getIcons(),
  2522. getTargetFolder(),
  2523. project.getProjectFilenameRootString());
  2524. addFileReference (assetsPath.toUnixStyle());
  2525. resourceIDs.add (addBuildFile (assetsPath, false, false));
  2526. resourceFileRefs.add (createFileRefID (assetsPath));
  2527. }
  2528. //==============================================================================
  2529. static String indentBracedList (const StringArray& list, int depth = 0) { return indentList (list, '{', '}', ";", depth, true); }
  2530. static String indentParenthesisedList (const StringArray& list, int depth = 0) { return indentList (list, '(', ')', ",", depth, false); }
  2531. static String indentList (StringArray list, char openBracket, char closeBracket, const String& separator, int extraTabs, bool shouldSort)
  2532. {
  2533. if (list.size() == 0)
  2534. return openBracket + String (" ") + closeBracket;
  2535. auto tabs = "\n" + String::repeatedString ("\t", extraTabs + 4);
  2536. if (shouldSort)
  2537. list.sort (true);
  2538. return openBracket + tabs + list.joinIntoString (separator + tabs) + separator
  2539. + "\n" + String::repeatedString ("\t", extraTabs + 3) + closeBracket;
  2540. }
  2541. String createID (String rootString) const
  2542. {
  2543. if (rootString.startsWith ("${"))
  2544. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  2545. rootString += project.getProjectUIDString();
  2546. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  2547. }
  2548. String createFileRefID (const build_tools::RelativePath& path) const { return createFileRefID (path.toUnixStyle()); }
  2549. String createFileRefID (const String& path) const { return createID ("__fileref_" + path); }
  2550. String getIDForGroup (const Project::Item& item) const { return createID (item.getID()); }
  2551. bool shouldFileBeCompiledByDefault (const File& file) const override
  2552. {
  2553. return file.hasFileExtension (sourceFileExtensions);
  2554. }
  2555. //==============================================================================
  2556. void updateOldOrientationSettings()
  2557. {
  2558. jassert (iOS);
  2559. StringArray orientationSettingStrings { getSetting (Ids::iPhoneScreenOrientation).getValue().toString(),
  2560. getSetting (Ids::iPadScreenOrientation).getValue().toString() };
  2561. for (int i = 0; i < 2; ++i)
  2562. {
  2563. auto& settingsString = orientationSettingStrings[i];
  2564. if (settingsString.isNotEmpty())
  2565. {
  2566. Array<var> orientations;
  2567. if (settingsString.contains ("portrait")) orientations.add ("UIInterfaceOrientationPortrait");
  2568. if (settingsString.contains ("landscape")) orientations.addArray ({ "UIInterfaceOrientationLandscapeLeft",
  2569. "UIInterfaceOrientationLandscapeRight" });
  2570. if (i == 0)
  2571. iPhoneScreenOrientationValue = orientations;
  2572. else
  2573. iPadScreenOrientationValue = orientations;
  2574. }
  2575. }
  2576. }
  2577. JUCE_DECLARE_NON_COPYABLE (XcodeProjectExporter)
  2578. };