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.

3025 lines
135KB

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