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.

3105 lines
141KB

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