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.

2868 lines
127KB

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