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.

3580 lines
174KB

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