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.

2907 lines
130KB

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