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.

2918 lines
130KB

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