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.

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