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.

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