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.

3085 lines
138KB

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