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.

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