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.

2877 lines
128KB

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