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.

3123 lines
142KB

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