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.

3359 lines
163KB

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