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.

2743 lines
120KB

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