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.

2885 lines
128KB

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