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.

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