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.

2903 lines
129KB

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