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.

3072 lines
137KB

  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 = 12;
  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. xcodeProductType = "com.apple.product-type.library.static";
  505. xcodeCopyToProductInstallPathAfterBuild = false;
  506. break;
  507. case DynamicLibrary:
  508. xcodeFileType = "compiled.mach-o.dylib";
  509. xcodeProductType = "com.apple.product-type.library.dynamic";
  510. xcodeBundleExtension = ".dylib";
  511. xcodeCopyToProductInstallPathAfterBuild = false;
  512. break;
  513. case VSTPlugIn:
  514. xcodePackageType = "BNDL";
  515. xcodeBundleSignature = "????";
  516. xcodeFileType = "wrapper.cfbundle";
  517. xcodeBundleExtension = ".vst";
  518. xcodeProductType = "com.apple.product-type.bundle";
  519. xcodeCopyToProductInstallPathAfterBuild = true;
  520. break;
  521. case VST3PlugIn:
  522. xcodePackageType = "BNDL";
  523. xcodeBundleSignature = "????";
  524. xcodeFileType = "wrapper.cfbundle";
  525. xcodeBundleExtension = ".vst3";
  526. xcodeProductType = "com.apple.product-type.bundle";
  527. xcodeCopyToProductInstallPathAfterBuild = true;
  528. break;
  529. case AudioUnitPlugIn:
  530. xcodePackageType = "BNDL";
  531. xcodeBundleSignature = "????";
  532. xcodeFileType = "wrapper.cfbundle";
  533. xcodeBundleExtension = ".component";
  534. xcodeProductType = "com.apple.product-type.bundle";
  535. xcodeCopyToProductInstallPathAfterBuild = true;
  536. addExtraAudioUnitTargetSettings();
  537. break;
  538. case StandalonePlugIn:
  539. xcodePackageType = "APPL";
  540. xcodeBundleSignature = "????";
  541. xcodeFileType = "wrapper.application";
  542. xcodeBundleExtension = ".app";
  543. xcodeProductType = "com.apple.product-type.application";
  544. xcodeCopyToProductInstallPathAfterBuild = false;
  545. break;
  546. case AudioUnitv3PlugIn:
  547. xcodePackageType = "XPC!";
  548. xcodeBundleSignature = "????";
  549. xcodeFileType = "wrapper.app-extension";
  550. xcodeBundleExtension = ".appex";
  551. xcodeBundleIDSubPath = "AUv3";
  552. xcodeProductType = "com.apple.product-type.app-extension";
  553. xcodeCopyToProductInstallPathAfterBuild = false;
  554. addExtraAudioUnitv3PlugInTargetSettings();
  555. break;
  556. case AAXPlugIn:
  557. xcodePackageType = "TDMw";
  558. xcodeBundleSignature = "PTul";
  559. xcodeFileType = "wrapper.cfbundle";
  560. xcodeBundleExtension = ".aaxplugin";
  561. xcodeProductType = "com.apple.product-type.bundle";
  562. xcodeCopyToProductInstallPathAfterBuild = true;
  563. break;
  564. case RTASPlugIn:
  565. xcodePackageType = "TDMw";
  566. xcodeBundleSignature = "PTul";
  567. xcodeFileType = "wrapper.cfbundle";
  568. xcodeBundleExtension = ".dpm";
  569. xcodeProductType = "com.apple.product-type.bundle";
  570. xcodeCopyToProductInstallPathAfterBuild = true;
  571. break;
  572. case SharedCodeTarget:
  573. xcodeFileType = "archive.ar";
  574. xcodeBundleExtension = ".a";
  575. xcodeProductType = "com.apple.product-type.library.static";
  576. xcodeCopyToProductInstallPathAfterBuild = false;
  577. break;
  578. case AggregateTarget:
  579. xcodeCopyToProductInstallPathAfterBuild = false;
  580. break;
  581. default:
  582. // unknown target type!
  583. jassertfalse;
  584. break;
  585. }
  586. }
  587. String getXcodeSchemeName() const
  588. {
  589. return owner.projectName + " - " + getName();
  590. }
  591. String getID() const
  592. {
  593. return owner.createID (String ("__target") + getName());
  594. }
  595. String getInfoPlistName() const
  596. {
  597. return String ("Info-") + String (getName()).replace (" ", "_") + String (".plist");
  598. }
  599. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  600. String xcodeProductType, xcodeFileType;
  601. String xcodeOtherRezFlags, xcodeBundleIDSubPath;
  602. bool xcodeCopyToProductInstallPathAfterBuild;
  603. StringArray xcodeFrameworks, xcodeLibs;
  604. Array<XmlElement> xcodeExtraPListEntries;
  605. StringArray frameworkIDs, buildPhaseIDs, configIDs, sourceIDs, rezFileIDs;
  606. StringArray frameworkNames;
  607. String dependencyID, mainBuildProductID;
  608. File infoPlistFile;
  609. struct SourceFileInfo
  610. {
  611. RelativePath path;
  612. bool shouldBeCompiled = false;
  613. };
  614. Array<SourceFileInfo> getSourceFilesInfo (const Project::Item& projectItem) const
  615. {
  616. Array<SourceFileInfo> result;
  617. const Type targetType = (owner.getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  618. if (projectItem.isGroup())
  619. {
  620. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  621. result.addArray (getSourceFilesInfo (projectItem.getChild (i)));
  622. }
  623. else if (projectItem.shouldBeAddedToTargetProject()
  624. && owner.getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  625. {
  626. SourceFileInfo info;
  627. info.path = RelativePath (projectItem.getFile(), owner.getTargetFolder(), RelativePath::buildTargetFolder);
  628. jassert (info.path.getRoot() == RelativePath::buildTargetFolder);
  629. if (targetType == SharedCodeTarget || projectItem.shouldBeCompiled())
  630. info.shouldBeCompiled = projectItem.shouldBeCompiled();
  631. result.add (info);
  632. }
  633. return result;
  634. }
  635. //==============================================================================
  636. void addMainBuildProduct() const
  637. {
  638. jassert (xcodeFileType.isNotEmpty());
  639. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar ('.'));
  640. if (ProjectExporter::BuildConfiguration::Ptr config = owner.getConfiguration(0))
  641. {
  642. String productName (owner.replacePreprocessorTokens (*config, config->getTargetBinaryNameString()));
  643. if (xcodeFileType == "archive.ar")
  644. productName = getStaticLibbedFilename (productName);
  645. else
  646. productName += xcodeBundleExtension;
  647. addBuildProduct (xcodeFileType, productName);
  648. }
  649. }
  650. //==============================================================================
  651. void addBuildProduct (const String& fileType, const String& binaryName) const
  652. {
  653. ValueTree* v = new ValueTree (owner.createID (String ("__productFileID") + getName()));
  654. v->setProperty ("isa", "PBXFileReference", nullptr);
  655. v->setProperty ("explicitFileType", fileType, nullptr);
  656. v->setProperty ("includeInIndex", (int) 0, nullptr);
  657. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  658. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  659. owner.pbxFileReferences.add (v);
  660. }
  661. //==============================================================================
  662. void addDependency()
  663. {
  664. jassert (dependencyID.isEmpty());
  665. dependencyID = owner.createID (String ("__dependency") + getName());
  666. ValueTree* const v = new ValueTree (dependencyID);
  667. v->setProperty ("isa", "PBXTargetDependency", nullptr);
  668. v->setProperty ("target", getID(), nullptr);
  669. owner.misc.add (v);
  670. }
  671. String getDependencyID() const
  672. {
  673. jassert (dependencyID.isNotEmpty());
  674. return dependencyID;
  675. }
  676. //==============================================================================
  677. void addTargetConfig (const String& configName, const StringArray& buildSettings)
  678. {
  679. String configID = owner.createID (String ("targetconfigid_") + getName() + String ("_") + configName);
  680. ValueTree* v = new ValueTree (configID);
  681. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  682. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  683. v->setProperty (Ids::name, configName, nullptr);
  684. configIDs.add (configID);
  685. owner.targetConfigs.add (v);
  686. }
  687. //==============================================================================
  688. String getTargetAttributes() const
  689. {
  690. auto attributes = getID() + " = { ";
  691. auto developmentTeamID = owner.getIosDevelopmentTeamIDString();
  692. if (developmentTeamID.isNotEmpty())
  693. {
  694. attributes << "DevelopmentTeam = " << developmentTeamID << "; ";
  695. attributes << "ProvisioningStyle = Automatic; ";
  696. }
  697. auto appGroupsEnabled = (owner.iOS && owner.isAppGroupsEnabled() ? 1 : 0);
  698. auto inAppPurchasesEnabled = owner.isInAppPurchasesEnabled() ? 1 : 0;
  699. auto interAppAudioEnabled = (owner.iOS
  700. && type == Target::StandalonePlugIn
  701. && owner.getProject().shouldEnableIAA()) ? 1 : 0;
  702. auto pushNotificationsEnabled = owner.isPushNotificationsEnabled() ? 1 : 0;
  703. auto sandboxEnabled = (type == Target::AudioUnitv3PlugIn ? 1 : 0);
  704. attributes << "SystemCapabilities = {";
  705. attributes << "com.apple.ApplicationGroups.iOS = { enabled = " << appGroupsEnabled << "; }; ";
  706. attributes << "com.apple.InAppPurchase = { enabled = " << inAppPurchasesEnabled << "; }; ";
  707. attributes << "com.apple.InterAppAudio = { enabled = " << interAppAudioEnabled << "; }; ";
  708. attributes << "com.apple.Push = { enabled = " << pushNotificationsEnabled << "; }; ";
  709. attributes << "com.apple.Sandbox = { enabled = " << sandboxEnabled << "; }; ";
  710. if (owner.iOS && owner.isiCloudPermissionsEnabled())
  711. attributes << "com.apple.iCloud = { enabled = 1; }; ";
  712. attributes << "}; };";
  713. return attributes;
  714. }
  715. //==============================================================================
  716. ValueTree& addBuildPhase (const String& buildPhaseType, const StringArray& fileIds, const StringRef humanReadableName = StringRef())
  717. {
  718. String buildPhaseName = buildPhaseType + String ("_") + getName() + String ("_") + (humanReadableName.isNotEmpty() ? String (humanReadableName) : String ("resbuildphase"));
  719. String buildPhaseId (owner.createID (buildPhaseName));
  720. int n = 0;
  721. while (buildPhaseIDs.contains (buildPhaseId))
  722. buildPhaseId = owner.createID (buildPhaseName + String (++n));
  723. buildPhaseIDs.add (buildPhaseId);
  724. ValueTree* v = new ValueTree (buildPhaseId);
  725. v->setProperty ("isa", buildPhaseType, nullptr);
  726. v->setProperty ("buildActionMask", "2147483647", nullptr);
  727. v->setProperty ("files", indentParenthesisedList (fileIds), nullptr);
  728. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  729. if (humanReadableName.isNotEmpty())
  730. v->setProperty ("name", String (humanReadableName), nullptr);
  731. owner.misc.add (v);
  732. return *v;
  733. }
  734. bool shouldCreatePList() const
  735. {
  736. const ProjectType::Target::TargetFileType fileType = getTargetFileType();
  737. return (fileType == executable && type != ConsoleApp) || fileType == pluginBundle || fileType == macOSAppex;
  738. }
  739. //==============================================================================
  740. bool shouldAddEntitlements() const
  741. {
  742. if (owner.isPushNotificationsEnabled() || owner.isAppGroupsEnabled() || (owner.isiOS() && owner.isiCloudPermissionsEnabled()))
  743. return true;
  744. if (owner.project.getProjectType().isAudioPlugin()
  745. && ( (owner.isOSX() && type == Target::AudioUnitv3PlugIn)
  746. || (owner.isiOS() && type == Target::StandalonePlugIn && owner.getProject().shouldEnableIAA())))
  747. return true;
  748. return false;
  749. }
  750. String getBundleIdentifier() const
  751. {
  752. String bundleIdentifier = owner.project.getBundleIdentifier().toString();
  753. if (xcodeBundleIDSubPath.isNotEmpty())
  754. {
  755. StringArray bundleIdSegments = StringArray::fromTokens (bundleIdentifier, ".", StringRef());
  756. jassert (bundleIdSegments.size() > 0);
  757. bundleIdentifier += String (".") + bundleIdSegments[bundleIdSegments.size() - 1] + xcodeBundleIDSubPath;
  758. }
  759. return bundleIdentifier;
  760. }
  761. //==============================================================================
  762. StringPairArray getTargetSettings (const XcodeBuildConfiguration& config) const
  763. {
  764. StringPairArray s;
  765. if (type == AggregateTarget && ! owner.isiOS())
  766. {
  767. // the aggregate target needs to have the deployment target set for
  768. // pre-/post-build scripts
  769. String sdkRoot;
  770. s.set ("MACOSX_DEPLOYMENT_TARGET", getOSXDeploymentTarget (config, &sdkRoot));
  771. if (sdkRoot.isNotEmpty())
  772. s.set ("SDKROOT", sdkRoot);
  773. return s;
  774. }
  775. s.set ("PRODUCT_BUNDLE_IDENTIFIER", getBundleIdentifier());
  776. const String arch ((! owner.isiOS() && type == Target::AudioUnitv3PlugIn) ? osxArch_64Bit : config.osxArchitecture.get());
  777. if (arch == osxArch_Native) s.set ("ARCHS", "\"$(NATIVE_ARCH_ACTUAL)\"");
  778. else if (arch == osxArch_32BitUniversal) s.set ("ARCHS", "\"$(ARCHS_STANDARD_32_BIT)\"");
  779. else if (arch == osxArch_64BitUniversal) s.set ("ARCHS", "\"$(ARCHS_STANDARD_32_64_BIT)\"");
  780. else if (arch == osxArch_64Bit) s.set ("ARCHS", "\"$(ARCHS_STANDARD_64_BIT)\"");
  781. s.set ("HEADER_SEARCH_PATHS", String ("(") + getHeaderSearchPaths (config).joinIntoString (", ") + ", \"$(inherited)\")");
  782. s.set ("USE_HEADERMAP", String (static_cast<bool> (config.exporter.settings.getProperty ("useHeaderMap")) ? "YES" : "NO"));
  783. s.set ("GCC_OPTIMIZATION_LEVEL", config.getGCCOptimisationFlag());
  784. if (shouldCreatePList())
  785. {
  786. s.set ("INFOPLIST_FILE", infoPlistFile.getFileName());
  787. if (owner.getPListPrefixHeaderString().isNotEmpty())
  788. s.set ("INFOPLIST_PREFIX_HEADER", owner.getPListPrefixHeaderString());
  789. s.set ("INFOPLIST_PREPROCESS", (owner.isPListPreprocessEnabled() ? String ("YES") : String ("NO")));
  790. auto plistDefs = parsePreprocessorDefs (config.plistPreprocessorDefinitions.get());
  791. StringArray defsList;
  792. for (int i = 0; i < plistDefs.size(); ++i)
  793. {
  794. String def (plistDefs.getAllKeys()[i]);
  795. const String value (plistDefs.getAllValues()[i]);
  796. if (value.isNotEmpty())
  797. def << "=" << value.replace ("\"", "\\\\\\\"");
  798. defsList.add ("\"" + def + "\"");
  799. }
  800. if (defsList.size() > 0)
  801. s.set ("INFOPLIST_PREPROCESSOR_DEFINITIONS", indentParenthesisedList (defsList));
  802. }
  803. if (config.isLinkTimeOptimisationEnabled())
  804. s.set ("LLVM_LTO", "YES");
  805. if (config.fastMathEnabled.get())
  806. s.set ("GCC_FAST_MATH", "YES");
  807. const String extraFlags (owner.replacePreprocessorTokens (config, owner.getExtraCompilerFlagsString()).trim());
  808. if (extraFlags.isNotEmpty())
  809. s.set ("OTHER_CPLUSPLUSFLAGS", extraFlags.quoted());
  810. String installPath = getInstallPathForConfiguration (config);
  811. if (installPath.isNotEmpty())
  812. {
  813. s.set ("INSTALL_PATH", installPath.quoted());
  814. if (xcodeCopyToProductInstallPathAfterBuild)
  815. {
  816. s.set ("DEPLOYMENT_LOCATION", "YES");
  817. s.set ("DSTROOT", "/");
  818. }
  819. }
  820. if (getTargetFileType() == pluginBundle)
  821. {
  822. s.set ("LIBRARY_STYLE", "Bundle");
  823. s.set ("WRAPPER_EXTENSION", xcodeBundleExtension.substring (1));
  824. s.set ("GENERATE_PKGINFO_FILE", "YES");
  825. }
  826. if (xcodeOtherRezFlags.isNotEmpty())
  827. s.set ("OTHER_REZFLAGS", "\"" + xcodeOtherRezFlags + "\"");
  828. String configurationBuildDir = "$(PROJECT_DIR)/build/$(CONFIGURATION)";
  829. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  830. {
  831. // a target's position can either be defined via installPath + xcodeCopyToProductInstallPathAfterBuild
  832. // (= for audio plug-ins) or using a custom binary path (for everything else), but not both (= conflict!)
  833. jassert (! xcodeCopyToProductInstallPathAfterBuild);
  834. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  835. configurationBuildDir = sanitisePath (binaryPath.rebased (owner.projectFolder, owner.getTargetFolder(), RelativePath::buildTargetFolder)
  836. .toUnixStyle());
  837. }
  838. s.set ("CONFIGURATION_BUILD_DIR", addQuotesIfRequired (configurationBuildDir));
  839. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  840. if (owner.iOS)
  841. {
  842. s.set ("ASSETCATALOG_COMPILER_APPICON_NAME", "AppIcon");
  843. s.set ("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME", "LaunchImage");
  844. }
  845. else
  846. {
  847. String sdkRoot;
  848. s.set ("MACOSX_DEPLOYMENT_TARGET", getOSXDeploymentTarget (config, &sdkRoot));
  849. if (sdkRoot.isNotEmpty())
  850. s.set ("SDKROOT", sdkRoot);
  851. s.set ("MACOSX_DEPLOYMENT_TARGET_ppc", "10.4");
  852. s.set ("SDKROOT_ppc", "macosx10.5");
  853. }
  854. s.set ("GCC_VERSION", gccVersion);
  855. s.set ("CLANG_LINK_OBJC_RUNTIME", "NO");
  856. if (isUsingCodeSigning (config))
  857. {
  858. s.set (owner.iOS ? "\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\"" : "CODE_SIGN_IDENTITY",
  859. getCodeSignIdentity (config).quoted());
  860. s.set ("PROVISIONING_PROFILE_SPECIFIER", "\"\"");
  861. }
  862. if (owner.getIosDevelopmentTeamIDString().isNotEmpty())
  863. s.set ("DEVELOPMENT_TEAM", owner.getIosDevelopmentTeamIDString());
  864. if (shouldAddEntitlements())
  865. s.set ("CODE_SIGN_ENTITLEMENTS", owner.getEntitlementsFileName().quoted());
  866. {
  867. auto cppStandard = owner.project.getCppStandardValue().toString();
  868. if (cppStandard == "latest")
  869. cppStandard = "1z";
  870. s.set ("CLANG_CXX_LANGUAGE_STANDARD", (String (owner.shouldUseGNUExtensions() ? "gnu++"
  871. : "c++") + cppStandard).quoted());
  872. }
  873. if (config.cppStandardLibrary.get().isNotEmpty())
  874. s.set ("CLANG_CXX_LIBRARY", config.cppStandardLibrary.get().quoted());
  875. s.set ("COMBINE_HIDPI_IMAGES", "YES");
  876. {
  877. StringArray linkerFlags, librarySearchPaths;
  878. getLinkerSettings (config, linkerFlags, librarySearchPaths);
  879. if (linkerFlags.size() > 0)
  880. s.set ("OTHER_LDFLAGS", linkerFlags.joinIntoString (" ").quoted());
  881. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  882. librarySearchPaths = getCleanedStringArray (librarySearchPaths);
  883. if (librarySearchPaths.size() > 0)
  884. {
  885. String libPaths ("(\"$(inherited)\"");
  886. for (auto& p : librarySearchPaths)
  887. libPaths += ", \"\\\"" + p + "\\\"\"";
  888. s.set ("LIBRARY_SEARCH_PATHS", libPaths + ")");
  889. }
  890. }
  891. StringPairArray defines;
  892. if (config.isDebug())
  893. {
  894. defines.set ("_DEBUG", "1");
  895. defines.set ("DEBUG", "1");
  896. s.set ("COPY_PHASE_STRIP", "NO");
  897. s.set ("GCC_DYNAMIC_NO_PIC", "NO");
  898. }
  899. else
  900. {
  901. defines.set ("_NDEBUG", "1");
  902. defines.set ("NDEBUG", "1");
  903. s.set ("GCC_GENERATE_DEBUGGING_SYMBOLS", "NO");
  904. s.set ("GCC_SYMBOLS_PRIVATE_EXTERN", "YES");
  905. s.set ("DEAD_CODE_STRIPPING", "YES");
  906. }
  907. if (type != Target::SharedCodeTarget && type != Target::StaticLibrary && type != Target::DynamicLibrary
  908. && config.stripLocalSymbolsEnabled.get())
  909. {
  910. s.set ("STRIPFLAGS", "\"-x\"");
  911. s.set ("DEPLOYMENT_POSTPROCESSING", "YES");
  912. s.set ("SEPARATE_STRIP", "YES");
  913. }
  914. if (owner.isInAppPurchasesEnabled())
  915. defines.set ("JUCE_IN_APP_PURCHASES", "1");
  916. if (owner.isPushNotificationsEnabled())
  917. defines.set ("JUCE_PUSH_NOTIFICATIONS", "1");
  918. defines = mergePreprocessorDefs (defines, owner.getAllPreprocessorDefs (config, type));
  919. StringArray defsList;
  920. for (int i = 0; i < defines.size(); ++i)
  921. {
  922. String def (defines.getAllKeys()[i]);
  923. const String value (defines.getAllValues()[i]);
  924. if (value.isNotEmpty())
  925. def << "=" << value.replace ("\"", "\\\\\\\"");
  926. defsList.add ("\"" + def + "\"");
  927. }
  928. s.set ("GCC_PREPROCESSOR_DEFINITIONS", indentParenthesisedList (defsList));
  929. StringArray customFlags;
  930. customFlags.addTokens (config.customXcodeFlags.get(), ",", "\"'");
  931. customFlags.removeEmptyStrings();
  932. for (auto flag : customFlags)
  933. {
  934. s.set (flag.upToFirstOccurrenceOf ("=", false, false).trim(),
  935. flag.fromFirstOccurrenceOf ("=", false, false).trim().quoted());
  936. }
  937. return s;
  938. }
  939. String getInstallPathForConfiguration (const XcodeBuildConfiguration& config) const
  940. {
  941. switch (type)
  942. {
  943. case GUIApp: return "$(HOME)/Applications";
  944. case ConsoleApp: return "/usr/bin";
  945. case VSTPlugIn: return config.pluginBinaryCopyStepEnabled.get() ? config.vstBinaryLocation.get() : String();
  946. case VST3PlugIn: return config.pluginBinaryCopyStepEnabled.get() ? config.vst3BinaryLocation.get() : String();
  947. case AudioUnitPlugIn: return config.pluginBinaryCopyStepEnabled.get() ? config.auBinaryLocation.get() : String();
  948. case RTASPlugIn: return config.pluginBinaryCopyStepEnabled.get() ? config.rtasBinaryLocation.get() : String();
  949. case AAXPlugIn: return config.pluginBinaryCopyStepEnabled.get() ? config.aaxBinaryLocation.get() : String();
  950. case SharedCodeTarget: return owner.isiOS() ? "@executable_path/Frameworks" : "@executable_path/../Frameworks";
  951. default: return {};
  952. }
  953. }
  954. //==============================================================================
  955. void getLinkerSettings (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  956. {
  957. if (getTargetFileType() == pluginBundle)
  958. flags.add (owner.isiOS() ? "-bitcode_bundle" : "-bundle");
  959. Array<RelativePath> extraLibs;
  960. addExtraLibsForTargetType (config, extraLibs);
  961. for (auto& lib : extraLibs)
  962. {
  963. flags.add (getLinkerFlagForLib (lib.getFileNameWithoutExtension()));
  964. librarySearchPaths.add (owner.getSearchPathForStaticLibrary (lib));
  965. }
  966. if (owner.project.getProjectType().isAudioPlugin() && type != Target::SharedCodeTarget)
  967. {
  968. if (owner.getTargetOfType (Target::SharedCodeTarget) != nullptr)
  969. {
  970. String productName (getStaticLibbedFilename (owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString())));
  971. RelativePath sharedCodelib (productName, RelativePath::buildTargetFolder);
  972. flags.add (getLinkerFlagForLib (sharedCodelib.getFileNameWithoutExtension()));
  973. }
  974. }
  975. flags.add (owner.replacePreprocessorTokens (config, owner.getExtraLinkerFlagsString()));
  976. flags.add (owner.getExternalLibraryFlags (config));
  977. StringArray libs (owner.xcodeLibs);
  978. libs.addArray (xcodeLibs);
  979. for (auto& l : libs)
  980. flags.add (getLinkerFlagForLib (l));
  981. flags = getCleanedStringArray (flags);
  982. }
  983. //========================================================================== c
  984. void writeInfoPlistFile() const
  985. {
  986. if (! shouldCreatePList())
  987. return;
  988. ScopedPointer<XmlElement> plist (XmlDocument::parse (owner.getPListToMergeString()));
  989. if (plist == nullptr || ! plist->hasTagName ("plist"))
  990. plist = new XmlElement ("plist");
  991. XmlElement* dict = plist->getChildByName ("dict");
  992. if (dict == nullptr)
  993. dict = plist->createNewChildElement ("dict");
  994. if (owner.iOS)
  995. {
  996. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  997. if (owner.isMicrophonePermissionEnabled())
  998. addPlistDictionaryKey (dict, "NSMicrophoneUsageDescription", "This app requires microphone input.");
  999. if (type != AudioUnitv3PlugIn)
  1000. addPlistDictionaryKeyBool (dict, "UIViewControllerBasedStatusBarAppearance", false);
  1001. }
  1002. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  1003. if (! owner.iOS) // (NB: on iOS this causes error ITMS-90032 during publishing)
  1004. addPlistDictionaryKey (dict, "CFBundleIconFile", owner.iconFile.exists() ? owner.iconFile.getFileName() : String());
  1005. addPlistDictionaryKey (dict, "CFBundleIdentifier", getBundleIdentifier());
  1006. addPlistDictionaryKey (dict, "CFBundleName", owner.projectName);
  1007. // needed by NSExtension on iOS
  1008. addPlistDictionaryKey (dict, "CFBundleDisplayName", owner.projectName);
  1009. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  1010. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  1011. addPlistDictionaryKey (dict, "CFBundleShortVersionString", owner.project.getVersionString());
  1012. addPlistDictionaryKey (dict, "CFBundleVersion", owner.project.getVersionString());
  1013. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", owner.project.getCompanyCopyright().toString());
  1014. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  1015. StringArray documentExtensions;
  1016. documentExtensions.addTokens (replacePreprocessorDefs (owner.getAllPreprocessorDefs(), owner.settings ["documentExtensions"]),
  1017. ",", StringRef());
  1018. documentExtensions.trim();
  1019. documentExtensions.removeEmptyStrings (true);
  1020. if (documentExtensions.size() > 0 && type != AudioUnitv3PlugIn)
  1021. {
  1022. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  1023. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  1024. XmlElement* arrayTag = nullptr;
  1025. for (String ex : documentExtensions)
  1026. {
  1027. if (ex.startsWithChar ('.'))
  1028. ex = ex.substring (1);
  1029. if (arrayTag == nullptr)
  1030. {
  1031. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  1032. arrayTag = dict2->createNewChildElement ("array");
  1033. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  1034. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  1035. addPlistDictionaryKey (dict2, "CFBundleTypeIconFile", "Icon");
  1036. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  1037. }
  1038. arrayTag->createNewChildElement ("string")->addTextElement (ex);
  1039. }
  1040. }
  1041. if (owner.settings ["UIFileSharingEnabled"] && type != AudioUnitv3PlugIn)
  1042. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  1043. if (owner.settings ["UIStatusBarHidden"] && type != AudioUnitv3PlugIn)
  1044. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  1045. if (owner.iOS)
  1046. {
  1047. if (type != AudioUnitv3PlugIn)
  1048. {
  1049. // Forcing full screen disables the split screen feature and prevents error ITMS-90475
  1050. addPlistDictionaryKeyBool (dict, "UIRequiresFullScreen", true);
  1051. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  1052. addIosScreenOrientations (dict);
  1053. addIosBackgroundModes (dict);
  1054. }
  1055. if (type == StandalonePlugIn && owner.getProject().shouldEnableIAA())
  1056. {
  1057. XmlElement audioComponentsPlistKey ("key");
  1058. audioComponentsPlistKey.addTextElement ("AudioComponents");
  1059. dict->addChildElement (new XmlElement (audioComponentsPlistKey));
  1060. XmlElement audioComponentsPlistEntry ("array");
  1061. XmlElement* audioComponentsDict = audioComponentsPlistEntry.createNewChildElement ("dict");
  1062. addPlistDictionaryKey (audioComponentsDict, "name", owner.project.getIAAPluginName());
  1063. addPlistDictionaryKey (audioComponentsDict, "manufacturer", owner.project.getPluginManufacturerCode().toString().trim().substring (0, 4));
  1064. addPlistDictionaryKey (audioComponentsDict, "type", owner.project.getIAATypeCode());
  1065. addPlistDictionaryKey (audioComponentsDict, "subtype", owner.project.getPluginCode().toString().trim().substring (0, 4));
  1066. addPlistDictionaryKeyInt (audioComponentsDict, "version", owner.project.getVersionAsHexInteger());
  1067. dict->addChildElement (new XmlElement (audioComponentsPlistEntry));
  1068. }
  1069. }
  1070. for (auto& e : xcodeExtraPListEntries)
  1071. dict->addChildElement (new XmlElement (e));
  1072. MemoryOutputStream mo;
  1073. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1074. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  1075. }
  1076. //==============================================================================
  1077. void addIosScreenOrientations (XmlElement* dict) const
  1078. {
  1079. String screenOrientations[2] = { owner.getiPhoneScreenOrientationString(), owner.getiPadScreenOrientationString() };
  1080. String plistSuffix[2] = { "", "~ipad" };
  1081. auto orientationsAreTheSame = ( screenOrientations[0] == screenOrientations[1] );
  1082. for (int i = 0; i < (orientationsAreTheSame ? 1 : 2); ++i)
  1083. {
  1084. StringArray iOSOrientations;
  1085. if (screenOrientations[i].contains ("portrait")) { iOSOrientations.add ("UIInterfaceOrientationPortrait"); }
  1086. if (screenOrientations[i].contains ("landscape")) { iOSOrientations.add ("UIInterfaceOrientationLandscapeLeft"); iOSOrientations.add ("UIInterfaceOrientationLandscapeRight"); }
  1087. addArrayToPlist (dict, String ("UISupportedInterfaceOrientations") + plistSuffix[i], iOSOrientations);
  1088. }
  1089. }
  1090. //==============================================================================
  1091. void addIosBackgroundModes (XmlElement* dict) const
  1092. {
  1093. StringArray iosBackgroundModes;
  1094. if (owner.isBackgroundAudioEnabled()) iosBackgroundModes.add ("audio");
  1095. if (owner.isBackgroundBleEnabled()) iosBackgroundModes.add ("bluetooth-central");
  1096. if (owner.isPushNotificationsEnabled()) iosBackgroundModes.add ("remote-notification");
  1097. addArrayToPlist (dict, "UIBackgroundModes", iosBackgroundModes);
  1098. }
  1099. //==============================================================================
  1100. static void addArrayToPlist (XmlElement* dict, String arrayKey, const StringArray& arrayElements)
  1101. {
  1102. dict->createNewChildElement ("key")->addTextElement (arrayKey);
  1103. XmlElement* plistStringArray = dict->createNewChildElement ("array");
  1104. for (auto& e : arrayElements)
  1105. plistStringArray->createNewChildElement ("string")->addTextElement (e);
  1106. }
  1107. //==============================================================================
  1108. void addShellScriptBuildPhase (const String& phaseName, const String& script)
  1109. {
  1110. if (script.trim().isNotEmpty())
  1111. {
  1112. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  1113. v.setProperty (Ids::name, phaseName, nullptr);
  1114. v.setProperty ("shellPath", "/bin/sh", nullptr);
  1115. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  1116. .replace ("\"", "\\\"")
  1117. .replace ("\r\n", "\\n")
  1118. .replace ("\n", "\\n"), nullptr);
  1119. }
  1120. }
  1121. void addCopyFilesPhase (const String& phaseName, const StringArray& files, XcodeCopyFilesDestinationIDs dst)
  1122. {
  1123. ValueTree& v = addBuildPhase ("PBXCopyFilesBuildPhase", files, phaseName);
  1124. v.setProperty ("dstPath", "", nullptr);
  1125. v.setProperty ("dstSubfolderSpec", (int) dst, nullptr);
  1126. }
  1127. //==============================================================================
  1128. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1129. {
  1130. StringArray paths (owner.extraSearchPaths);
  1131. paths.addArray (config.getHeaderSearchPaths());
  1132. paths.addArray (getTargetExtraHeaderSearchPaths());
  1133. if (owner.project.getModules().isModuleEnabled ("juce_audio_plugin_client"))
  1134. {
  1135. // Needed to compile .r files
  1136. paths.add (owner.getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  1137. .rebased (owner.projectFolder, owner.getTargetFolder(), RelativePath::buildTargetFolder)
  1138. .toUnixStyle());
  1139. }
  1140. paths = getCleanedStringArray (paths);
  1141. for (auto& s : paths)
  1142. {
  1143. s = owner.replacePreprocessorTokens (config, s);
  1144. if (s.containsChar (' '))
  1145. s = "\"\\\"" + s + "\\\"\""; // crazy double quotes required when there are spaces..
  1146. else
  1147. s = "\"" + s + "\"";
  1148. }
  1149. return paths;
  1150. }
  1151. private:
  1152. //==============================================================================
  1153. void addExtraAudioUnitTargetSettings()
  1154. {
  1155. xcodeOtherRezFlags = "-d ppc_$ppc -d i386_$i386 -d ppc64_$ppc64 -d x86_64_$x86_64"
  1156. " -I /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Versions/A/Headers"
  1157. " -I \\\"$(DEVELOPER_DIR)/Extras/CoreAudio/AudioUnits/AUPublic/AUBase\\\"";
  1158. xcodeFrameworks.addTokens ("AudioUnit CoreAudioKit", false);
  1159. XmlElement plistKey ("key");
  1160. plistKey.addTextElement ("AudioComponents");
  1161. XmlElement plistEntry ("array");
  1162. XmlElement* dict = plistEntry.createNewChildElement ("dict");
  1163. const String pluginManufacturerCode = owner.project.getPluginManufacturerCode().toString().trim().substring (0, 4);
  1164. const String pluginSubType = owner.project.getPluginCode() .toString().trim().substring (0, 4);
  1165. if (pluginManufacturerCode.toLowerCase() == pluginManufacturerCode)
  1166. {
  1167. throw SaveError ("AudioUnit plugin code identifiers invalid!\n\n"
  1168. "You have used only lower case letters in your AU plugin manufacturer identifier. "
  1169. "You must have at least one uppercase letter in your AU plugin manufacturer "
  1170. "identifier code.");
  1171. }
  1172. addPlistDictionaryKey (dict, "name", owner.project.getPluginManufacturer().toString()
  1173. + ": " + owner.project.getPluginName().toString());
  1174. addPlistDictionaryKey (dict, "description", owner.project.getPluginDesc().toString());
  1175. addPlistDictionaryKey (dict, "factoryFunction", owner.project.getPluginAUExportPrefix().toString() + "Factory");
  1176. addPlistDictionaryKey (dict, "manufacturer", pluginManufacturerCode);
  1177. addPlistDictionaryKey (dict, "type", owner.project.getAUMainTypeCode());
  1178. addPlistDictionaryKey (dict, "subtype", pluginSubType);
  1179. addPlistDictionaryKeyInt (dict, "version", owner.project.getVersionAsHexInteger());
  1180. xcodeExtraPListEntries.add (plistKey);
  1181. xcodeExtraPListEntries.add (plistEntry);
  1182. }
  1183. void addExtraAudioUnitv3PlugInTargetSettings()
  1184. {
  1185. if (owner.isiOS())
  1186. xcodeFrameworks.addTokens ("CoreAudioKit AVFoundation", false);
  1187. else
  1188. xcodeFrameworks.addTokens ("AudioUnit CoreAudioKit AVFoundation", false);
  1189. XmlElement plistKey ("key");
  1190. plistKey.addTextElement ("NSExtension");
  1191. XmlElement plistEntry ("dict");
  1192. addPlistDictionaryKey (&plistEntry, "NSExtensionPrincipalClass", owner.project.getPluginAUExportPrefix().toString() + "FactoryAUv3");
  1193. addPlistDictionaryKey (&plistEntry, "NSExtensionPointIdentifier", "com.apple.AudioUnit-UI");
  1194. plistEntry.createNewChildElement ("key")->addTextElement ("NSExtensionAttributes");
  1195. XmlElement* dict = plistEntry.createNewChildElement ("dict");
  1196. dict->createNewChildElement ("key")->addTextElement ("AudioComponents");
  1197. XmlElement* componentArray = dict->createNewChildElement ("array");
  1198. XmlElement* componentDict = componentArray->createNewChildElement ("dict");
  1199. addPlistDictionaryKey (componentDict, "name", owner.project.getPluginManufacturer().toString()
  1200. + ": " + owner.project.getPluginName().toString());
  1201. addPlistDictionaryKey (componentDict, "description", owner.project.getPluginDesc().toString());
  1202. addPlistDictionaryKey (componentDict, "factoryFunction",owner.project. getPluginAUExportPrefix().toString() + "FactoryAUv3");
  1203. addPlistDictionaryKey (componentDict, "manufacturer", owner.project.getPluginManufacturerCode().toString().trim().substring (0, 4));
  1204. addPlistDictionaryKey (componentDict, "type", owner.project.getAUMainTypeCode());
  1205. addPlistDictionaryKey (componentDict, "subtype", owner.project.getPluginCode().toString().trim().substring (0, 4));
  1206. addPlistDictionaryKeyInt (componentDict, "version", owner.project.getVersionAsHexInteger());
  1207. addPlistDictionaryKeyBool (componentDict, "sandboxSafe", true);
  1208. componentDict->createNewChildElement ("key")->addTextElement ("tags");
  1209. XmlElement* tagsArray = componentDict->createNewChildElement ("array");
  1210. tagsArray->createNewChildElement ("string")
  1211. ->addTextElement (static_cast<bool> (owner.project.getPluginIsSynth().getValue()) ? "Synth" : "Effects");
  1212. xcodeExtraPListEntries.add (plistKey);
  1213. xcodeExtraPListEntries.add (plistEntry);
  1214. }
  1215. void addExtraLibsForTargetType (const BuildConfiguration& config, Array<RelativePath>& extraLibs) const
  1216. {
  1217. if (type == AAXPlugIn)
  1218. {
  1219. auto aaxLibsFolder
  1220. = RelativePath (owner.getAAXPathValue().toString(), RelativePath::projectFolder)
  1221. .getChildFile ("Libs");
  1222. String libraryPath (config.isDebug() ? "Debug/libAAXLibrary" : "Release/libAAXLibrary");
  1223. libraryPath += (isUsingClangCppLibrary (config) ? "_libcpp.a" : ".a");
  1224. extraLibs.add (aaxLibsFolder.getChildFile (libraryPath));
  1225. }
  1226. else if (type == RTASPlugIn)
  1227. {
  1228. RelativePath rtasFolder (owner.getRTASPathValue().toString(), RelativePath::projectFolder);
  1229. extraLibs.add (rtasFolder.getChildFile ("MacBag/Libs/Debug/libPluginLibrary.a"));
  1230. extraLibs.add (rtasFolder.getChildFile ("MacBag/Libs/Release/libPluginLibrary.a"));
  1231. }
  1232. }
  1233. StringArray getTargetExtraHeaderSearchPaths() const
  1234. {
  1235. StringArray targetExtraSearchPaths;
  1236. if (type == RTASPlugIn)
  1237. {
  1238. RelativePath rtasFolder (owner.getRTASPathValue().toString(), RelativePath::projectFolder);
  1239. targetExtraSearchPaths.add ("$(DEVELOPER_DIR)/Headers/FlatCarbon");
  1240. targetExtraSearchPaths.add ("$(SDKROOT)/Developer/Headers/FlatCarbon");
  1241. static const char* p[] = { "AlturaPorts/TDMPlugIns/PlugInLibrary/Controls",
  1242. "AlturaPorts/TDMPlugIns/PlugInLibrary/CoreClasses",
  1243. "AlturaPorts/TDMPlugIns/PlugInLibrary/DSPClasses",
  1244. "AlturaPorts/TDMPlugIns/PlugInLibrary/EffectClasses",
  1245. "AlturaPorts/TDMPlugIns/PlugInLibrary/MacBuild",
  1246. "AlturaPorts/TDMPlugIns/PlugInLibrary/Meters",
  1247. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses",
  1248. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses/Interfaces",
  1249. "AlturaPorts/TDMPlugIns/PlugInLibrary/RTASP_Adapt",
  1250. "AlturaPorts/TDMPlugIns/PlugInLibrary/Utilities",
  1251. "AlturaPorts/TDMPlugIns/PlugInLibrary/ViewClasses",
  1252. "AlturaPorts/TDMPlugIns/DSPManager/**",
  1253. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/Encryption",
  1254. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/GraphicsExtensions",
  1255. "AlturaPorts/TDMPlugIns/common/**",
  1256. "AlturaPorts/TDMPlugIns/common/PI_LibInterface",
  1257. "AlturaPorts/TDMPlugIns/PACEProtection/**",
  1258. "AlturaPorts/TDMPlugIns/SignalProcessing/**",
  1259. "AlturaPorts/OMS/Headers",
  1260. "AlturaPorts/Fic/Interfaces/**",
  1261. "AlturaPorts/Fic/Source/SignalNets",
  1262. "AlturaPorts/DSIPublicInterface/PublicHeaders",
  1263. "DAEWin/Include",
  1264. "AlturaPorts/DigiPublic/Interfaces",
  1265. "AlturaPorts/DigiPublic",
  1266. "AlturaPorts/NewFileLibs/DOA",
  1267. "AlturaPorts/NewFileLibs/Cmn",
  1268. "xplat/AVX/avx2/avx2sdk/inc",
  1269. "xplat/AVX/avx2/avx2sdk/utils" };
  1270. for (auto* path : p)
  1271. owner.addProjectPathToBuildPathList (targetExtraSearchPaths, rtasFolder.getChildFile (path));
  1272. }
  1273. return targetExtraSearchPaths;
  1274. }
  1275. bool isUsingClangCppLibrary (const BuildConfiguration& config) const
  1276. {
  1277. if (auto xcodeConfig = dynamic_cast<const XcodeBuildConfiguration*> (&config))
  1278. {
  1279. const auto& configValue = xcodeConfig->cppStandardLibrary.get();
  1280. if (configValue.isNotEmpty())
  1281. return (configValue == "libc++");
  1282. auto minorOSXDeploymentTarget = getOSXDeploymentTarget (*xcodeConfig)
  1283. .fromLastOccurrenceOf (".", false, false)
  1284. .getIntValue();
  1285. return (minorOSXDeploymentTarget > 8);
  1286. }
  1287. return false;
  1288. }
  1289. String getOSXDeploymentTarget (const XcodeBuildConfiguration& config, String* sdkRoot = nullptr) const
  1290. {
  1291. const String sdk (config.osxSDKVersion.get());
  1292. const String sdkCompat (config.osxDeploymentTarget.get());
  1293. // The AUv3 target always needs to be at least 10.11
  1294. int oldestAllowedDeploymentTarget = (type == Target::AudioUnitv3PlugIn ? minimumAUv3SDKVersion
  1295. : oldestSDKVersion);
  1296. // if the user doesn't set it, then use the last known version that works well with JUCE
  1297. String deploymentTarget = "10.11";
  1298. for (int ver = oldestAllowedDeploymentTarget; ver <= currentSDKVersion; ++ver)
  1299. {
  1300. if (sdk == getSDKName (ver) && sdkRoot != nullptr) *sdkRoot = String ("macosx10." + String (ver));
  1301. if (sdkCompat == getSDKName (ver)) deploymentTarget = "10." + String (ver);
  1302. }
  1303. return deploymentTarget;
  1304. }
  1305. String getCodeSignIdentity (const XcodeBuildConfiguration& config) const
  1306. {
  1307. if (config.codeSignIdentity.isUsingDefault())
  1308. return owner.iOS ? "iPhone Developer" : "Mac Developer";
  1309. return config.codeSignIdentity.get();
  1310. }
  1311. bool isUsingCodeSigning (const XcodeBuildConfiguration& config) const
  1312. {
  1313. return (! config.codeSignIdentity.isUsingDefault())
  1314. || owner.getIosDevelopmentTeamIDString().isNotEmpty();
  1315. }
  1316. //==============================================================================
  1317. const XcodeProjectExporter& owner;
  1318. Target& operator= (const Target&) JUCE_DELETED_FUNCTION;
  1319. };
  1320. mutable StringArray xcodeFrameworks;
  1321. StringArray xcodeLibs;
  1322. private:
  1323. //==============================================================================
  1324. friend class CLionProjectExporter;
  1325. bool xcodeCanUseDwarf;
  1326. OwnedArray<XcodeTarget> targets;
  1327. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  1328. mutable StringArray resourceIDs, sourceIDs, targetIDs;
  1329. mutable StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  1330. mutable File menuNibFile, iconFile;
  1331. mutable StringArray buildProducts;
  1332. const bool iOS;
  1333. static String sanitisePath (const String& path)
  1334. {
  1335. if (path.startsWithChar ('~'))
  1336. return "$(HOME)" + path.substring (1);
  1337. return path;
  1338. }
  1339. static String addQuotesIfRequired (const String& s)
  1340. {
  1341. return s.containsAnyOf (" $") ? s.quoted() : s;
  1342. }
  1343. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  1344. //==============================================================================
  1345. void createObjects() const
  1346. {
  1347. prepareTargets();
  1348. addFrameworks();
  1349. addCustomResourceFolders();
  1350. addPlistFileReferences();
  1351. if (iOS && ! projectType.isStaticLibrary())
  1352. addXcassets();
  1353. else
  1354. addNibFiles();
  1355. addIcons();
  1356. addBuildConfigurations();
  1357. addProjectConfigList (projectConfigs, createID ("__projList"));
  1358. {
  1359. StringArray topLevelGroupIDs;
  1360. addFilesAndGroupsToProject (topLevelGroupIDs);
  1361. addBuildPhases();
  1362. addExtraGroupsToProject (topLevelGroupIDs);
  1363. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  1364. }
  1365. addProjectObject();
  1366. removeMismatchedXcuserdata();
  1367. }
  1368. void prepareTargets() const
  1369. {
  1370. for (auto* target : targets)
  1371. {
  1372. if (target->type == XcodeTarget::AggregateTarget)
  1373. continue;
  1374. target->addMainBuildProduct();
  1375. String targetName = target->getName();
  1376. String fileID (createID (targetName + String ("__targetbuildref")));
  1377. String fileRefID (createID (String ("__productFileID") + targetName));
  1378. ValueTree* v = new ValueTree (fileID);
  1379. v->setProperty ("isa", "PBXBuildFile", nullptr);
  1380. v->setProperty ("fileRef", fileRefID, nullptr);
  1381. target->mainBuildProductID = fileID;
  1382. pbxBuildFiles.add (v);
  1383. target->addDependency();
  1384. }
  1385. }
  1386. void addPlistFileReferences() const
  1387. {
  1388. for (auto* target : targets)
  1389. {
  1390. if (target->type == XcodeTarget::AggregateTarget)
  1391. continue;
  1392. if (target->shouldCreatePList())
  1393. {
  1394. RelativePath plistPath (target->infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1395. addFileReference (plistPath.toUnixStyle());
  1396. resourceFileRefs.add (createFileRefID (plistPath));
  1397. }
  1398. }
  1399. }
  1400. void addNibFiles() const
  1401. {
  1402. MemoryOutputStream nib;
  1403. nib.write (BinaryData::RecentFilesMenuTemplate_nib, BinaryData::RecentFilesMenuTemplate_nibSize);
  1404. overwriteFileIfDifferentOrThrow (menuNibFile, nib);
  1405. RelativePath menuNibPath (menuNibFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1406. addFileReference (menuNibPath.toUnixStyle());
  1407. resourceIDs.add (addBuildFile (menuNibPath, false, false));
  1408. resourceFileRefs.add (createFileRefID (menuNibPath));
  1409. }
  1410. void addIcons() const
  1411. {
  1412. if (iconFile.exists())
  1413. {
  1414. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1415. addFileReference (iconPath.toUnixStyle());
  1416. resourceIDs.add (addBuildFile (iconPath, false, false));
  1417. resourceFileRefs.add (createFileRefID (iconPath));
  1418. }
  1419. }
  1420. void addBuildConfigurations() const
  1421. {
  1422. for (ConstConfigIterator config (*this); config.next();)
  1423. {
  1424. const auto& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1425. StringArray settingsLines;
  1426. const auto configSettings = getProjectSettings (xcodeConfig);
  1427. for (auto& key : configSettings.getAllKeys())
  1428. settingsLines.add (key + " = " + configSettings[key]);
  1429. addProjectConfig (config->getName(), settingsLines);
  1430. }
  1431. }
  1432. void addFilesAndGroupsToProject (StringArray& topLevelGroupIDs) const
  1433. {
  1434. StringPairArray entitlements = getEntitlements();
  1435. if (entitlements.size() > 0)
  1436. topLevelGroupIDs.add (addEntitlementsFile (entitlements));
  1437. for (auto& group : getAllGroups())
  1438. if (group.getNumChildren() > 0)
  1439. topLevelGroupIDs.add (addProjectItem (group));
  1440. }
  1441. void addExtraGroupsToProject (StringArray& topLevelGroupIDs) const
  1442. {
  1443. { // Add 'resources' group
  1444. String resourcesGroupID (createID ("__resources"));
  1445. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  1446. topLevelGroupIDs.add (resourcesGroupID);
  1447. }
  1448. { // Add 'frameworks' group
  1449. String frameworksGroupID (createID ("__frameworks"));
  1450. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  1451. topLevelGroupIDs.add (frameworksGroupID);
  1452. }
  1453. { // Add 'products' group
  1454. String productsGroupID (createID ("__products"));
  1455. addGroup (productsGroupID, "Products", buildProducts);
  1456. topLevelGroupIDs.add (productsGroupID);
  1457. }
  1458. }
  1459. void addBuildPhases() const
  1460. {
  1461. // add build phases
  1462. for (auto* target : targets)
  1463. {
  1464. if (target->type != XcodeTarget::AggregateTarget)
  1465. buildProducts.add (createID (String ("__productFileID") + String (target->getName())));
  1466. for (ConstConfigIterator config (*this); config.next();)
  1467. {
  1468. const XcodeBuildConfiguration& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1469. const auto configSettings = target->getTargetSettings (xcodeConfig);
  1470. StringArray settingsLines;
  1471. for (auto& key : configSettings.getAllKeys())
  1472. settingsLines.add (key + " = " + configSettings.getValue (key, "\"\""));
  1473. target->addTargetConfig (config->getName(), settingsLines);
  1474. }
  1475. addConfigList (*target, targetConfigs, createID (String ("__configList") + target->getName()));
  1476. target->addShellScriptBuildPhase ("Pre-build script", getPreBuildScript());
  1477. if (target->type != XcodeTarget::AggregateTarget)
  1478. {
  1479. auto skipAUv3 = (target->type == XcodeTarget::AudioUnitv3PlugIn
  1480. && ! shouldDuplicateResourcesFolderForAppExtension());
  1481. if (! projectType.isStaticLibrary() && target->type != XcodeTarget::SharedCodeTarget && ! skipAUv3)
  1482. target->addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  1483. StringArray rezFiles (rezFileIDs);
  1484. rezFiles.addArray (target->rezFileIDs);
  1485. if (rezFiles.size() > 0)
  1486. target->addBuildPhase ("PBXRezBuildPhase", rezFiles);
  1487. StringArray sourceFiles (target->sourceIDs);
  1488. if (target->type == XcodeTarget::SharedCodeTarget
  1489. || (! project.getProjectType().isAudioPlugin()))
  1490. sourceFiles.addArray (sourceIDs);
  1491. target->addBuildPhase ("PBXSourcesBuildPhase", sourceFiles);
  1492. if (! projectType.isStaticLibrary() && target->type != XcodeTarget::SharedCodeTarget)
  1493. target->addBuildPhase ("PBXFrameworksBuildPhase", target->frameworkIDs);
  1494. }
  1495. target->addShellScriptBuildPhase ("Post-build script", getPostBuildScript());
  1496. if (project.getProjectType().isAudioPlugin() && project.shouldBuildAUv3()
  1497. && project.shouldBuildStandalonePlugin() && target->type == XcodeTarget::StandalonePlugIn)
  1498. embedAppExtension();
  1499. addTargetObject (*target);
  1500. }
  1501. }
  1502. void embedAppExtension() const
  1503. {
  1504. if (auto* standaloneTarget = getTargetOfType (XcodeTarget::StandalonePlugIn))
  1505. {
  1506. if (auto* auv3Target = getTargetOfType (XcodeTarget::AudioUnitv3PlugIn))
  1507. {
  1508. StringArray files;
  1509. files.add (auv3Target->mainBuildProductID);
  1510. standaloneTarget->addCopyFilesPhase ("Embed App Extensions", files, kPluginsFolder);
  1511. }
  1512. }
  1513. }
  1514. static Image fixMacIconImageSize (Drawable& image)
  1515. {
  1516. const int validSizes[] = { 16, 32, 48, 128, 256, 512, 1024 };
  1517. const int w = image.getWidth();
  1518. const int h = image.getHeight();
  1519. int bestSize = 16;
  1520. for (int size : validSizes)
  1521. {
  1522. if (w == h && w == size)
  1523. {
  1524. bestSize = w;
  1525. break;
  1526. }
  1527. if (jmax (w, h) > size)
  1528. bestSize = size;
  1529. }
  1530. return rescaleImageForIcon (image, bestSize);
  1531. }
  1532. //==============================================================================
  1533. XcodeTarget* getTargetOfType (ProjectType::Target::Type type) const
  1534. {
  1535. for (auto& target : targets)
  1536. if (target->type == type)
  1537. return target;
  1538. return nullptr;
  1539. }
  1540. void addTargetObject (XcodeTarget& target) const
  1541. {
  1542. String targetName = target.getName();
  1543. String targetID = target.getID();
  1544. ValueTree* const v = new ValueTree (targetID);
  1545. v->setProperty ("isa", target.type == XcodeTarget::AggregateTarget ? "PBXAggregateTarget" : "PBXNativeTarget", nullptr);
  1546. v->setProperty ("buildConfigurationList", createID (String ("__configList") + targetName), nullptr);
  1547. v->setProperty ("buildPhases", indentParenthesisedList (target.buildPhaseIDs), nullptr);
  1548. v->setProperty ("buildRules", "( )", nullptr);
  1549. v->setProperty ("dependencies", indentParenthesisedList (getTargetDependencies (target)), nullptr);
  1550. v->setProperty (Ids::name, target.getXcodeSchemeName(), nullptr);
  1551. v->setProperty ("productName", projectName, nullptr);
  1552. if (target.type != XcodeTarget::AggregateTarget)
  1553. {
  1554. v->setProperty ("productReference", createID (String ("__productFileID") + targetName), nullptr);
  1555. jassert (target.xcodeProductType.isNotEmpty());
  1556. v->setProperty ("productType", target.xcodeProductType, nullptr);
  1557. }
  1558. targetIDs.add (targetID);
  1559. misc.add (v);
  1560. }
  1561. StringArray getTargetDependencies (const XcodeTarget& target) const
  1562. {
  1563. StringArray dependencies;
  1564. if (project.getProjectType().isAudioPlugin())
  1565. {
  1566. if (target.type == XcodeTarget::StandalonePlugIn) // depends on AUv3 and shared code
  1567. {
  1568. if (XcodeTarget* auv3Target = getTargetOfType (XcodeTarget::AudioUnitv3PlugIn))
  1569. dependencies.add (auv3Target->getDependencyID());
  1570. if (XcodeTarget* sharedCodeTarget = getTargetOfType (XcodeTarget::SharedCodeTarget))
  1571. dependencies.add (sharedCodeTarget->getDependencyID());
  1572. }
  1573. else if (target.type == XcodeTarget::AggregateTarget) // depends on all other targets
  1574. {
  1575. for (int i = 1; i < targets.size(); ++i)
  1576. dependencies.add (targets[i]->getDependencyID());
  1577. }
  1578. else if (target.type != XcodeTarget::SharedCodeTarget) // shared code doesn't depend on anything; all other targets depend only on the shared code
  1579. {
  1580. if (XcodeTarget* sharedCodeTarget = getTargetOfType (XcodeTarget::SharedCodeTarget))
  1581. dependencies.add (sharedCodeTarget->getDependencyID());
  1582. }
  1583. }
  1584. return dependencies;
  1585. }
  1586. static void writeOldIconFormat (MemoryOutputStream& out, const Image& image, const char* type, const char* maskType)
  1587. {
  1588. const int w = image.getWidth();
  1589. const int h = image.getHeight();
  1590. out.write (type, 4);
  1591. out.writeIntBigEndian (8 + 4 * w * h);
  1592. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  1593. for (int y = 0; y < h; ++y)
  1594. {
  1595. for (int x = 0; x < w; ++x)
  1596. {
  1597. const Colour pixel (bitmap.getPixelColour (x, y));
  1598. out.writeByte ((char) pixel.getAlpha());
  1599. out.writeByte ((char) pixel.getRed());
  1600. out.writeByte ((char) pixel.getGreen());
  1601. out.writeByte ((char) pixel.getBlue());
  1602. }
  1603. }
  1604. out.write (maskType, 4);
  1605. out.writeIntBigEndian (8 + w * h);
  1606. for (int y = 0; y < h; ++y)
  1607. {
  1608. for (int x = 0; x < w; ++x)
  1609. {
  1610. const Colour pixel (bitmap.getPixelColour (x, y));
  1611. out.writeByte ((char) pixel.getAlpha());
  1612. }
  1613. }
  1614. }
  1615. static void writeNewIconFormat (MemoryOutputStream& out, const Image& image, const char* type)
  1616. {
  1617. MemoryOutputStream pngData;
  1618. PNGImageFormat pngFormat;
  1619. pngFormat.writeImageToStream (image, pngData);
  1620. out.write (type, 4);
  1621. out.writeIntBigEndian (8 + (int) pngData.getDataSize());
  1622. out << pngData;
  1623. }
  1624. void writeIcnsFile (const OwnedArray<Drawable>& images, OutputStream& out) const
  1625. {
  1626. MemoryOutputStream data;
  1627. int smallest = 0x7fffffff;
  1628. Drawable* smallestImage = nullptr;
  1629. for (int i = 0; i < images.size(); ++i)
  1630. {
  1631. const Image image (fixMacIconImageSize (*images.getUnchecked(i)));
  1632. jassert (image.getWidth() == image.getHeight());
  1633. if (image.getWidth() < smallest)
  1634. {
  1635. smallest = image.getWidth();
  1636. smallestImage = images.getUnchecked(i);
  1637. }
  1638. switch (image.getWidth())
  1639. {
  1640. case 16: writeOldIconFormat (data, image, "is32", "s8mk"); break;
  1641. case 32: writeOldIconFormat (data, image, "il32", "l8mk"); break;
  1642. case 48: writeOldIconFormat (data, image, "ih32", "h8mk"); break;
  1643. case 128: writeOldIconFormat (data, image, "it32", "t8mk"); break;
  1644. case 256: writeNewIconFormat (data, image, "ic08"); break;
  1645. case 512: writeNewIconFormat (data, image, "ic09"); break;
  1646. case 1024: writeNewIconFormat (data, image, "ic10"); break;
  1647. default: break;
  1648. }
  1649. }
  1650. jassert (data.getDataSize() > 0); // no suitable sized images?
  1651. // If you only supply a 1024 image, the file doesn't work on 10.8, so we need
  1652. // to force a smaller one in there too..
  1653. if (smallest > 512 && smallestImage != nullptr)
  1654. writeNewIconFormat (data, rescaleImageForIcon (*smallestImage, 512), "ic09");
  1655. out.write ("icns", 4);
  1656. out.writeIntBigEndian ((int) data.getDataSize() + 8);
  1657. out << data;
  1658. }
  1659. void getIconImages (OwnedArray<Drawable>& images) const
  1660. {
  1661. ScopedPointer<Drawable> bigIcon (getBigIcon());
  1662. if (bigIcon != nullptr)
  1663. images.add (bigIcon.release());
  1664. ScopedPointer<Drawable> smallIcon (getSmallIcon());
  1665. if (smallIcon != nullptr)
  1666. images.add (smallIcon.release());
  1667. }
  1668. void createiOSIconFiles (File appIconSet) const
  1669. {
  1670. OwnedArray<Drawable> images;
  1671. getIconImages (images);
  1672. if (images.size() > 0)
  1673. {
  1674. for (auto& type : getiOSAppIconTypes())
  1675. {
  1676. auto image = rescaleImageForIcon (*images.getFirst(), type.size);
  1677. MemoryOutputStream pngData;
  1678. PNGImageFormat pngFormat;
  1679. pngFormat.writeImageToStream (image, pngData);
  1680. overwriteFileIfDifferentOrThrow (appIconSet.getChildFile (type.filename), pngData);
  1681. }
  1682. }
  1683. }
  1684. void createIconFile() const
  1685. {
  1686. OwnedArray<Drawable> images;
  1687. getIconImages (images);
  1688. if (images.size() > 0)
  1689. {
  1690. MemoryOutputStream mo;
  1691. writeIcnsFile (images, mo);
  1692. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  1693. overwriteFileIfDifferentOrThrow (iconFile, mo);
  1694. }
  1695. }
  1696. void writeInfoPlistFiles() const
  1697. {
  1698. for (auto& target : targets)
  1699. target->writeInfoPlistFile();
  1700. }
  1701. // Delete .rsrc files in folder but don't follow sym-links
  1702. void deleteRsrcFiles (const File& folder) const
  1703. {
  1704. for (DirectoryIterator di (folder, false, "*", File::findFilesAndDirectories); di.next();)
  1705. {
  1706. const File& entry = di.getFile();
  1707. if (! entry.isSymbolicLink())
  1708. {
  1709. if (entry.existsAsFile() && entry.getFileExtension().toLowerCase() == ".rsrc")
  1710. entry.deleteFile();
  1711. else if (entry.isDirectory())
  1712. deleteRsrcFiles (entry);
  1713. }
  1714. }
  1715. }
  1716. static String getLinkerFlagForLib (String library)
  1717. {
  1718. if (library.substring (0, 3) == "lib")
  1719. library = library.substring (3);
  1720. return "-l" + library.replace (" ", "\\\\ ").upToLastOccurrenceOf (".", false, false);
  1721. }
  1722. String getSearchPathForStaticLibrary (const RelativePath& library) const
  1723. {
  1724. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  1725. if (! library.isAbsolute())
  1726. {
  1727. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  1728. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  1729. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  1730. searchPath = srcRoot + searchPath;
  1731. }
  1732. return sanitisePath (searchPath);
  1733. }
  1734. StringPairArray getProjectSettings (const XcodeBuildConfiguration& config) const
  1735. {
  1736. StringPairArray s;
  1737. s.set ("ALWAYS_SEARCH_USER_PATHS", "NO");
  1738. s.set ("ENABLE_STRICT_OBJC_MSGSEND", "YES");
  1739. s.set ("GCC_C_LANGUAGE_STANDARD", "c11");
  1740. s.set ("GCC_NO_COMMON_BLOCKS", "YES");
  1741. s.set ("GCC_MODEL_TUNING", "G5");
  1742. s.set ("GCC_WARN_ABOUT_RETURN_TYPE", "YES");
  1743. s.set ("GCC_WARN_CHECK_SWITCH_STATEMENTS", "YES");
  1744. s.set ("GCC_WARN_UNUSED_VARIABLE", "YES");
  1745. s.set ("GCC_WARN_MISSING_PARENTHESES", "YES");
  1746. s.set ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR", "YES");
  1747. s.set ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF", "YES");
  1748. s.set ("GCC_WARN_64_TO_32_BIT_CONVERSION", "YES");
  1749. s.set ("GCC_WARN_UNDECLARED_SELECTOR", "YES");
  1750. s.set ("GCC_WARN_UNINITIALIZED_AUTOS", "YES");
  1751. s.set ("GCC_WARN_UNUSED_FUNCTION", "YES");
  1752. s.set ("CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING", "YES");
  1753. s.set ("CLANG_WARN_BOOL_CONVERSION", "YES");
  1754. s.set ("CLANG_WARN_COMMA", "YES");
  1755. s.set ("CLANG_WARN_CONSTANT_CONVERSION", "YES");
  1756. s.set ("CLANG_WARN_EMPTY_BODY", "YES");
  1757. s.set ("CLANG_WARN_ENUM_CONVERSION", "YES");
  1758. s.set ("CLANG_WARN_INFINITE_RECURSION", "YES");
  1759. s.set ("CLANG_WARN_INT_CONVERSION", "YES");
  1760. s.set ("CLANG_WARN_NON_LITERAL_NULL_CONVERSION", "YES");
  1761. s.set ("CLANG_WARN_OBJC_LITERAL_CONVERSION", "YES");
  1762. s.set ("CLANG_WARN_RANGE_LOOP_ANALYSIS", "YES");
  1763. s.set ("CLANG_WARN_STRICT_PROTOTYPES", "YES");
  1764. s.set ("CLANG_WARN_SUSPICIOUS_MOVE", "YES");
  1765. s.set ("CLANG_WARN_UNREACHABLE_CODE", "YES");
  1766. s.set ("CLANG_WARN__DUPLICATE_METHOD_MATCH", "YES");
  1767. s.set ("WARNING_CFLAGS", "-Wreorder");
  1768. if (projectType.isStaticLibrary())
  1769. {
  1770. s.set ("GCC_INLINES_ARE_PRIVATE_EXTERN", "NO");
  1771. s.set ("GCC_SYMBOLS_PRIVATE_EXTERN", "NO");
  1772. }
  1773. else
  1774. {
  1775. s.set ("GCC_INLINES_ARE_PRIVATE_EXTERN", "YES");
  1776. }
  1777. if (config.isDebug())
  1778. {
  1779. s.set ("ENABLE_TESTABILITY", "YES");
  1780. if (config.osxArchitecture.get() == osxArch_Default || config.osxArchitecture.get().isEmpty())
  1781. s.set ("ONLY_ACTIVE_ARCH", "YES");
  1782. }
  1783. if (iOS)
  1784. {
  1785. s.set ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\"", config.codeSignIdentity.get().quoted());
  1786. s.set ("SDKROOT", "iphoneos");
  1787. s.set ("TARGETED_DEVICE_FAMILY", getDeviceFamilyString().quoted());
  1788. const String iosVersion (config.iosDeploymentTarget.get());
  1789. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  1790. s.set ("IPHONEOS_DEPLOYMENT_TARGET", iosVersion);
  1791. else
  1792. s.set ("IPHONEOS_DEPLOYMENT_TARGET", "9.3");
  1793. }
  1794. else
  1795. {
  1796. if (! config.codeSignIdentity.isUsingDefault() || getIosDevelopmentTeamIDString().isNotEmpty())
  1797. s.set ("CODE_SIGN_IDENTITY", config.codeSignIdentity.get().quoted());
  1798. }
  1799. s.set ("ZERO_LINK", "NO");
  1800. if (xcodeCanUseDwarf)
  1801. s.set ("DEBUG_INFORMATION_FORMAT", "\"dwarf\"");
  1802. s.set ("PRODUCT_NAME", replacePreprocessorTokens (config, config.getTargetBinaryNameString()).quoted());
  1803. return s;
  1804. }
  1805. void addFrameworks() const
  1806. {
  1807. if (! projectType.isStaticLibrary())
  1808. {
  1809. if (isInAppPurchasesEnabled())
  1810. xcodeFrameworks.addIfNotAlreadyThere ("StoreKit");
  1811. if (iOS && isPushNotificationsEnabled())
  1812. xcodeFrameworks.addIfNotAlreadyThere ("UserNotifications");
  1813. xcodeFrameworks.addTokens (getExtraFrameworksString(), ",;", "\"'");
  1814. xcodeFrameworks.trim();
  1815. StringArray s (xcodeFrameworks);
  1816. for (auto& target : targets)
  1817. s.addArray (target->xcodeFrameworks);
  1818. if (project.getConfigFlag ("JUCE_QUICKTIME") == Project::configFlagDisabled)
  1819. s.removeString ("QuickTime");
  1820. s.trim();
  1821. s.removeDuplicates (true);
  1822. s.sort (true);
  1823. for (auto& framework : s)
  1824. {
  1825. String frameworkID = addFramework (framework);
  1826. // find all the targets that are referring to this object
  1827. for (auto& target : targets)
  1828. {
  1829. if (xcodeFrameworks.contains (framework) || target->xcodeFrameworks.contains (framework))
  1830. {
  1831. target->frameworkIDs.add (frameworkID);
  1832. target->frameworkNames.add (framework);
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. void addCustomResourceFolders() const
  1839. {
  1840. StringArray folders;
  1841. folders.addTokens (getCustomResourceFoldersString(), ":", "");
  1842. folders.trim();
  1843. for (auto& crf : folders)
  1844. addCustomResourceFolder (crf);
  1845. }
  1846. void addXcassets() const
  1847. {
  1848. String customXcassetsPath = getCustomXcassetsFolderString();
  1849. if (customXcassetsPath.isEmpty())
  1850. createXcassetsFolderFromIcons();
  1851. else
  1852. addCustomResourceFolder (customXcassetsPath, "folder.assetcatalog");
  1853. }
  1854. void addCustomResourceFolder (String folderPathRelativeToProjectFolder, const String fileType = "folder") const
  1855. {
  1856. String folderPath = RelativePath (folderPathRelativeToProjectFolder, RelativePath::projectFolder)
  1857. .rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  1858. .toUnixStyle();
  1859. const String fileRefID (createFileRefID (folderPath));
  1860. addFileOrFolderReference (folderPath, "<group>", fileType);
  1861. resourceIDs.add (addBuildFile (folderPath, fileRefID, false, false));
  1862. resourceFileRefs.add (createFileRefID (folderPath));
  1863. }
  1864. //==============================================================================
  1865. void writeProjectFile (OutputStream& output) const
  1866. {
  1867. output << "// !$*UTF8*$!\n{\n"
  1868. "\tarchiveVersion = 1;\n"
  1869. "\tclasses = {\n\t};\n"
  1870. "\tobjectVersion = 46;\n"
  1871. "\tobjects = {\n\n";
  1872. Array<ValueTree*> objects;
  1873. objects.addArray (pbxBuildFiles);
  1874. objects.addArray (pbxFileReferences);
  1875. objects.addArray (pbxGroups);
  1876. objects.addArray (targetConfigs);
  1877. objects.addArray (projectConfigs);
  1878. objects.addArray (misc);
  1879. for (auto* o : objects)
  1880. {
  1881. output << "\t\t" << o->getType().toString() << " = {";
  1882. for (int j = 0; j < o->getNumProperties(); ++j)
  1883. {
  1884. const Identifier propertyName (o->getPropertyName(j));
  1885. String val (o->getProperty (propertyName).toString());
  1886. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n\\#%^`*")
  1887. && ! (val.trimStart().startsWithChar ('(')
  1888. || val.trimStart().startsWithChar ('{'))))
  1889. val = "\"" + val + "\"";
  1890. output << propertyName.toString() << " = " << val << "; ";
  1891. }
  1892. output << "};\n";
  1893. }
  1894. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  1895. }
  1896. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings, XcodeTarget* xcodeTarget = nullptr) const
  1897. {
  1898. String fileID (createID (path + "buildref"));
  1899. if (addToSourceBuildPhase)
  1900. {
  1901. if (xcodeTarget != nullptr)
  1902. xcodeTarget->sourceIDs.add (fileID);
  1903. else
  1904. sourceIDs.add (fileID);
  1905. }
  1906. ValueTree* v = new ValueTree (fileID);
  1907. v->setProperty ("isa", "PBXBuildFile", nullptr);
  1908. v->setProperty ("fileRef", fileRefID, nullptr);
  1909. if (inhibitWarnings)
  1910. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  1911. pbxBuildFiles.add (v);
  1912. return fileID;
  1913. }
  1914. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings, XcodeTarget* xcodeTarget = nullptr) const
  1915. {
  1916. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings, xcodeTarget);
  1917. }
  1918. String addFileReference (String pathString) const
  1919. {
  1920. String sourceTree ("SOURCE_ROOT");
  1921. RelativePath path (pathString, RelativePath::unknown);
  1922. if (pathString.startsWith ("${"))
  1923. {
  1924. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  1925. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  1926. }
  1927. else if (path.isAbsolute())
  1928. {
  1929. sourceTree = "<absolute>";
  1930. }
  1931. String fileType = getFileType (path);
  1932. return addFileOrFolderReference (pathString, sourceTree, fileType);
  1933. }
  1934. String addFileOrFolderReference (String pathString, String sourceTree, String fileType) const
  1935. {
  1936. const String fileRefID (createFileRefID (pathString));
  1937. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  1938. v->setProperty ("isa", "PBXFileReference", nullptr);
  1939. v->setProperty ("lastKnownFileType", fileType, nullptr);
  1940. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  1941. v->setProperty ("path", pathString, nullptr);
  1942. v->setProperty ("sourceTree", sourceTree, nullptr);
  1943. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  1944. if (existing >= 0)
  1945. {
  1946. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  1947. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  1948. }
  1949. else
  1950. {
  1951. pbxFileReferences.addSorted (*this, v.release());
  1952. }
  1953. return fileRefID;
  1954. }
  1955. public:
  1956. static int compareElements (const ValueTree* first, const ValueTree* second)
  1957. {
  1958. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  1959. }
  1960. private:
  1961. static String getFileType (const RelativePath& file)
  1962. {
  1963. if (file.hasFileExtension (cppFileExtensions)) return "sourcecode.cpp.cpp";
  1964. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  1965. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  1966. if (file.hasFileExtension (".c")) return "sourcecode.c.c";
  1967. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  1968. if (file.hasFileExtension (asmFileExtensions)) return "sourcecode.c.asm";
  1969. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  1970. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  1971. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  1972. if (file.hasFileExtension ("html;htm")) return "text.html";
  1973. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  1974. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  1975. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  1976. if (file.hasFileExtension ("entitlements")) return "text.plist.xml";
  1977. if (file.hasFileExtension ("app")) return "wrapper.application";
  1978. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  1979. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  1980. if (file.hasFileExtension ("a")) return "archive.ar";
  1981. if (file.hasFileExtension ("xcassets")) return "folder.assetcatalog";
  1982. return "file" + file.getFileExtension();
  1983. }
  1984. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources,
  1985. bool shouldBeAddedToXcodeResources, bool inhibitWarnings, XcodeTarget* xcodeTarget) const
  1986. {
  1987. const String pathAsString (path.toUnixStyle());
  1988. const String refID (addFileReference (path.toUnixStyle()));
  1989. if (shouldBeCompiled)
  1990. {
  1991. addBuildFile (pathAsString, refID, true, inhibitWarnings, xcodeTarget);
  1992. }
  1993. else if (! shouldBeAddedToBinaryResources || shouldBeAddedToXcodeResources)
  1994. {
  1995. const String fileType (getFileType (path));
  1996. if (shouldBeAddedToXcodeResources)
  1997. {
  1998. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  1999. resourceFileRefs.add (refID);
  2000. }
  2001. }
  2002. return refID;
  2003. }
  2004. String addRezFile (const Project::Item& projectItem, const RelativePath& path) const
  2005. {
  2006. const String pathAsString (path.toUnixStyle());
  2007. const String refID (addFileReference (path.toUnixStyle()));
  2008. if (projectItem.isModuleCode())
  2009. {
  2010. if (XcodeTarget* xcodeTarget = getTargetOfType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), false)))
  2011. {
  2012. String rezFileID = addBuildFile (pathAsString, refID, false, false, xcodeTarget);
  2013. xcodeTarget->rezFileIDs.add (rezFileID);
  2014. return refID;
  2015. }
  2016. }
  2017. return {};
  2018. }
  2019. String getEntitlementsFileName() const
  2020. {
  2021. return project.getProjectFilenameRoot() + String (".entitlements");
  2022. }
  2023. StringPairArray getEntitlements() const
  2024. {
  2025. StringPairArray entitlements;
  2026. if (project.getProjectType().isAudioPlugin())
  2027. {
  2028. if (isiOS())
  2029. {
  2030. if (project.shouldEnableIAA())
  2031. entitlements.set ("inter-app-audio", "<true/>");
  2032. }
  2033. else
  2034. {
  2035. entitlements.set ("com.apple.security.app-sandbox", "<true/>");
  2036. }
  2037. }
  2038. else
  2039. {
  2040. if (isPushNotificationsEnabled())
  2041. entitlements.set (isiOS() ? "aps-environment"
  2042. : "com.apple.developer.aps-environment",
  2043. "<string>development</string>");
  2044. }
  2045. if (isAppGroupsEnabled())
  2046. {
  2047. auto appGroups = StringArray::fromTokens (getAppGroupIdString(), ";", { });
  2048. auto groups = String ("<array>");
  2049. for (auto group : appGroups)
  2050. groups += "\n\t\t<string>" + group.trim() + "</string>";
  2051. groups += "\n\t</array>";
  2052. entitlements.set ("com.apple.security.application-groups", groups);
  2053. }
  2054. if (isiOS() && isiCloudPermissionsEnabled())
  2055. {
  2056. entitlements.set ("com.apple.developer.icloud-container-identifiers",
  2057. "<array>\n"
  2058. " <string>iCloud.$(CFBundleIdentifier)</string>\n"
  2059. " </array>");
  2060. entitlements.set ("com.apple.developer.icloud-services",
  2061. "<array>\n"
  2062. " <string>CloudDocuments</string>\n"
  2063. " </array>");
  2064. entitlements.set ("com.apple.developer.ubiquity-container-identifiers",
  2065. "<array>\n"
  2066. " <string>iCloud.$(CFBundleIdentifier)</string>\n"
  2067. " </array>");
  2068. }
  2069. return entitlements;
  2070. }
  2071. String addEntitlementsFile (StringPairArray entitlements) const
  2072. {
  2073. String content =
  2074. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2075. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  2076. "<plist version=\"1.0\">\n"
  2077. "<dict>\n";
  2078. const auto keys = entitlements.getAllKeys();
  2079. for (auto& key : keys)
  2080. {
  2081. content += "\t<key>" + key + "</key>\n"
  2082. "\t" + entitlements[key] + "\n";
  2083. }
  2084. content += "</dict>\n"
  2085. "</plist>\n";
  2086. File entitlementsFile = getTargetFolder().getChildFile (getEntitlementsFileName());
  2087. overwriteFileIfDifferentOrThrow (entitlementsFile, content);
  2088. RelativePath plistPath (entitlementsFile, getTargetFolder(), RelativePath::buildTargetFolder);
  2089. return addFile (plistPath, false, false, false, false, nullptr);
  2090. }
  2091. String addProjectItem (const Project::Item& projectItem) const
  2092. {
  2093. if (modulesGroup != nullptr && projectItem.getParent() == *modulesGroup)
  2094. return addFileReference (rebaseFromProjectFolderToBuildTarget (getModuleFolderRelativeToProject (projectItem.getName())).toUnixStyle());
  2095. if (projectItem.isGroup())
  2096. {
  2097. StringArray childIDs;
  2098. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  2099. {
  2100. const String childID (addProjectItem (projectItem.getChild(i)));
  2101. if (childID.isNotEmpty())
  2102. childIDs.add (childID);
  2103. }
  2104. return addGroup (projectItem, childIDs);
  2105. }
  2106. if (projectItem.shouldBeAddedToTargetProject())
  2107. {
  2108. const String itemPath (projectItem.getFilePath());
  2109. RelativePath path;
  2110. if (itemPath.startsWith ("${"))
  2111. path = RelativePath (itemPath, RelativePath::unknown);
  2112. else
  2113. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  2114. if (path.hasFileExtension (".r"))
  2115. return addRezFile (projectItem, path);
  2116. XcodeTarget* xcodeTarget = nullptr;
  2117. if (projectItem.isModuleCode() && projectItem.shouldBeCompiled())
  2118. xcodeTarget = getTargetOfType (project.getTargetTypeFromFilePath (projectItem.getFile(), false));
  2119. return addFile (path, projectItem.shouldBeCompiled(),
  2120. projectItem.shouldBeAddedToBinaryResources(),
  2121. projectItem.shouldBeAddedToXcodeResources(),
  2122. projectItem.shouldInhibitWarnings(),
  2123. xcodeTarget);
  2124. }
  2125. return {};
  2126. }
  2127. String addFramework (const String& frameworkName) const
  2128. {
  2129. String path (frameworkName);
  2130. if (! File::isAbsolutePath (path))
  2131. path = "System/Library/Frameworks/" + path;
  2132. if (! path.endsWithIgnoreCase (".framework"))
  2133. path << ".framework";
  2134. const String fileRefID (createFileRefID (path));
  2135. addFileReference ((File::isAbsolutePath (frameworkName) ? "" : "${SDKROOT}/") + path);
  2136. frameworkFileIDs.add (fileRefID);
  2137. return addBuildFile (path, fileRefID, false, false);
  2138. }
  2139. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  2140. {
  2141. ValueTree* v = new ValueTree (groupID);
  2142. v->setProperty ("isa", "PBXGroup", nullptr);
  2143. v->setProperty ("children", indentParenthesisedList (childIDs), nullptr);
  2144. v->setProperty (Ids::name, groupName, nullptr);
  2145. v->setProperty ("sourceTree", "<group>", nullptr);
  2146. pbxGroups.add (v);
  2147. }
  2148. String addGroup (const Project::Item& item, StringArray& childIDs) const
  2149. {
  2150. const String groupName (item.getName());
  2151. const String groupID (getIDForGroup (item));
  2152. addGroup (groupID, groupName, childIDs);
  2153. return groupID;
  2154. }
  2155. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  2156. {
  2157. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  2158. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  2159. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  2160. v->setProperty (Ids::name, configName, nullptr);
  2161. projectConfigs.add (v);
  2162. }
  2163. void addConfigList (XcodeTarget& target, const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  2164. {
  2165. ValueTree* v = new ValueTree (listID);
  2166. v->setProperty ("isa", "XCConfigurationList", nullptr);
  2167. v->setProperty ("buildConfigurations", indentParenthesisedList (target.configIDs), nullptr);
  2168. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  2169. if (auto* first = configsToUse.getFirst())
  2170. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  2171. misc.add (v);
  2172. }
  2173. void addProjectConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  2174. {
  2175. StringArray configIDs;
  2176. for (auto* c : configsToUse)
  2177. configIDs.add (c->getType().toString());
  2178. ValueTree* v = new ValueTree (listID);
  2179. v->setProperty ("isa", "XCConfigurationList", nullptr);
  2180. v->setProperty ("buildConfigurations", indentParenthesisedList (configIDs), nullptr);
  2181. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  2182. if (auto* first = configsToUse.getFirst())
  2183. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  2184. misc.add (v);
  2185. }
  2186. void addProjectObject() const
  2187. {
  2188. ValueTree* const v = new ValueTree (createID ("__root"));
  2189. v->setProperty ("isa", "PBXProject", nullptr);
  2190. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  2191. v->setProperty ("attributes", getProjectObjectAttributes(), nullptr);
  2192. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  2193. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  2194. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  2195. v->setProperty ("projectDirPath", "\"\"", nullptr);
  2196. v->setProperty ("projectRoot", "\"\"", nullptr);
  2197. String targetString = "(" + targetIDs.joinIntoString (", ") + ")";
  2198. v->setProperty ("targets", targetString, nullptr);
  2199. misc.add (v);
  2200. }
  2201. //==============================================================================
  2202. void removeMismatchedXcuserdata() const
  2203. {
  2204. if (settings ["keepCustomXcodeSchemes"])
  2205. return;
  2206. File xcuserdata = getProjectBundle().getChildFile ("xcuserdata");
  2207. if (! xcuserdata.exists())
  2208. return;
  2209. if (! xcuserdataMatchesTargets (xcuserdata))
  2210. {
  2211. xcuserdata.deleteRecursively();
  2212. getProjectBundle().getChildFile ("project.xcworkspace").deleteRecursively();
  2213. }
  2214. }
  2215. bool xcuserdataMatchesTargets (const File& xcuserdata) const
  2216. {
  2217. Array<File> xcschemeManagementPlists;
  2218. xcuserdata.findChildFiles (xcschemeManagementPlists, File::findFiles, true, "xcschememanagement.plist");
  2219. for (auto& plist : xcschemeManagementPlists)
  2220. if (! xcschemeManagementPlistMatchesTargets (plist))
  2221. return false;
  2222. return true;
  2223. }
  2224. static StringArray parseNamesOfTargetsFromPlist (const XmlElement& dictXML)
  2225. {
  2226. forEachXmlChildElementWithTagName (dictXML, schemesKey, "key")
  2227. {
  2228. if (schemesKey->getAllSubText().trim().equalsIgnoreCase ("SchemeUserState"))
  2229. {
  2230. if (auto* dict = schemesKey->getNextElement())
  2231. {
  2232. if (dict->hasTagName ("dict"))
  2233. {
  2234. StringArray names;
  2235. forEachXmlChildElementWithTagName (*dict, key, "key")
  2236. names.add (key->getAllSubText().upToLastOccurrenceOf (".xcscheme", false, false).trim());
  2237. names.sort (false);
  2238. return names;
  2239. }
  2240. }
  2241. }
  2242. }
  2243. return {};
  2244. }
  2245. StringArray getNamesOfTargets() const
  2246. {
  2247. StringArray names;
  2248. for (auto& target : targets)
  2249. names.add (target->getXcodeSchemeName());
  2250. names.sort (false);
  2251. return names;
  2252. }
  2253. bool xcschemeManagementPlistMatchesTargets (const File& plist) const
  2254. {
  2255. ScopedPointer<XmlElement> xml (XmlDocument::parse (plist));
  2256. if (xml != nullptr)
  2257. if (auto* dict = xml->getChildByName ("dict"))
  2258. return parseNamesOfTargetsFromPlist (*dict) == getNamesOfTargets();
  2259. return false;
  2260. }
  2261. //==============================================================================
  2262. struct AppIconType
  2263. {
  2264. const char* idiom;
  2265. const char* sizeString;
  2266. const char* filename;
  2267. const char* scale;
  2268. int size;
  2269. };
  2270. static Array<AppIconType> getiOSAppIconTypes()
  2271. {
  2272. AppIconType types[] =
  2273. {
  2274. { "iphone", "20x20", "Icon-Notification-20@2x.png", "2x", 40 },
  2275. { "iphone", "20x20", "Icon-Notification-20@3x.png", "3x", 60 },
  2276. { "iphone", "29x29", "Icon-29.png", "1x", 29 },
  2277. { "iphone", "29x29", "Icon-29@2x.png", "2x", 58 },
  2278. { "iphone", "29x29", "Icon-29@3x.png", "3x", 87 },
  2279. { "iphone", "40x40", "Icon-Spotlight-40@2x.png", "2x", 80 },
  2280. { "iphone", "40x40", "Icon-Spotlight-40@3x.png", "3x", 120 },
  2281. { "iphone", "57x57", "Icon.png", "1x", 57 },
  2282. { "iphone", "57x57", "Icon@2x.png", "2x", 114 },
  2283. { "iphone", "60x60", "Icon-60@2x.png", "2x", 120 },
  2284. { "iphone", "60x60", "Icon-@3x.png", "3x", 180 },
  2285. { "ipad", "20x20", "Icon-Notifications-20.png", "1x", 20 },
  2286. { "ipad", "20x20", "Icon-Notifications-20@2x.png", "2x", 40 },
  2287. { "ipad", "29x29", "Icon-Small-1.png", "1x", 29 },
  2288. { "ipad", "29x29", "Icon-Small@2x-1.png", "2x", 58 },
  2289. { "ipad", "40x40", "Icon-Spotlight-40.png", "1x", 40 },
  2290. { "ipad", "40x40", "Icon-Spotlight-40@2x-1.png", "2x", 80 },
  2291. { "ipad", "50x50", "Icon-Small-50.png", "1x", 50 },
  2292. { "ipad", "50x50", "Icon-Small-50@2x.png", "2x", 100 },
  2293. { "ipad", "72x72", "Icon-72.png", "1x", 72 },
  2294. { "ipad", "72x72", "Icon-72@2x.png", "2x", 144 },
  2295. { "ipad", "76x76", "Icon-76.png", "1x", 76 },
  2296. { "ipad", "76x76", "Icon-76@2x.png", "2x", 152 },
  2297. { "ipad", "83.5x83.5", "Icon-83.5@2x.png", "2x", 167 },
  2298. { "ios-marketing", "1024x1024", "Icon-AppStore-1024.png", "1x", 1024 }
  2299. };
  2300. return Array<AppIconType> (types, numElementsInArray (types));
  2301. }
  2302. static String getiOSAppIconContents()
  2303. {
  2304. var images;
  2305. for (auto& type : getiOSAppIconTypes())
  2306. {
  2307. DynamicObject::Ptr d = new DynamicObject();
  2308. d->setProperty ("idiom", type.idiom);
  2309. d->setProperty ("size", type.sizeString);
  2310. d->setProperty ("filename", type.filename);
  2311. d->setProperty ("scale", type.scale);
  2312. images.append (var (d.get()));
  2313. }
  2314. return getiOSAssetContents (images);
  2315. }
  2316. String getProjectObjectAttributes() const
  2317. {
  2318. String attributes;
  2319. attributes << "{ LastUpgradeCheck = 0830; "
  2320. << "ORGANIZATIONNAME = " << getProject().getCompanyNameString().quoted()
  2321. <<"; ";
  2322. if (projectType.isGUIApplication() || projectType.isAudioPlugin())
  2323. {
  2324. attributes << "TargetAttributes = { ";
  2325. for (auto& target : targets)
  2326. attributes << target->getTargetAttributes();
  2327. attributes << " }; ";
  2328. }
  2329. attributes << "}";
  2330. return attributes;
  2331. }
  2332. //==============================================================================
  2333. struct ImageType
  2334. {
  2335. const char* orientation;
  2336. const char* idiom;
  2337. const char* subtype;
  2338. const char* extent;
  2339. const char* scale;
  2340. const char* filename;
  2341. int width;
  2342. int height;
  2343. };
  2344. static Array<ImageType> getiOSLaunchImageTypes()
  2345. {
  2346. ImageType types[] =
  2347. {
  2348. { "portrait", "iphone", nullptr, "full-screen", "2x", "LaunchImage-iphone-2x.png", 640, 960 },
  2349. { "portrait", "iphone", "retina4", "full-screen", "2x", "LaunchImage-iphone-retina4.png", 640, 1136 },
  2350. { "portrait", "ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-portrait-1x.png", 768, 1024 },
  2351. { "landscape","ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-landscape-1x.png", 1024, 768 },
  2352. { "portrait", "ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-portrait-2x.png", 1536, 2048 },
  2353. { "landscape","ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-landscape-2x.png", 2048, 1536 }
  2354. };
  2355. return Array<ImageType> (types, numElementsInArray (types));
  2356. }
  2357. static String getiOSLaunchImageContents()
  2358. {
  2359. var images;
  2360. for (auto& type : getiOSLaunchImageTypes())
  2361. {
  2362. DynamicObject::Ptr d = new DynamicObject();
  2363. d->setProperty ("orientation", type.orientation);
  2364. d->setProperty ("idiom", type.idiom);
  2365. d->setProperty ("extent", type.extent);
  2366. d->setProperty ("minimum-system-version", "7.0");
  2367. d->setProperty ("scale", type.scale);
  2368. d->setProperty ("filename", type.filename);
  2369. if (type.subtype != nullptr)
  2370. d->setProperty ("subtype", type.subtype);
  2371. images.append (var (d.get()));
  2372. }
  2373. return getiOSAssetContents (images);
  2374. }
  2375. static void createiOSLaunchImageFiles (const File& launchImageSet)
  2376. {
  2377. for (auto& type : getiOSLaunchImageTypes())
  2378. {
  2379. Image image (Image::ARGB, type.width, type.height, true); // (empty black image)
  2380. image.clear (image.getBounds(), Colours::black);
  2381. MemoryOutputStream pngData;
  2382. PNGImageFormat pngFormat;
  2383. pngFormat.writeImageToStream (image, pngData);
  2384. overwriteFileIfDifferentOrThrow (launchImageSet.getChildFile (type.filename), pngData);
  2385. }
  2386. }
  2387. //==============================================================================
  2388. static String getiOSAssetContents (var images)
  2389. {
  2390. DynamicObject::Ptr v (new DynamicObject());
  2391. var info (new DynamicObject());
  2392. info.getDynamicObject()->setProperty ("version", 1);
  2393. info.getDynamicObject()->setProperty ("author", "xcode");
  2394. v->setProperty ("images", images);
  2395. v->setProperty ("info", info);
  2396. return JSON::toString (var (v.get()));
  2397. }
  2398. void createXcassetsFolderFromIcons() const
  2399. {
  2400. const File assets (getTargetFolder().getChildFile (project.getProjectFilenameRoot())
  2401. .getChildFile ("Images.xcassets"));
  2402. const File iconSet (assets.getChildFile ("AppIcon.appiconset"));
  2403. const File launchImage (assets.getChildFile ("LaunchImage.launchimage"));
  2404. overwriteFileIfDifferentOrThrow (iconSet.getChildFile ("Contents.json"), getiOSAppIconContents());
  2405. createiOSIconFiles (iconSet);
  2406. overwriteFileIfDifferentOrThrow (launchImage.getChildFile ("Contents.json"), getiOSLaunchImageContents());
  2407. createiOSLaunchImageFiles (launchImage);
  2408. RelativePath assetsPath (assets, getTargetFolder(), RelativePath::buildTargetFolder);
  2409. addFileReference (assetsPath.toUnixStyle());
  2410. resourceIDs.add (addBuildFile (assetsPath, false, false));
  2411. resourceFileRefs.add (createFileRefID (assetsPath));
  2412. }
  2413. //==============================================================================
  2414. static String indentBracedList (const StringArray& list) { return "{" + indentList (list, ";", 0, true) + " }"; }
  2415. static String indentParenthesisedList (const StringArray& list) { return "(" + indentList (list, ",", 1, false) + " )"; }
  2416. static String indentList (const StringArray& list, const String& separator, int extraTabs, bool shouldSort)
  2417. {
  2418. if (list.size() == 0)
  2419. return " ";
  2420. const String tabs ("\n" + String::repeatedString ("\t", extraTabs + 4));
  2421. if (shouldSort)
  2422. {
  2423. StringArray sorted (list);
  2424. sorted.sort (true);
  2425. return tabs + sorted.joinIntoString (separator + tabs) + separator;
  2426. }
  2427. return tabs + list.joinIntoString (separator + tabs) + separator;
  2428. }
  2429. String createID (String rootString) const
  2430. {
  2431. if (rootString.startsWith ("${"))
  2432. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  2433. rootString += project.getProjectUID();
  2434. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  2435. }
  2436. String createFileRefID (const RelativePath& path) const { return createFileRefID (path.toUnixStyle()); }
  2437. String createFileRefID (const String& path) const { return createID ("__fileref_" + path); }
  2438. String getIDForGroup (const Project::Item& item) const { return createID (item.getID()); }
  2439. bool shouldFileBeCompiledByDefault (const RelativePath& file) const override
  2440. {
  2441. return file.hasFileExtension (sourceFileExtensions);
  2442. }
  2443. static String getOSXVersionName (int version)
  2444. {
  2445. jassert (version >= 4);
  2446. return "10." + String (version);
  2447. }
  2448. static String getSDKName (int version)
  2449. {
  2450. return getOSXVersionName (version) + " SDK";
  2451. }
  2452. JUCE_DECLARE_NON_COPYABLE (XcodeProjectExporter)
  2453. };