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.

2759 lines
121KB

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