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.

2994 lines
133KB

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