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.

3303 lines
160KB

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