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.

3704 lines
176KB

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