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.

2876 lines
128KB

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