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.

2662 lines
117KB

  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. addExtraAAXTargetSettings();
  493. break;
  494. case RTASPlugIn:
  495. xcodePackageType = "TDMw";
  496. xcodeBundleSignature = "PTul";
  497. xcodeFileType = "wrapper.cfbundle";
  498. xcodeBundleExtension = ".dpm";
  499. xcodeProductType = "com.apple.product-type.bundle";
  500. xcodeCopyToProductInstallPathAfterBuild = true;
  501. addExtraRTASTargetSettings();
  502. break;
  503. case SharedCodeTarget:
  504. xcodeFileType = "archive.ar";
  505. xcodeProductType = "com.apple.product-type.library.static";
  506. xcodeCopyToProductInstallPathAfterBuild = false;
  507. break;
  508. case AggregateTarget:
  509. xcodeCopyToProductInstallPathAfterBuild = false;
  510. break;
  511. default:
  512. // unknown target type!
  513. jassertfalse;
  514. break;
  515. }
  516. }
  517. String getXCodeSchemeName() const
  518. {
  519. return owner.projectName + " - " + getName();
  520. }
  521. String getID() const
  522. {
  523. return owner.createID (String ("__target") + getName());
  524. }
  525. String getInfoPlistName() const
  526. {
  527. return String ("Info-") + String (getName()).replace (" ", "_") + String (".plist");
  528. }
  529. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  530. String xcodeProductType, xcodeFileType;
  531. String xcodeOtherRezFlags, xcodeExcludedFiles64Bit, xcodeBundleIDSubPath;
  532. bool xcodeCopyToProductInstallPathAfterBuild;
  533. StringArray xcodeFrameworks, xcodeLibs;
  534. Array<XmlElement> xcodeExtraPListEntries;
  535. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  536. StringArray frameworkIDs, buildPhaseIDs, configIDs, sourceIDs, rezFileIDs;
  537. String dependencyID, mainBuildProductID;
  538. File infoPlistFile;
  539. //==============================================================================
  540. void addMainBuildProduct() const
  541. {
  542. jassert (xcodeFileType.isNotEmpty());
  543. jassert (xcodeBundleExtension.isEmpty() || xcodeBundleExtension.startsWithChar ('.'));
  544. if (ProjectExporter::BuildConfiguration::Ptr config = owner.getConfiguration(0))
  545. {
  546. String productName (owner.replacePreprocessorTokens (*config, config->getTargetBinaryNameString()));
  547. if (xcodeFileType == "archive.ar")
  548. productName = getStaticLibbedFilename (productName);
  549. else
  550. productName += xcodeBundleExtension;
  551. addBuildProduct (xcodeFileType, productName);
  552. }
  553. }
  554. //==============================================================================
  555. void addBuildProduct (const String& fileType, const String& binaryName) const
  556. {
  557. ValueTree* v = new ValueTree (owner.createID (String ("__productFileID") + getName()));
  558. v->setProperty ("isa", "PBXFileReference", nullptr);
  559. v->setProperty ("explicitFileType", fileType, nullptr);
  560. v->setProperty ("includeInIndex", (int) 0, nullptr);
  561. v->setProperty ("path", sanitisePath (binaryName), nullptr);
  562. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", nullptr);
  563. owner.pbxFileReferences.add (v);
  564. }
  565. //==============================================================================
  566. void addDependency()
  567. {
  568. jassert (dependencyID.isEmpty());
  569. dependencyID = owner.createID (String ("__dependency") + getName());
  570. ValueTree* const v = new ValueTree (dependencyID);
  571. v->setProperty ("isa", "PBXTargetDependency", nullptr);
  572. v->setProperty ("target", getID(), nullptr);
  573. owner.misc.add (v);
  574. }
  575. String getDependencyID() const
  576. {
  577. jassert (dependencyID.isNotEmpty());
  578. return dependencyID;
  579. }
  580. //==============================================================================
  581. void addTargetConfig (const String& configName, const StringArray& buildSettings)
  582. {
  583. String configID = owner.createID (String ("targetconfigid_") + getName() + String ("_") + configName);
  584. ValueTree* v = new ValueTree (configID);
  585. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  586. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  587. v->setProperty (Ids::name, configName, nullptr);
  588. configIDs.add (configID);
  589. owner.targetConfigs.add (v);
  590. }
  591. //==============================================================================
  592. String getTargetAttributes() const
  593. {
  594. String attributes;
  595. attributes << getID() << " = { ";
  596. String developmentTeamID = owner.getIosDevelopmentTeamIDString();
  597. if (developmentTeamID.isNotEmpty())
  598. attributes << "DevelopmentTeam = " << developmentTeamID << "; ";
  599. const int inAppPurchasesEnabled = (owner.iOS && owner.isInAppPurchasesEnabled()) ? 1 : 0;
  600. const int sandboxEnabled = (type == Target::AudioUnitv3PlugIn ? 1 : 0);
  601. attributes << "SystemCapabilities = {";
  602. attributes << "com.apple.InAppPurchase = { enabled = " << inAppPurchasesEnabled << "; }; ";
  603. attributes << "com.apple.Sandbox = { enabled = " << sandboxEnabled << "; }; ";
  604. attributes << "}; };";
  605. return attributes;
  606. }
  607. //==============================================================================
  608. ValueTree& addBuildPhase (const String& buildPhaseType, const StringArray& fileIds, const StringRef humanReadableName = StringRef())
  609. {
  610. String buildPhaseName = buildPhaseType + String ("_") + getName() + String ("_") + (humanReadableName.isNotEmpty() ? String (humanReadableName) : String ("resbuildphase"));
  611. String buildPhaseId (owner.createID (buildPhaseName));
  612. int n = 0;
  613. while (buildPhaseIDs.contains (buildPhaseId))
  614. buildPhaseId = owner.createID (buildPhaseName + String (++n));
  615. buildPhaseIDs.add (buildPhaseId);
  616. ValueTree* v = new ValueTree (buildPhaseId);
  617. v->setProperty ("isa", buildPhaseType, nullptr);
  618. v->setProperty ("buildActionMask", "2147483647", nullptr);
  619. v->setProperty ("files", indentParenthesisedList (fileIds), nullptr);
  620. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, nullptr);
  621. if (humanReadableName.isNotEmpty())
  622. v->setProperty ("name", String (humanReadableName), nullptr);
  623. owner.misc.add (v);
  624. return *v;
  625. }
  626. bool shouldCreatePList() const
  627. {
  628. const ProjectType::Target::TargetFileType fileType = getTargetFileType();
  629. return (fileType == executable && type != ConsoleApp) || fileType == pluginBundle || fileType == macOSAppex;
  630. }
  631. //==============================================================================
  632. StringArray getTargetSettings (const XcodeBuildConfiguration& config) const
  633. {
  634. if (type == AggregateTarget)
  635. // the aggregate target should not specify any settings at all!
  636. // it just defines dependencies on the other targets.
  637. return StringArray();
  638. StringArray s;
  639. String bundleIdentifier = owner.project.getBundleIdentifier().toString();
  640. if (xcodeBundleIDSubPath.isNotEmpty())
  641. {
  642. StringArray bundleIdSegments = StringArray::fromTokens (bundleIdentifier, ".", StringRef());
  643. jassert (bundleIdSegments.size() > 0);
  644. bundleIdentifier += String (".") + bundleIdSegments[bundleIdSegments.size() - 1] + xcodeBundleIDSubPath;
  645. }
  646. s.add ("PRODUCT_BUNDLE_IDENTIFIER = " + bundleIdentifier);
  647. const String arch ((! owner.isiOS() && type == Target::AudioUnitv3PlugIn) ? osxArch_64Bit : config.osxArchitecture.get());
  648. if (arch == osxArch_Native) s.add ("ARCHS = \"$(NATIVE_ARCH_ACTUAL)\"");
  649. else if (arch == osxArch_32BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  650. else if (arch == osxArch_64BitUniversal) s.add ("ARCHS = \"$(ARCHS_STANDARD_32_64_BIT)\"");
  651. else if (arch == osxArch_64Bit) s.add ("ARCHS = \"$(ARCHS_STANDARD_64_BIT)\"");
  652. s.add ("HEADER_SEARCH_PATHS = " + getHeaderSearchPaths (config));
  653. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  654. if (shouldCreatePList())
  655. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  656. if (config.linkTimeOptimisationEnabled.get())
  657. s.add ("LLVM_LTO = YES");
  658. if (config.fastMathEnabled.get())
  659. s.add ("GCC_FAST_MATH = YES");
  660. const String extraFlags (owner.replacePreprocessorTokens (config, owner.getExtraCompilerFlagsString()).trim());
  661. if (extraFlags.isNotEmpty())
  662. s.add ("OTHER_CPLUSPLUSFLAGS = \"" + extraFlags + "\"");
  663. String installPath = getInstallPathForConfiguration (config);
  664. if (installPath.isNotEmpty())
  665. {
  666. s.add ("INSTALL_PATH = \"" + installPath + "\"");
  667. if (xcodeCopyToProductInstallPathAfterBuild)
  668. {
  669. s.add ("DEPLOYMENT_LOCATION = YES");
  670. s.add ("DSTROOT = /");
  671. }
  672. }
  673. if (getTargetFileType() == pluginBundle)
  674. {
  675. s.add ("LIBRARY_STYLE = Bundle");
  676. s.add ("WRAPPER_EXTENSION = " + xcodeBundleExtension.substring (1));
  677. s.add ("GENERATE_PKGINFO_FILE = YES");
  678. }
  679. if (xcodeOtherRezFlags.isNotEmpty())
  680. s.add ("OTHER_REZFLAGS = \"" + xcodeOtherRezFlags + "\"");
  681. String configurationBuildDir = "$(PROJECT_DIR)/build/$(CONFIGURATION)";
  682. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  683. {
  684. // a target's position can either be defined via installPath + xcodeCopyToProductInstallPathAfterBuild
  685. // (= for audio plug-ins) or using a custom binary path (for everything else), but not both (= conflict!)
  686. jassert (! xcodeCopyToProductInstallPathAfterBuild);
  687. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  688. configurationBuildDir = sanitisePath (binaryPath.rebased (owner.projectFolder, owner.getTargetFolder(), RelativePath::buildTargetFolder)
  689. .toUnixStyle());
  690. }
  691. s.add ("CONFIGURATION_BUILD_DIR = " + addQuotesIfRequired (configurationBuildDir));
  692. String gccVersion ("com.apple.compilers.llvm.clang.1_0");
  693. if (owner.iOS)
  694. {
  695. s.add ("ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon");
  696. s.add ("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage");
  697. }
  698. else
  699. {
  700. const String sdk (config.osxSDKVersion.get());
  701. const String sdkCompat (config.osxDeploymentTarget.get());
  702. // The AUv3 target always needs to be at least 10.11
  703. int oldestAllowedDeploymentTarget = (type == Target::AudioUnitv3PlugIn ? minimumAUv3SDKVersion
  704. : oldestSDKVersion);
  705. // if the user doesn't set it, then use the last known version that works well with JUCE
  706. String deploymentTarget = "10.11";
  707. for (int ver = oldestAllowedDeploymentTarget; ver <= currentSDKVersion; ++ver)
  708. {
  709. if (sdk == getSDKName (ver)) s.add ("SDKROOT = macosx10." + String (ver));
  710. if (sdkCompat == getSDKName (ver)) deploymentTarget = "10." + String (ver);
  711. }
  712. s.add ("MACOSX_DEPLOYMENT_TARGET = " + deploymentTarget);
  713. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  714. s.add ("SDKROOT_ppc = macosx10.5");
  715. if (xcodeExcludedFiles64Bit.isNotEmpty())
  716. {
  717. s.add ("EXCLUDED_SOURCE_FILE_NAMES = \"$(EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))\"");
  718. s.add ("EXCLUDED_SOURCE_FILE_NAMES_x86_64 = " + xcodeExcludedFiles64Bit);
  719. }
  720. }
  721. s.add ("GCC_VERSION = " + gccVersion);
  722. s.add ("CLANG_CXX_LANGUAGE_STANDARD = \"c++0x\"");
  723. s.add ("CLANG_LINK_OBJC_RUNTIME = NO");
  724. if (! config.codeSignIdentity.isUsingDefault())
  725. s.add ("CODE_SIGN_IDENTITY = " + config.codeSignIdentity.get().quoted());
  726. if (config.cppLanguageStandard.get().isNotEmpty())
  727. s.add ("CLANG_CXX_LANGUAGE_STANDARD = " + config.cppLanguageStandard.get().quoted());
  728. if (config.cppStandardLibrary.get().isNotEmpty())
  729. s.add ("CLANG_CXX_LIBRARY = " + config.cppStandardLibrary.get().quoted());
  730. s.add ("COMBINE_HIDPI_IMAGES = YES");
  731. {
  732. StringArray linkerFlags, librarySearchPaths;
  733. getLinkerSettings (config, linkerFlags, librarySearchPaths);
  734. if (linkerFlags.size() > 0)
  735. s.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  736. librarySearchPaths.addArray (config.getLibrarySearchPaths());
  737. librarySearchPaths = getCleanedStringArray (librarySearchPaths);
  738. if (librarySearchPaths.size() > 0)
  739. {
  740. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  741. for (auto& p : librarySearchPaths)
  742. libPaths += ", \"\\\"" + p + "\\\"\"";
  743. s.add (libPaths + ")");
  744. }
  745. }
  746. StringPairArray defines;
  747. if (config.isDebug())
  748. {
  749. defines.set ("_DEBUG", "1");
  750. defines.set ("DEBUG", "1");
  751. s.add ("COPY_PHASE_STRIP = NO");
  752. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  753. }
  754. else
  755. {
  756. defines.set ("_NDEBUG", "1");
  757. defines.set ("NDEBUG", "1");
  758. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  759. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  760. s.add ("DEAD_CODE_STRIPPING = YES");
  761. }
  762. if (type != Target::SharedCodeTarget && type != Target::StaticLibrary && type != Target::DynamicLibrary
  763. && config.stripLocalSymbolsEnabled.get())
  764. {
  765. s.add ("STRIPFLAGS = \"-x\"");
  766. s.add ("DEPLOYMENT_POSTPROCESSING = YES");
  767. s.add ("SEPARATE_STRIP = YES");
  768. }
  769. if (owner.project.getProjectType().isAudioPlugin() && type == Target::AudioUnitv3PlugIn && owner.isOSX())
  770. s.add (String ("CODE_SIGN_ENTITLEMENTS = \"") + owner.getEntitlementsFileName() + String ("\""));
  771. defines = mergePreprocessorDefs (defines, owner.getAllPreprocessorDefs (config, type));
  772. StringArray defsList;
  773. for (int i = 0; i < defines.size(); ++i)
  774. {
  775. String def (defines.getAllKeys()[i]);
  776. const String value (defines.getAllValues()[i]);
  777. if (value.isNotEmpty())
  778. def << "=" << value.replace ("\"", "\\\\\\\"");
  779. defsList.add ("\"" + def + "\"");
  780. }
  781. s.add ("GCC_PREPROCESSOR_DEFINITIONS = " + indentParenthesisedList (defsList));
  782. s.addTokens (config.customXcodeFlags.get(), ",", "\"'");
  783. return getCleanedStringArray (s);
  784. }
  785. String getInstallPathForConfiguration (const XcodeBuildConfiguration& config) const
  786. {
  787. switch (type)
  788. {
  789. case GUIApp: return "$(HOME)/Applications";
  790. case ConsoleApp: return "/usr/bin";
  791. case VSTPlugIn: return config.vstBinaryLocation.get();
  792. case VST3PlugIn: return config.vst3BinaryLocation.get();
  793. case AudioUnitPlugIn: return config.auBinaryLocation.get();
  794. case RTASPlugIn: return config.rtasBinaryLocation.get();
  795. case AAXPlugIn: return config.aaxBinaryLocation.get();
  796. case SharedCodeTarget: return owner.isiOS() ? "@executable_path/Frameworks" : "@executable_path/../Frameworks";
  797. default: return String();
  798. }
  799. }
  800. //==============================================================================
  801. void getLinkerSettings (const BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths) const
  802. {
  803. if (getTargetFileType() == pluginBundle)
  804. flags.add (owner.isiOS() ? "-bitcode_bundle" : "-bundle");
  805. const Array<RelativePath>& extraLibs = config.isDebug() ? xcodeExtraLibrariesDebug
  806. : xcodeExtraLibrariesRelease;
  807. for (auto& lib : extraLibs)
  808. {
  809. flags.add (getLinkerFlagForLib (lib.getFileNameWithoutExtension()));
  810. librarySearchPaths.add (owner.getSearchPathForStaticLibrary (lib));
  811. }
  812. if (owner.project.getProjectType().isAudioPlugin() && type != Target::SharedCodeTarget)
  813. {
  814. if (owner.getTargetOfType (Target::SharedCodeTarget) != nullptr)
  815. {
  816. String productName (getStaticLibbedFilename (owner.replacePreprocessorTokens (config, config.getTargetBinaryNameString())));
  817. RelativePath sharedCodelib (productName, RelativePath::buildTargetFolder);
  818. flags.add (getLinkerFlagForLib (sharedCodelib.getFileNameWithoutExtension()));
  819. }
  820. }
  821. flags.add (owner.replacePreprocessorTokens (config, owner.getExtraLinkerFlagsString()));
  822. flags.add (owner.getExternalLibraryFlags (config));
  823. StringArray libs (owner.xcodeLibs);
  824. libs.addArray (xcodeLibs);
  825. for (auto& l : libs)
  826. flags.add (getLinkerFlagForLib (l));
  827. flags = getCleanedStringArray (flags);
  828. }
  829. //========================================================================== c
  830. void writeInfoPlistFile() const
  831. {
  832. if (! shouldCreatePList())
  833. return;
  834. ScopedPointer<XmlElement> plist (XmlDocument::parse (owner.getPListToMergeString()));
  835. if (plist == nullptr || ! plist->hasTagName ("plist"))
  836. plist = new XmlElement ("plist");
  837. XmlElement* dict = plist->getChildByName ("dict");
  838. if (dict == nullptr)
  839. dict = plist->createNewChildElement ("dict");
  840. if (owner.iOS)
  841. {
  842. addPlistDictionaryKeyBool (dict, "LSRequiresIPhoneOS", true);
  843. if (owner.isMicrophonePermissionEnabled())
  844. addPlistDictionaryKey (dict, "NSMicrophoneUsageDescription", "This app requires microphone input.");
  845. if (type != AudioUnitv3PlugIn)
  846. addPlistDictionaryKeyBool (dict, "UIViewControllerBasedStatusBarAppearance", false);
  847. }
  848. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  849. if (! owner.iOS) // (NB: on iOS this causes error ITMS-90032 during publishing)
  850. addPlistDictionaryKey (dict, "CFBundleIconFile", owner.iconFile.exists() ? owner.iconFile.getFileName() : String());
  851. addPlistDictionaryKey (dict, "CFBundleIdentifier", "$(PRODUCT_BUNDLE_IDENTIFIER)");
  852. addPlistDictionaryKey (dict, "CFBundleName", owner.projectName);
  853. // needed by NSExtension on iOS
  854. addPlistDictionaryKey (dict, "CFBundleDisplayName", owner.projectName);
  855. addPlistDictionaryKey (dict, "CFBundlePackageType", xcodePackageType);
  856. addPlistDictionaryKey (dict, "CFBundleSignature", xcodeBundleSignature);
  857. addPlistDictionaryKey (dict, "CFBundleShortVersionString", owner.project.getVersionString());
  858. addPlistDictionaryKey (dict, "CFBundleVersion", owner.project.getVersionString());
  859. addPlistDictionaryKey (dict, "NSHumanReadableCopyright", owner.project.getCompanyName().toString());
  860. addPlistDictionaryKeyBool (dict, "NSHighResolutionCapable", true);
  861. StringArray documentExtensions;
  862. documentExtensions.addTokens (replacePreprocessorDefs (owner.getAllPreprocessorDefs(), owner.settings ["documentExtensions"]),
  863. ",", StringRef());
  864. documentExtensions.trim();
  865. documentExtensions.removeEmptyStrings (true);
  866. if (documentExtensions.size() > 0 && type != AudioUnitv3PlugIn)
  867. {
  868. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  869. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  870. XmlElement* arrayTag = nullptr;
  871. for (String ex : documentExtensions)
  872. {
  873. if (ex.startsWithChar ('.'))
  874. ex = ex.substring (1);
  875. if (arrayTag == nullptr)
  876. {
  877. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  878. arrayTag = dict2->createNewChildElement ("array");
  879. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  880. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  881. addPlistDictionaryKey (dict2, "CFBundleTypeIconFile", "Icon");
  882. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  883. }
  884. arrayTag->createNewChildElement ("string")->addTextElement (ex);
  885. }
  886. }
  887. if (owner.settings ["UIFileSharingEnabled"] && type != AudioUnitv3PlugIn)
  888. addPlistDictionaryKeyBool (dict, "UIFileSharingEnabled", true);
  889. if (owner.settings ["UIStatusBarHidden"] && type != AudioUnitv3PlugIn)
  890. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  891. if (owner.iOS && type != AudioUnitv3PlugIn)
  892. {
  893. // Forcing full screen disables the split screen feature and prevents error ITMS-90475
  894. addPlistDictionaryKeyBool (dict, "UIRequiresFullScreen", true);
  895. addPlistDictionaryKeyBool (dict, "UIStatusBarHidden", true);
  896. addIosScreenOrientations (dict);
  897. addIosBackgroundModes (dict);
  898. }
  899. for (auto& e : xcodeExtraPListEntries)
  900. dict->addChildElement (new XmlElement (e));
  901. MemoryOutputStream mo;
  902. plist->writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  903. overwriteFileIfDifferentOrThrow (infoPlistFile, mo);
  904. }
  905. //==============================================================================
  906. void addIosScreenOrientations (XmlElement* dict) const
  907. {
  908. String screenOrientation = owner.getScreenOrientationString();
  909. StringArray iOSOrientations;
  910. if (screenOrientation.contains ("portrait")) { iOSOrientations.add ("UIInterfaceOrientationPortrait"); }
  911. if (screenOrientation.contains ("landscape")) { iOSOrientations.add ("UIInterfaceOrientationLandscapeLeft"); iOSOrientations.add ("UIInterfaceOrientationLandscapeRight"); }
  912. addArrayToPlist (dict, "UISupportedInterfaceOrientations", iOSOrientations);
  913. }
  914. //==============================================================================
  915. void addIosBackgroundModes (XmlElement* dict) const
  916. {
  917. StringArray iosBackgroundModes;
  918. if (owner.isBackgroundAudioEnabled()) iosBackgroundModes.add ("audio");
  919. if (owner.isBackgroundBleEnabled()) iosBackgroundModes.add ("bluetooth-central");
  920. addArrayToPlist (dict, "UIBackgroundModes", iosBackgroundModes);
  921. }
  922. //==============================================================================
  923. static void addArrayToPlist (XmlElement* dict, String arrayKey, const StringArray& arrayElements)
  924. {
  925. dict->createNewChildElement ("key")->addTextElement (arrayKey);
  926. XmlElement* plistStringArray = dict->createNewChildElement ("array");
  927. for (auto& e : arrayElements)
  928. plistStringArray->createNewChildElement ("string")->addTextElement (e);
  929. }
  930. //==============================================================================
  931. void addShellScriptBuildPhase (const String& phaseName, const String& script)
  932. {
  933. if (script.trim().isNotEmpty())
  934. {
  935. ValueTree& v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  936. v.setProperty (Ids::name, phaseName, nullptr);
  937. v.setProperty ("shellPath", "/bin/sh", nullptr);
  938. v.setProperty ("shellScript", script.replace ("\\", "\\\\")
  939. .replace ("\"", "\\\"")
  940. .replace ("\r\n", "\\n")
  941. .replace ("\n", "\\n"), nullptr);
  942. }
  943. }
  944. void addCopyFilesPhase (const String& phaseName, const StringArray& files, XcodeCopyFilesDestinationIDs dst)
  945. {
  946. ValueTree& v = addBuildPhase ("PBXCopyFilesBuildPhase", files, phaseName);
  947. v.setProperty ("dstPath", "", nullptr);
  948. v.setProperty ("dstSubfolderSpec", (int) dst, nullptr);
  949. }
  950. //==============================================================================
  951. String getHeaderSearchPaths (const BuildConfiguration& config) const
  952. {
  953. StringArray paths (owner.extraSearchPaths);
  954. paths.addArray (config.getHeaderSearchPaths());
  955. paths.addArray (getTargetExtraHeaderSearchPaths());
  956. paths.add ("$(inherited)");
  957. paths = getCleanedStringArray (paths);
  958. for (auto& s : paths)
  959. {
  960. s = owner.replacePreprocessorTokens (config, s);
  961. if (s.containsChar (' '))
  962. s = "\"\\\"" + s + "\\\"\""; // crazy double quotes required when there are spaces..
  963. else
  964. s = "\"" + s + "\"";
  965. }
  966. return "(" + paths.joinIntoString (", ") + ")";
  967. }
  968. private:
  969. //==============================================================================
  970. void addExtraAudioUnitTargetSettings()
  971. {
  972. xcodeOtherRezFlags = "-d ppc_$ppc -d i386_$i386 -d ppc64_$ppc64 -d x86_64_$x86_64"
  973. " -I /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Versions/A/Headers"
  974. " -I \\\"$(DEVELOPER_DIR)/Extras/CoreAudio/AudioUnits/AUPublic/AUBase\\\"";
  975. xcodeFrameworks.addTokens ("AudioUnit CoreAudioKit", false);
  976. XmlElement plistKey ("key");
  977. plistKey.addTextElement ("AudioComponents");
  978. XmlElement plistEntry ("array");
  979. XmlElement* dict = plistEntry.createNewChildElement ("dict");
  980. const String pluginManufacturerCode = owner.project.getPluginManufacturerCode().toString().trim().substring (0, 4);
  981. const String pluginSubType = owner.project.getPluginCode() .toString().trim().substring (0, 4);
  982. if (pluginManufacturerCode.toLowerCase() == pluginManufacturerCode)
  983. {
  984. throw SaveError ("AudioUnit plugin code identifiers invalid!\n\n"
  985. "You have used only lower case letters in your AU plugin manufacturer identifier. "
  986. "You must have at least one uppercase letter in your AU plugin manufacturer "
  987. "identifier code.");
  988. }
  989. addPlistDictionaryKey (dict, "name", owner.project.getPluginManufacturer().toString()
  990. + ": " + owner.project.getPluginName().toString());
  991. addPlistDictionaryKey (dict, "description", owner.project.getPluginDesc().toString());
  992. addPlistDictionaryKey (dict, "factoryFunction", owner.project.getPluginAUExportPrefix().toString() + "Factory");
  993. addPlistDictionaryKey (dict, "manufacturer", pluginManufacturerCode);
  994. addPlistDictionaryKey (dict, "type", owner.project.getAUMainTypeCode());
  995. addPlistDictionaryKey (dict, "subtype", pluginSubType);
  996. addPlistDictionaryKeyInt (dict, "version", owner.project.getVersionAsHexInteger());
  997. xcodeExtraPListEntries.add (plistKey);
  998. xcodeExtraPListEntries.add (plistEntry);
  999. }
  1000. void addExtraAudioUnitv3PlugInTargetSettings()
  1001. {
  1002. if (owner.isiOS())
  1003. xcodeFrameworks.addTokens ("CoreAudioKit AVFoundation", false);
  1004. else
  1005. xcodeFrameworks.addTokens ("AudioUnit CoreAudioKit AVFoundation", false);
  1006. XmlElement plistKey ("key");
  1007. plistKey.addTextElement ("NSExtension");
  1008. XmlElement plistEntry ("dict");
  1009. addPlistDictionaryKey (&plistEntry, "NSExtensionPrincipalClass", owner.project.getPluginAUExportPrefix().toString() + "FactoryAUv3");
  1010. addPlistDictionaryKey (&plistEntry, "NSExtensionPointIdentifier", "com.apple.AudioUnit-UI");
  1011. plistEntry.createNewChildElement ("key")->addTextElement ("NSExtensionAttributes");
  1012. XmlElement* dict = plistEntry.createNewChildElement ("dict");
  1013. dict->createNewChildElement ("key")->addTextElement ("AudioComponents");
  1014. XmlElement* componentArray = dict->createNewChildElement ("array");
  1015. XmlElement* componentDict = componentArray->createNewChildElement ("dict");
  1016. addPlistDictionaryKey (componentDict, "name", owner.project.getPluginManufacturer().toString()
  1017. + ": " + owner.project.getPluginName().toString());
  1018. addPlistDictionaryKey (componentDict, "description", owner.project.getPluginDesc().toString());
  1019. addPlistDictionaryKey (componentDict, "factoryFunction",owner.project. getPluginAUExportPrefix().toString() + "FactoryAUv3");
  1020. addPlistDictionaryKey (componentDict, "manufacturer", owner.project.getPluginManufacturerCode().toString().trim().substring (0, 4));
  1021. addPlistDictionaryKey (componentDict, "type", owner.project.getAUMainTypeCode());
  1022. addPlistDictionaryKey (componentDict, "subtype", owner.project.getPluginCode().toString().trim().substring (0, 4));
  1023. addPlistDictionaryKeyInt (componentDict, "version", owner.project.getVersionAsHexInteger());
  1024. addPlistDictionaryKeyBool (componentDict, "sandboxSafe", true);
  1025. componentDict->createNewChildElement ("key")->addTextElement ("tags");
  1026. XmlElement* tagsArray = componentDict->createNewChildElement ("array");
  1027. tagsArray->createNewChildElement ("string")
  1028. ->addTextElement (static_cast<bool> (owner.project.getPluginIsSynth().getValue()) ? "Synth" : "Effects");
  1029. xcodeExtraPListEntries.add (plistKey);
  1030. xcodeExtraPListEntries.add (plistEntry);
  1031. }
  1032. void addExtraAAXTargetSettings()
  1033. {
  1034. auto aaxLibsFolder = RelativePath (owner.getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  1035. xcodeExtraLibrariesDebug.add (aaxLibsFolder.getChildFile ("Debug/libAAXLibrary.a"));
  1036. xcodeExtraLibrariesRelease.add (aaxLibsFolder.getChildFile ("Release/libAAXLibrary.a"));
  1037. }
  1038. StringArray getTargetExtraHeaderSearchPaths() const
  1039. {
  1040. StringArray targetExtraSearchPaths;
  1041. if (type == RTASPlugIn)
  1042. {
  1043. RelativePath rtasFolder (owner.getRTASPathValue().toString(), RelativePath::projectFolder);
  1044. targetExtraSearchPaths.add ("$(DEVELOPER_DIR)/Headers/FlatCarbon");
  1045. targetExtraSearchPaths.add ("$(SDKROOT)/Developer/Headers/FlatCarbon");
  1046. static const char* p[] = { "AlturaPorts/TDMPlugIns/PlugInLibrary/Controls",
  1047. "AlturaPorts/TDMPlugIns/PlugInLibrary/CoreClasses",
  1048. "AlturaPorts/TDMPlugIns/PlugInLibrary/DSPClasses",
  1049. "AlturaPorts/TDMPlugIns/PlugInLibrary/EffectClasses",
  1050. "AlturaPorts/TDMPlugIns/PlugInLibrary/MacBuild",
  1051. "AlturaPorts/TDMPlugIns/PlugInLibrary/Meters",
  1052. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses",
  1053. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses/Interfaces",
  1054. "AlturaPorts/TDMPlugIns/PlugInLibrary/RTASP_Adapt",
  1055. "AlturaPorts/TDMPlugIns/PlugInLibrary/Utilities",
  1056. "AlturaPorts/TDMPlugIns/PlugInLibrary/ViewClasses",
  1057. "AlturaPorts/TDMPlugIns/DSPManager/**",
  1058. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/Encryption",
  1059. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/GraphicsExtensions",
  1060. "AlturaPorts/TDMPlugIns/common/**",
  1061. "AlturaPorts/TDMPlugIns/common/PI_LibInterface",
  1062. "AlturaPorts/TDMPlugIns/PACEProtection/**",
  1063. "AlturaPorts/TDMPlugIns/SignalProcessing/**",
  1064. "AlturaPorts/OMS/Headers",
  1065. "AlturaPorts/Fic/Interfaces/**",
  1066. "AlturaPorts/Fic/Source/SignalNets",
  1067. "AlturaPorts/DSIPublicInterface/PublicHeaders",
  1068. "DAEWin/Include",
  1069. "AlturaPorts/DigiPublic/Interfaces",
  1070. "AlturaPorts/DigiPublic",
  1071. "AlturaPorts/NewFileLibs/DOA",
  1072. "AlturaPorts/NewFileLibs/Cmn",
  1073. "xplat/AVX/avx2/avx2sdk/inc",
  1074. "xplat/AVX/avx2/avx2sdk/utils" };
  1075. for (auto* path : p)
  1076. owner.addProjectPathToBuildPathList (targetExtraSearchPaths, rtasFolder.getChildFile (path));
  1077. }
  1078. return targetExtraSearchPaths;
  1079. }
  1080. void addExtraRTASTargetSettings()
  1081. {
  1082. RelativePath rtasFolder (owner.getRTASPathValue().toString(), RelativePath::projectFolder);
  1083. xcodeExtraLibrariesDebug.add (rtasFolder.getChildFile ("MacBag/Libs/Debug/libPluginLibrary.a"));
  1084. xcodeExtraLibrariesRelease.add (rtasFolder.getChildFile ("MacBag/Libs/Release/libPluginLibrary.a"));
  1085. }
  1086. //==============================================================================
  1087. const XCodeProjectExporter& owner;
  1088. Target& operator= (const Target&) JUCE_DELETED_FUNCTION;
  1089. };
  1090. mutable StringArray xcodeFrameworks;
  1091. StringArray xcodeLibs;
  1092. private:
  1093. //==============================================================================
  1094. bool xcodeCanUseDwarf;
  1095. OwnedArray<XCodeTarget> targets;
  1096. mutable OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, pbxGroups, misc, projectConfigs, targetConfigs;
  1097. mutable StringArray resourceIDs, sourceIDs, targetIDs;
  1098. mutable StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  1099. mutable File menuNibFile, iconFile;
  1100. mutable StringArray buildProducts;
  1101. const bool iOS;
  1102. static String sanitisePath (const String& path)
  1103. {
  1104. if (path.startsWithChar ('~'))
  1105. return "$(HOME)" + path.substring (1);
  1106. return path;
  1107. }
  1108. static String addQuotesIfRequired (const String& s)
  1109. {
  1110. return s.containsAnyOf (" $") ? s.quoted() : s;
  1111. }
  1112. File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  1113. //==============================================================================
  1114. void createObjects() const
  1115. {
  1116. prepareTargets();
  1117. addFrameworks();
  1118. addCustomResourceFolders();
  1119. addPlistFileReferences();
  1120. if (iOS && ! projectType.isStaticLibrary())
  1121. addXcassets();
  1122. else
  1123. addNibFiles();
  1124. addIcons();
  1125. addBuildConfigurations();
  1126. addProjectConfigList (projectConfigs, createID ("__projList"));
  1127. {
  1128. StringArray topLevelGroupIDs;
  1129. addFilesAndGroupsToProject (topLevelGroupIDs);
  1130. addBuildPhases();
  1131. addExtraGroupsToProject (topLevelGroupIDs);
  1132. addGroup (createID ("__mainsourcegroup"), "Source", topLevelGroupIDs);
  1133. }
  1134. addProjectObject();
  1135. removeMismatchedXcuserdata();
  1136. }
  1137. void prepareTargets() const
  1138. {
  1139. for (auto* target : targets)
  1140. {
  1141. if (target->type == XCodeTarget::AggregateTarget)
  1142. continue;
  1143. target->addMainBuildProduct();
  1144. String targetName = target->getName();
  1145. String fileID (createID (targetName + String ("__targetbuildref")));
  1146. String fileRefID (createID (String ("__productFileID") + targetName));
  1147. ValueTree* v = new ValueTree (fileID);
  1148. v->setProperty ("isa", "PBXBuildFile", nullptr);
  1149. v->setProperty ("fileRef", fileRefID, nullptr);
  1150. target->mainBuildProductID = fileID;
  1151. pbxBuildFiles.add (v);
  1152. target->addDependency();
  1153. }
  1154. }
  1155. void addPlistFileReferences() const
  1156. {
  1157. for (auto* target : targets)
  1158. {
  1159. if (target->type == XCodeTarget::AggregateTarget)
  1160. continue;
  1161. if (target->shouldCreatePList())
  1162. {
  1163. RelativePath plistPath (target->infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1164. addFileReference (plistPath.toUnixStyle());
  1165. resourceFileRefs.add (createFileRefID (plistPath));
  1166. }
  1167. }
  1168. }
  1169. void addNibFiles() const
  1170. {
  1171. MemoryOutputStream nib;
  1172. nib.write (BinaryData::RecentFilesMenuTemplate_nib, BinaryData::RecentFilesMenuTemplate_nibSize);
  1173. overwriteFileIfDifferentOrThrow (menuNibFile, nib);
  1174. RelativePath menuNibPath (menuNibFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1175. addFileReference (menuNibPath.toUnixStyle());
  1176. resourceIDs.add (addBuildFile (menuNibPath, false, false));
  1177. resourceFileRefs.add (createFileRefID (menuNibPath));
  1178. }
  1179. void addIcons() const
  1180. {
  1181. if (iconFile.exists())
  1182. {
  1183. RelativePath iconPath (iconFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1184. addFileReference (iconPath.toUnixStyle());
  1185. resourceIDs.add (addBuildFile (iconPath, false, false));
  1186. resourceFileRefs.add (createFileRefID (iconPath));
  1187. }
  1188. }
  1189. void addBuildConfigurations() const
  1190. {
  1191. // add build configurations
  1192. for (ConstConfigIterator config (*this); config.next();)
  1193. {
  1194. const XcodeBuildConfiguration& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1195. addProjectConfig (config->getName(), getProjectSettings (xcodeConfig));
  1196. }
  1197. }
  1198. void addFilesAndGroupsToProject (StringArray& topLevelGroupIDs) const
  1199. {
  1200. if (! isiOS() && project.getProjectType().isAudioPlugin())
  1201. topLevelGroupIDs.add (addEntitlementsFile());
  1202. for (auto& group : getAllGroups())
  1203. if (group.getNumChildren() > 0)
  1204. topLevelGroupIDs.add (addProjectItem (group));
  1205. }
  1206. void addExtraGroupsToProject (StringArray& topLevelGroupIDs) const
  1207. {
  1208. { // Add 'resources' group
  1209. String resourcesGroupID (createID ("__resources"));
  1210. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  1211. topLevelGroupIDs.add (resourcesGroupID);
  1212. }
  1213. { // Add 'frameworks' group
  1214. String frameworksGroupID (createID ("__frameworks"));
  1215. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  1216. topLevelGroupIDs.add (frameworksGroupID);
  1217. }
  1218. { // Add 'products' group
  1219. String productsGroupID (createID ("__products"));
  1220. addGroup (productsGroupID, "Products", buildProducts);
  1221. topLevelGroupIDs.add (productsGroupID);
  1222. }
  1223. }
  1224. void addBuildPhases() const
  1225. {
  1226. // add build phases
  1227. for (auto* target : targets)
  1228. {
  1229. if (target->type != XCodeTarget::AggregateTarget)
  1230. buildProducts.add (createID (String ("__productFileID") + String (target->getName())));
  1231. for (ConstConfigIterator config (*this); config.next();)
  1232. {
  1233. const XcodeBuildConfiguration& xcodeConfig = dynamic_cast<const XcodeBuildConfiguration&> (*config);
  1234. target->addTargetConfig (config->getName(), target->getTargetSettings (xcodeConfig));
  1235. }
  1236. addConfigList (*target, targetConfigs, createID (String ("__configList") + target->getName()));
  1237. target->addShellScriptBuildPhase ("Pre-build script", getPreBuildScript());
  1238. if (target->type != XCodeTarget::AggregateTarget)
  1239. {
  1240. // TODO: ideally resources wouldn't be copied into the AUv3 bundle as well.
  1241. // However, fixing this requires supporting App groups -> TODO: add app groups
  1242. if (! projectType.isStaticLibrary() && target->type != XCodeTarget::SharedCodeTarget)
  1243. target->addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  1244. StringArray rezFiles (rezFileIDs);
  1245. rezFiles.addArray (target->rezFileIDs);
  1246. if (rezFiles.size() > 0)
  1247. target->addBuildPhase ("PBXRezBuildPhase", rezFiles);
  1248. StringArray sourceFiles (target->sourceIDs);
  1249. if (target->type == XCodeTarget::SharedCodeTarget
  1250. || (! project.getProjectType().isAudioPlugin()))
  1251. sourceFiles.addArray (sourceIDs);
  1252. target->addBuildPhase ("PBXSourcesBuildPhase", sourceFiles);
  1253. if (! projectType.isStaticLibrary() && target->type != XCodeTarget::SharedCodeTarget)
  1254. target->addBuildPhase ("PBXFrameworksBuildPhase", target->frameworkIDs);
  1255. }
  1256. target->addShellScriptBuildPhase ("Post-build script", getPostBuildScript());
  1257. if (project.getProjectType().isAudioPlugin() && project.shouldBuildAUv3()
  1258. && project.shouldBuildStandalonePlugin() && target->type == XCodeTarget::StandalonePlugIn)
  1259. embedAppExtension();
  1260. addTargetObject (*target);
  1261. }
  1262. }
  1263. void embedAppExtension() const
  1264. {
  1265. if (auto* standaloneTarget = getTargetOfType (XCodeTarget::StandalonePlugIn))
  1266. {
  1267. if (auto* auv3Target = getTargetOfType (XCodeTarget::AudioUnitv3PlugIn))
  1268. {
  1269. StringArray files;
  1270. files.add (auv3Target->mainBuildProductID);
  1271. standaloneTarget->addCopyFilesPhase ("Embed App Extensions", files, kPluginsFolder);
  1272. }
  1273. }
  1274. }
  1275. static Image fixMacIconImageSize (Drawable& image)
  1276. {
  1277. const int validSizes[] = { 16, 32, 48, 128, 256, 512, 1024 };
  1278. const int w = image.getWidth();
  1279. const int h = image.getHeight();
  1280. int bestSize = 16;
  1281. for (int size : validSizes)
  1282. {
  1283. if (w == h && w == size)
  1284. {
  1285. bestSize = w;
  1286. break;
  1287. }
  1288. if (jmax (w, h) > size)
  1289. bestSize = size;
  1290. }
  1291. return rescaleImageForIcon (image, bestSize);
  1292. }
  1293. //==============================================================================
  1294. XCodeTarget* getTargetOfType (ProjectType::Target::Type type) const
  1295. {
  1296. for (auto& target : targets)
  1297. if (target->type == type)
  1298. return target;
  1299. return nullptr;
  1300. }
  1301. void addTargetObject (XCodeTarget& target) const
  1302. {
  1303. String targetName = target.getName();
  1304. String targetID = target.getID();
  1305. ValueTree* const v = new ValueTree (targetID);
  1306. v->setProperty ("isa", target.type == XCodeTarget::AggregateTarget ? "PBXAggregateTarget" : "PBXNativeTarget", nullptr);
  1307. v->setProperty ("buildConfigurationList", createID (String ("__configList") + targetName), nullptr);
  1308. v->setProperty ("buildPhases", indentParenthesisedList (target.buildPhaseIDs), nullptr);
  1309. v->setProperty ("buildRules", "( )", nullptr);
  1310. v->setProperty ("dependencies", indentParenthesisedList (getTargetDependencies (target)), nullptr);
  1311. v->setProperty (Ids::name, target.getXCodeSchemeName(), nullptr);
  1312. v->setProperty ("productName", projectName, nullptr);
  1313. if (target.type != XCodeTarget::AggregateTarget)
  1314. {
  1315. v->setProperty ("productReference", createID (String ("__productFileID") + targetName), nullptr);
  1316. jassert (target.xcodeProductType.isNotEmpty());
  1317. v->setProperty ("productType", target.xcodeProductType, nullptr);
  1318. }
  1319. targetIDs.add (targetID);
  1320. misc.add (v);
  1321. }
  1322. StringArray getTargetDependencies (const XCodeTarget& target) const
  1323. {
  1324. StringArray dependencies;
  1325. if (project.getProjectType().isAudioPlugin())
  1326. {
  1327. if (target.type == XCodeTarget::StandalonePlugIn) // depends on AUv3 and shared code
  1328. {
  1329. if (XCodeTarget* auv3Target = getTargetOfType (XCodeTarget::AudioUnitv3PlugIn))
  1330. dependencies.add (auv3Target->getDependencyID());
  1331. if (XCodeTarget* sharedCodeTarget = getTargetOfType (XCodeTarget::SharedCodeTarget))
  1332. dependencies.add (sharedCodeTarget->getDependencyID());
  1333. }
  1334. else if (target.type == XCodeTarget::AggregateTarget) // depends on all other targets
  1335. {
  1336. for (int i = 1; i < targets.size(); ++i)
  1337. dependencies.add (targets[i]->getDependencyID());
  1338. }
  1339. else if (target.type != XCodeTarget::SharedCodeTarget) // shared code doesn't depend on anything; all other targets depend only on the shared code
  1340. {
  1341. if (XCodeTarget* sharedCodeTarget = getTargetOfType (XCodeTarget::SharedCodeTarget))
  1342. dependencies.add (sharedCodeTarget->getDependencyID());
  1343. }
  1344. }
  1345. return dependencies;
  1346. }
  1347. static void writeOldIconFormat (MemoryOutputStream& out, const Image& image, const char* type, const char* maskType)
  1348. {
  1349. const int w = image.getWidth();
  1350. const int h = image.getHeight();
  1351. out.write (type, 4);
  1352. out.writeIntBigEndian (8 + 4 * w * h);
  1353. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  1354. for (int y = 0; y < h; ++y)
  1355. {
  1356. for (int x = 0; x < w; ++x)
  1357. {
  1358. const Colour pixel (bitmap.getPixelColour (x, y));
  1359. out.writeByte ((char) pixel.getAlpha());
  1360. out.writeByte ((char) pixel.getRed());
  1361. out.writeByte ((char) pixel.getGreen());
  1362. out.writeByte ((char) pixel.getBlue());
  1363. }
  1364. }
  1365. out.write (maskType, 4);
  1366. out.writeIntBigEndian (8 + w * h);
  1367. for (int y = 0; y < h; ++y)
  1368. {
  1369. for (int x = 0; x < w; ++x)
  1370. {
  1371. const Colour pixel (bitmap.getPixelColour (x, y));
  1372. out.writeByte ((char) pixel.getAlpha());
  1373. }
  1374. }
  1375. }
  1376. static void writeNewIconFormat (MemoryOutputStream& out, const Image& image, const char* type)
  1377. {
  1378. MemoryOutputStream pngData;
  1379. PNGImageFormat pngFormat;
  1380. pngFormat.writeImageToStream (image, pngData);
  1381. out.write (type, 4);
  1382. out.writeIntBigEndian (8 + (int) pngData.getDataSize());
  1383. out << pngData;
  1384. }
  1385. void writeIcnsFile (const OwnedArray<Drawable>& images, OutputStream& out) const
  1386. {
  1387. MemoryOutputStream data;
  1388. int smallest = 0x7fffffff;
  1389. Drawable* smallestImage = nullptr;
  1390. for (int i = 0; i < images.size(); ++i)
  1391. {
  1392. const Image image (fixMacIconImageSize (*images.getUnchecked(i)));
  1393. jassert (image.getWidth() == image.getHeight());
  1394. if (image.getWidth() < smallest)
  1395. {
  1396. smallest = image.getWidth();
  1397. smallestImage = images.getUnchecked(i);
  1398. }
  1399. switch (image.getWidth())
  1400. {
  1401. case 16: writeOldIconFormat (data, image, "is32", "s8mk"); break;
  1402. case 32: writeOldIconFormat (data, image, "il32", "l8mk"); break;
  1403. case 48: writeOldIconFormat (data, image, "ih32", "h8mk"); break;
  1404. case 128: writeOldIconFormat (data, image, "it32", "t8mk"); break;
  1405. case 256: writeNewIconFormat (data, image, "ic08"); break;
  1406. case 512: writeNewIconFormat (data, image, "ic09"); break;
  1407. case 1024: writeNewIconFormat (data, image, "ic10"); break;
  1408. default: break;
  1409. }
  1410. }
  1411. jassert (data.getDataSize() > 0); // no suitable sized images?
  1412. // If you only supply a 1024 image, the file doesn't work on 10.8, so we need
  1413. // to force a smaller one in there too..
  1414. if (smallest > 512 && smallestImage != nullptr)
  1415. writeNewIconFormat (data, rescaleImageForIcon (*smallestImage, 512), "ic09");
  1416. out.write ("icns", 4);
  1417. out.writeIntBigEndian ((int) data.getDataSize() + 8);
  1418. out << data;
  1419. }
  1420. void getIconImages (OwnedArray<Drawable>& images) const
  1421. {
  1422. ScopedPointer<Drawable> bigIcon (getBigIcon());
  1423. if (bigIcon != nullptr)
  1424. images.add (bigIcon.release());
  1425. ScopedPointer<Drawable> smallIcon (getSmallIcon());
  1426. if (smallIcon != nullptr)
  1427. images.add (smallIcon.release());
  1428. }
  1429. void createiOSIconFiles (File appIconSet) const
  1430. {
  1431. OwnedArray<Drawable> images;
  1432. getIconImages (images);
  1433. if (images.size() > 0)
  1434. {
  1435. for (auto& type : getiOSAppIconTypes())
  1436. {
  1437. auto image = rescaleImageForIcon (*images.getFirst(), type.size);
  1438. MemoryOutputStream pngData;
  1439. PNGImageFormat pngFormat;
  1440. pngFormat.writeImageToStream (image, pngData);
  1441. overwriteFileIfDifferentOrThrow (appIconSet.getChildFile (type.filename), pngData);
  1442. }
  1443. }
  1444. }
  1445. void createIconFile() const
  1446. {
  1447. OwnedArray<Drawable> images;
  1448. getIconImages (images);
  1449. if (images.size() > 0)
  1450. {
  1451. MemoryOutputStream mo;
  1452. writeIcnsFile (images, mo);
  1453. iconFile = getTargetFolder().getChildFile ("Icon.icns");
  1454. overwriteFileIfDifferentOrThrow (iconFile, mo);
  1455. }
  1456. }
  1457. void writeInfoPlistFiles() const
  1458. {
  1459. for (auto& target : targets)
  1460. target->writeInfoPlistFile();
  1461. }
  1462. // Delete .rsrc files in folder but don't follow sym-links
  1463. void deleteRsrcFiles (const File& folder) const
  1464. {
  1465. for (DirectoryIterator di (folder, false, "*", File::findFilesAndDirectories); di.next();)
  1466. {
  1467. const File& entry = di.getFile();
  1468. if (! entry.isSymbolicLink())
  1469. {
  1470. if (entry.existsAsFile() && entry.getFileExtension().toLowerCase() == ".rsrc")
  1471. entry.deleteFile();
  1472. else if (entry.isDirectory())
  1473. deleteRsrcFiles (entry);
  1474. }
  1475. }
  1476. }
  1477. static String getLinkerFlagForLib (String library)
  1478. {
  1479. if (library.substring (0, 3) == "lib")
  1480. library = library.substring (3);
  1481. return "-l" + library.replace (" ", "\\\\ ").upToLastOccurrenceOf (".", false, false);
  1482. }
  1483. String getSearchPathForStaticLibrary (const RelativePath& library) const
  1484. {
  1485. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  1486. if (! library.isAbsolute())
  1487. {
  1488. String srcRoot (rebaseFromProjectFolderToBuildTarget (RelativePath (".", RelativePath::projectFolder)).toUnixStyle());
  1489. if (srcRoot.endsWith ("/.")) srcRoot = srcRoot.dropLastCharacters (2);
  1490. if (! srcRoot.endsWithChar ('/')) srcRoot << '/';
  1491. searchPath = srcRoot + searchPath;
  1492. }
  1493. return sanitisePath (searchPath);
  1494. }
  1495. StringArray getProjectSettings (const XcodeBuildConfiguration& config) const
  1496. {
  1497. StringArray s;
  1498. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  1499. s.add ("GCC_C_LANGUAGE_STANDARD = c11");
  1500. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  1501. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  1502. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  1503. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  1504. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  1505. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  1506. s.add ("WARNING_CFLAGS = -Wreorder");
  1507. s.add ("GCC_MODEL_TUNING = G5");
  1508. if (projectType.isStaticLibrary())
  1509. {
  1510. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = NO");
  1511. s.add ("GCC_SYMBOLS_PRIVATE_EXTERN = NO");
  1512. }
  1513. else
  1514. {
  1515. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  1516. }
  1517. if (config.isDebug())
  1518. {
  1519. s.add ("ENABLE_TESTABILITY = YES");
  1520. if (config.osxArchitecture.get() == osxArch_Default || config.osxArchitecture.get().isEmpty())
  1521. s.add ("ONLY_ACTIVE_ARCH = YES");
  1522. }
  1523. if (iOS)
  1524. {
  1525. s.add ("\"CODE_SIGN_IDENTITY[sdk=iphoneos*]\" = " + config.codeSignIdentity.get().quoted());
  1526. s.add ("SDKROOT = iphoneos");
  1527. s.add ("TARGETED_DEVICE_FAMILY = \"1,2\"");
  1528. const String iosVersion (config.iosDeploymentTarget.get());
  1529. if (iosVersion.isNotEmpty() && iosVersion != osxVersionDefault)
  1530. s.add ("IPHONEOS_DEPLOYMENT_TARGET = " + iosVersion);
  1531. else
  1532. s.add ("IPHONEOS_DEPLOYMENT_TARGET = 9.3");
  1533. }
  1534. else
  1535. {
  1536. if (! config.codeSignIdentity.isUsingDefault() || getIosDevelopmentTeamIDString().isNotEmpty())
  1537. s.add ("\"CODE_SIGN_IDENTITY\" = " + config.codeSignIdentity.get().quoted());
  1538. }
  1539. s.add ("ZERO_LINK = NO");
  1540. if (xcodeCanUseDwarf)
  1541. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf\"");
  1542. s.add ("PRODUCT_NAME = \"" + replacePreprocessorTokens (config, config.getTargetBinaryNameString()) + "\"");
  1543. return s;
  1544. }
  1545. void addFrameworks() const
  1546. {
  1547. if (! projectType.isStaticLibrary())
  1548. {
  1549. if (iOS && isInAppPurchasesEnabled())
  1550. xcodeFrameworks.addIfNotAlreadyThere ("StoreKit");
  1551. xcodeFrameworks.addTokens (getExtraFrameworksString(), ",;", "\"'");
  1552. xcodeFrameworks.trim();
  1553. StringArray s (xcodeFrameworks);
  1554. for (auto& target : targets)
  1555. s.addArray (target->xcodeFrameworks);
  1556. if (project.getConfigFlag ("JUCE_QUICKTIME") == Project::configFlagDisabled)
  1557. s.removeString ("QuickTime");
  1558. s.trim();
  1559. s.removeDuplicates (true);
  1560. s.sort (true);
  1561. for (auto& framework : s)
  1562. {
  1563. String frameworkID = addFramework (framework);
  1564. // find all the targets that are referring to this object
  1565. for (auto& target : targets)
  1566. if (xcodeFrameworks.contains (framework) || target->xcodeFrameworks.contains (framework))
  1567. target->frameworkIDs.add (frameworkID);
  1568. }
  1569. }
  1570. }
  1571. void addCustomResourceFolders() const
  1572. {
  1573. StringArray folders;
  1574. folders.addTokens (getCustomResourceFoldersString(), ":", "");
  1575. folders.trim();
  1576. for (auto& crf : folders)
  1577. addCustomResourceFolder (crf);
  1578. }
  1579. void addXcassets() const
  1580. {
  1581. String customXcassetsPath = getCustomXcassetsFolderString();
  1582. if (customXcassetsPath.isEmpty())
  1583. createXcassetsFolderFromIcons();
  1584. else
  1585. addCustomResourceFolder (customXcassetsPath, "folder.assetcatalog");
  1586. }
  1587. void addCustomResourceFolder (String folderPathRelativeToProjectFolder, const String fileType = "folder") const
  1588. {
  1589. String folderPath = RelativePath (folderPathRelativeToProjectFolder, RelativePath::projectFolder)
  1590. .rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  1591. .toUnixStyle();
  1592. const String fileRefID (createFileRefID (folderPath));
  1593. addFileOrFolderReference (folderPath, "<group>", fileType);
  1594. resourceIDs.add (addBuildFile (folderPath, fileRefID, false, false));
  1595. resourceFileRefs.add (createFileRefID (folderPath));
  1596. }
  1597. //==============================================================================
  1598. void writeProjectFile (OutputStream& output) const
  1599. {
  1600. output << "// !$*UTF8*$!\n{\n"
  1601. "\tarchiveVersion = 1;\n"
  1602. "\tclasses = {\n\t};\n"
  1603. "\tobjectVersion = 46;\n"
  1604. "\tobjects = {\n\n";
  1605. Array<ValueTree*> objects;
  1606. objects.addArray (pbxBuildFiles);
  1607. objects.addArray (pbxFileReferences);
  1608. objects.addArray (pbxGroups);
  1609. objects.addArray (targetConfigs);
  1610. objects.addArray (projectConfigs);
  1611. objects.addArray (misc);
  1612. for (auto* o : objects)
  1613. {
  1614. output << "\t\t" << o->getType().toString() << " = {";
  1615. for (int j = 0; j < o->getNumProperties(); ++j)
  1616. {
  1617. const Identifier propertyName (o->getPropertyName(j));
  1618. String val (o->getProperty (propertyName).toString());
  1619. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,&+-_@~\r\n\\#%^`*")
  1620. && ! (val.trimStart().startsWithChar ('(')
  1621. || val.trimStart().startsWithChar ('{'))))
  1622. val = "\"" + val + "\"";
  1623. output << propertyName.toString() << " = " << val << "; ";
  1624. }
  1625. output << "};\n";
  1626. }
  1627. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  1628. }
  1629. String addBuildFile (const String& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings, XCodeTarget* xcodeTarget = nullptr) const
  1630. {
  1631. String fileID (createID (path + "buildref"));
  1632. if (addToSourceBuildPhase)
  1633. {
  1634. if (xcodeTarget != nullptr) xcodeTarget->sourceIDs.add (fileID);
  1635. else sourceIDs.add (fileID);
  1636. }
  1637. ValueTree* v = new ValueTree (fileID);
  1638. v->setProperty ("isa", "PBXBuildFile", nullptr);
  1639. v->setProperty ("fileRef", fileRefID, nullptr);
  1640. if (inhibitWarnings)
  1641. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", nullptr);
  1642. pbxBuildFiles.add (v);
  1643. return fileID;
  1644. }
  1645. String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings, XCodeTarget* xcodeTarget = nullptr) const
  1646. {
  1647. return addBuildFile (path.toUnixStyle(), createFileRefID (path), addToSourceBuildPhase, inhibitWarnings, xcodeTarget);
  1648. }
  1649. String addFileReference (String pathString) const
  1650. {
  1651. String sourceTree ("SOURCE_ROOT");
  1652. RelativePath path (pathString, RelativePath::unknown);
  1653. if (pathString.startsWith ("${"))
  1654. {
  1655. sourceTree = pathString.substring (2).upToFirstOccurrenceOf ("}", false, false);
  1656. pathString = pathString.fromFirstOccurrenceOf ("}/", false, false);
  1657. }
  1658. else if (path.isAbsolute())
  1659. {
  1660. sourceTree = "<absolute>";
  1661. }
  1662. String fileType = getFileType (path);
  1663. return addFileOrFolderReference (pathString, sourceTree, fileType);
  1664. }
  1665. String addFileOrFolderReference (String pathString, String sourceTree, String fileType) const
  1666. {
  1667. const String fileRefID (createFileRefID (pathString));
  1668. ScopedPointer<ValueTree> v (new ValueTree (fileRefID));
  1669. v->setProperty ("isa", "PBXFileReference", nullptr);
  1670. v->setProperty ("lastKnownFileType", fileType, nullptr);
  1671. v->setProperty (Ids::name, pathString.fromLastOccurrenceOf ("/", false, false), nullptr);
  1672. v->setProperty ("path", sanitisePath (pathString), nullptr);
  1673. v->setProperty ("sourceTree", sourceTree, nullptr);
  1674. const int existing = pbxFileReferences.indexOfSorted (*this, v);
  1675. if (existing >= 0)
  1676. {
  1677. // If this fails, there's either a string hash collision, or the same file is being added twice (incorrectly)
  1678. jassert (pbxFileReferences.getUnchecked (existing)->isEquivalentTo (*v));
  1679. }
  1680. else
  1681. {
  1682. pbxFileReferences.addSorted (*this, v.release());
  1683. }
  1684. return fileRefID;
  1685. }
  1686. public:
  1687. static int compareElements (const ValueTree* first, const ValueTree* second)
  1688. {
  1689. return first->getType().getCharPointer().compare (second->getType().getCharPointer());
  1690. }
  1691. private:
  1692. static String getFileType (const RelativePath& file)
  1693. {
  1694. if (file.hasFileExtension (cppFileExtensions)) return "sourcecode.cpp.cpp";
  1695. if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  1696. if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  1697. if (file.hasFileExtension (".c")) return "sourcecode.c.c";
  1698. if (file.hasFileExtension (headerFileExtensions)) return "sourcecode.c.h";
  1699. if (file.hasFileExtension (asmFileExtensions)) return "sourcecode.c.asm";
  1700. if (file.hasFileExtension (".framework")) return "wrapper.framework";
  1701. if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  1702. if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  1703. if (file.hasFileExtension ("html;htm")) return "text.html";
  1704. if (file.hasFileExtension ("xml;zip;wav")) return "file" + file.getFileExtension();
  1705. if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  1706. if (file.hasFileExtension ("plist")) return "text.plist.xml";
  1707. if (file.hasFileExtension ("entitlements")) return "text.plist.xml";
  1708. if (file.hasFileExtension ("app")) return "wrapper.application";
  1709. if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  1710. if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  1711. if (file.hasFileExtension ("a")) return "archive.ar";
  1712. if (file.hasFileExtension ("xcassets")) return "folder.assetcatalog";
  1713. return "file" + file.getFileExtension();
  1714. }
  1715. String addFile (const RelativePath& path, bool shouldBeCompiled, bool shouldBeAddedToBinaryResources,
  1716. bool shouldBeAddedToXcodeResources, bool inhibitWarnings, XCodeTarget* xcodeTarget) const
  1717. {
  1718. const String pathAsString (path.toUnixStyle());
  1719. const String refID (addFileReference (path.toUnixStyle()));
  1720. if (shouldBeCompiled)
  1721. {
  1722. addBuildFile (pathAsString, refID, true, inhibitWarnings, xcodeTarget);
  1723. }
  1724. else if (! shouldBeAddedToBinaryResources || shouldBeAddedToXcodeResources)
  1725. {
  1726. const String fileType (getFileType (path));
  1727. if (shouldBeAddedToXcodeResources)
  1728. {
  1729. resourceIDs.add (addBuildFile (pathAsString, refID, false, false));
  1730. resourceFileRefs.add (refID);
  1731. }
  1732. }
  1733. return refID;
  1734. }
  1735. String addRezFile (const Project::Item& projectItem, const RelativePath& path) const
  1736. {
  1737. const String pathAsString (path.toUnixStyle());
  1738. const String refID (addFileReference (path.toUnixStyle()));
  1739. if (projectItem.isModuleCode())
  1740. {
  1741. if (XCodeTarget* xcodeTarget = getTargetOfType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), false)))
  1742. {
  1743. String rezFileID = addBuildFile (pathAsString, refID, false, false, xcodeTarget);
  1744. xcodeTarget->rezFileIDs.add (rezFileID);
  1745. return refID;
  1746. }
  1747. }
  1748. return String();
  1749. }
  1750. String getEntitlementsFileName() const
  1751. {
  1752. return project.getProjectFilenameRoot() + String (".entitlements");
  1753. }
  1754. String addEntitlementsFile() const
  1755. {
  1756. const char* sandboxEntitlement =
  1757. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  1758. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
  1759. "<plist version=\"1.0\">"
  1760. "<dict>"
  1761. " <key>com.apple.security.app-sandbox</key>"
  1762. " <true/>"
  1763. "</dict>"
  1764. "</plist>";
  1765. File entitlementsFile = getTargetFolder().getChildFile (getEntitlementsFileName());
  1766. overwriteFileIfDifferentOrThrow (entitlementsFile, sandboxEntitlement);
  1767. RelativePath plistPath (entitlementsFile, getTargetFolder(), RelativePath::buildTargetFolder);
  1768. return addFile (plistPath, false, false, false, false, nullptr);
  1769. }
  1770. String addProjectItem (const Project::Item& projectItem) const
  1771. {
  1772. if (projectItem.getParent() == *modulesGroup)
  1773. return addFileReference (rebaseFromProjectFolderToBuildTarget (getModuleFolderRelativeToProject (projectItem.getName())).toUnixStyle());
  1774. if (projectItem.isGroup())
  1775. {
  1776. StringArray childIDs;
  1777. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1778. {
  1779. const String childID (addProjectItem (projectItem.getChild(i)));
  1780. if (childID.isNotEmpty())
  1781. childIDs.add (childID);
  1782. }
  1783. return addGroup (projectItem, childIDs);
  1784. }
  1785. if (projectItem.shouldBeAddedToTargetProject())
  1786. {
  1787. const String itemPath (projectItem.getFilePath());
  1788. RelativePath path;
  1789. if (itemPath.startsWith ("${"))
  1790. path = RelativePath (itemPath, RelativePath::unknown);
  1791. else
  1792. path = RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1793. if (path.hasFileExtension (".r"))
  1794. return addRezFile (projectItem, path);
  1795. XCodeTarget* xcodeTarget = nullptr;
  1796. if (projectItem.isModuleCode() && projectItem.shouldBeCompiled())
  1797. xcodeTarget = getTargetOfType (project.getTargetTypeFromFilePath (projectItem.getFile(), false));
  1798. return addFile (path, projectItem.shouldBeCompiled(),
  1799. projectItem.shouldBeAddedToBinaryResources(),
  1800. projectItem.shouldBeAddedToXcodeResources(),
  1801. projectItem.shouldInhibitWarnings(),
  1802. xcodeTarget);
  1803. }
  1804. return String();
  1805. }
  1806. String addFramework (const String& frameworkName) const
  1807. {
  1808. String path (frameworkName);
  1809. if (! File::isAbsolutePath (path))
  1810. path = "System/Library/Frameworks/" + path;
  1811. if (! path.endsWithIgnoreCase (".framework"))
  1812. path << ".framework";
  1813. const String fileRefID (createFileRefID (path));
  1814. addFileReference ((File::isAbsolutePath (frameworkName) ? "" : "${SDKROOT}/") + path);
  1815. frameworkFileIDs.add (fileRefID);
  1816. return addBuildFile (path, fileRefID, false, false);
  1817. }
  1818. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs) const
  1819. {
  1820. ValueTree* v = new ValueTree (groupID);
  1821. v->setProperty ("isa", "PBXGroup", nullptr);
  1822. v->setProperty ("children", indentParenthesisedList (childIDs), nullptr);
  1823. v->setProperty (Ids::name, groupName, nullptr);
  1824. v->setProperty ("sourceTree", "<group>", nullptr);
  1825. pbxGroups.add (v);
  1826. }
  1827. String addGroup (const Project::Item& item, StringArray& childIDs) const
  1828. {
  1829. const String groupName (item.getName());
  1830. const String groupID (getIDForGroup (item));
  1831. addGroup (groupID, groupName, childIDs);
  1832. return groupID;
  1833. }
  1834. void addProjectConfig (const String& configName, const StringArray& buildSettings) const
  1835. {
  1836. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  1837. v->setProperty ("isa", "XCBuildConfiguration", nullptr);
  1838. v->setProperty ("buildSettings", indentBracedList (buildSettings), nullptr);
  1839. v->setProperty (Ids::name, configName, nullptr);
  1840. projectConfigs.add (v);
  1841. }
  1842. void addConfigList (XCodeTarget& target, const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  1843. {
  1844. ValueTree* v = new ValueTree (listID);
  1845. v->setProperty ("isa", "XCConfigurationList", nullptr);
  1846. v->setProperty ("buildConfigurations", indentParenthesisedList (target.configIDs), nullptr);
  1847. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  1848. if (auto* first = configsToUse.getFirst())
  1849. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  1850. misc.add (v);
  1851. }
  1852. void addProjectConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID) const
  1853. {
  1854. StringArray configIDs;
  1855. for (auto* c : configsToUse)
  1856. configIDs.add (c->getType().toString());
  1857. ValueTree* v = new ValueTree (listID);
  1858. v->setProperty ("isa", "XCConfigurationList", nullptr);
  1859. v->setProperty ("buildConfigurations", indentParenthesisedList (configIDs), nullptr);
  1860. v->setProperty ("defaultConfigurationIsVisible", (int) 0, nullptr);
  1861. if (auto* first = configsToUse.getFirst())
  1862. v->setProperty ("defaultConfigurationName", first->getProperty (Ids::name), nullptr);
  1863. misc.add (v);
  1864. }
  1865. void addProjectObject() const
  1866. {
  1867. ValueTree* const v = new ValueTree (createID ("__root"));
  1868. v->setProperty ("isa", "PBXProject", nullptr);
  1869. v->setProperty ("buildConfigurationList", createID ("__projList"), nullptr);
  1870. v->setProperty ("attributes", getProjectObjectAttributes(), nullptr);
  1871. v->setProperty ("compatibilityVersion", "Xcode 3.2", nullptr);
  1872. v->setProperty ("hasScannedForEncodings", (int) 0, nullptr);
  1873. v->setProperty ("mainGroup", createID ("__mainsourcegroup"), nullptr);
  1874. v->setProperty ("projectDirPath", "\"\"", nullptr);
  1875. v->setProperty ("projectRoot", "\"\"", nullptr);
  1876. String targetString = "(" + targetIDs.joinIntoString (", ") + ")";
  1877. v->setProperty ("targets", targetString, nullptr);
  1878. misc.add (v);
  1879. }
  1880. //==============================================================================
  1881. void removeMismatchedXcuserdata() const
  1882. {
  1883. if (settings ["keepCustomXcodeSchemes"])
  1884. return;
  1885. File xcuserdata = getProjectBundle().getChildFile ("xcuserdata");
  1886. if (! xcuserdata.exists())
  1887. return;
  1888. if (! xcuserdataMatchesTargets (xcuserdata))
  1889. {
  1890. xcuserdata.deleteRecursively();
  1891. getProjectBundle().getChildFile ("project.xcworkspace").deleteRecursively();
  1892. }
  1893. }
  1894. bool xcuserdataMatchesTargets (const File& xcuserdata) const
  1895. {
  1896. Array<File> xcschemeManagementPlists;
  1897. xcuserdata.findChildFiles (xcschemeManagementPlists, File::findFiles, true, "xcschememanagement.plist");
  1898. for (auto& plist : xcschemeManagementPlists)
  1899. if (! xcschemeManagementPlistMatchesTargets (plist))
  1900. return false;
  1901. return true;
  1902. }
  1903. static StringArray parseNamesOfTargetsFromPlist (const XmlElement& dictXML)
  1904. {
  1905. forEachXmlChildElementWithTagName (dictXML, schemesKey, "key")
  1906. {
  1907. if (schemesKey->getAllSubText().trim().equalsIgnoreCase ("SchemeUserState"))
  1908. {
  1909. if (auto* dict = schemesKey->getNextElement())
  1910. {
  1911. if (dict->hasTagName ("dict"))
  1912. {
  1913. StringArray names;
  1914. forEachXmlChildElementWithTagName (*dict, key, "key")
  1915. names.add (key->getAllSubText().upToLastOccurrenceOf (".xcscheme", false, false).trim());
  1916. names.sort (false);
  1917. return names;
  1918. }
  1919. }
  1920. }
  1921. }
  1922. return StringArray();
  1923. }
  1924. StringArray getNamesOfTargets() const
  1925. {
  1926. StringArray names;
  1927. for (auto& target : targets)
  1928. names.add (target->getXCodeSchemeName());
  1929. names.sort (false);
  1930. return names;
  1931. }
  1932. bool xcschemeManagementPlistMatchesTargets (const File& plist) const
  1933. {
  1934. ScopedPointer<XmlElement> xml (XmlDocument::parse (plist));
  1935. if (xml != nullptr)
  1936. if (auto* dict = xml->getChildByName ("dict"))
  1937. return parseNamesOfTargetsFromPlist (*dict) == getNamesOfTargets();
  1938. return false;
  1939. }
  1940. //==============================================================================
  1941. struct AppIconType
  1942. {
  1943. const char* idiom;
  1944. const char* sizeString;
  1945. const char* filename;
  1946. const char* scale;
  1947. int size;
  1948. };
  1949. static Array<AppIconType> getiOSAppIconTypes()
  1950. {
  1951. AppIconType types[] =
  1952. {
  1953. { "iphone", "29x29", "Icon-29.png", "1x", 29 },
  1954. { "iphone", "29x29", "Icon-29@2x.png", "2x", 58 },
  1955. { "iphone", "29x29", "Icon-29@3x.png", "3x", 87 },
  1956. { "iphone", "40x40", "Icon-Spotlight-40@2x.png", "2x", 80 },
  1957. { "iphone", "40x40", "Icon-Spotlight-40@3x.png", "3x", 120 },
  1958. { "iphone", "57x57", "Icon.png", "1x", 57 },
  1959. { "iphone", "57x57", "Icon@2x.png", "2x", 114 },
  1960. { "iphone", "60x60", "Icon-60@2x.png", "2x", 120 },
  1961. { "iphone", "60x60", "Icon-@3x.png", "3x", 180 },
  1962. { "ipad", "29x29", "Icon-Small-1.png", "1x", 29 },
  1963. { "ipad", "29x29", "Icon-Small@2x-1.png", "2x", 58 },
  1964. { "ipad", "40x40", "Icon-Spotlight-40.png", "1x", 40 },
  1965. { "ipad", "40x40", "Icon-Spotlight-40@2x-1.png", "2x", 80 },
  1966. { "ipad", "50x50", "Icon-Small-50.png", "1x", 50 },
  1967. { "ipad", "50x50", "Icon-Small-50@2x.png", "2x", 100 },
  1968. { "ipad", "72x72", "Icon-72.png", "1x", 72 },
  1969. { "ipad", "72x72", "Icon-72@2x.png", "2x", 144 },
  1970. { "ipad", "76x76", "Icon-76.png", "1x", 76 },
  1971. { "ipad", "76x76", "Icon-76@2x.png", "2x", 152 },
  1972. { "ipad", "83.5x83.5", "Icon-83.5@2x.png", "2x", 167 }
  1973. };
  1974. return Array<AppIconType> (types, numElementsInArray (types));
  1975. }
  1976. static String getiOSAppIconContents()
  1977. {
  1978. var images;
  1979. for (auto& type : getiOSAppIconTypes())
  1980. {
  1981. DynamicObject::Ptr d = new DynamicObject();
  1982. d->setProperty ("idiom", type.idiom);
  1983. d->setProperty ("size", type.sizeString);
  1984. d->setProperty ("filename", type.filename);
  1985. d->setProperty ("scale", type.scale);
  1986. images.append (var (d.get()));
  1987. }
  1988. return getiOSAssetContents (images);
  1989. }
  1990. String getProjectObjectAttributes() const
  1991. {
  1992. String attributes;
  1993. attributes << "{ LastUpgradeCheck = 0820; ";
  1994. if (projectType.isGUIApplication() || projectType.isAudioPlugin())
  1995. {
  1996. attributes << "TargetAttributes = { ";
  1997. for (auto& target : targets)
  1998. attributes << target->getTargetAttributes();
  1999. attributes << " }; ";
  2000. }
  2001. attributes << "}";
  2002. return attributes;
  2003. }
  2004. //==============================================================================
  2005. struct ImageType
  2006. {
  2007. const char* orientation;
  2008. const char* idiom;
  2009. const char* subtype;
  2010. const char* extent;
  2011. const char* scale;
  2012. const char* filename;
  2013. int width;
  2014. int height;
  2015. };
  2016. static Array<ImageType> getiOSLaunchImageTypes()
  2017. {
  2018. ImageType types[] =
  2019. {
  2020. { "portrait", "iphone", nullptr, "full-screen", "2x", "LaunchImage-iphone-2x.png", 640, 960 },
  2021. { "portrait", "iphone", "retina4", "full-screen", "2x", "LaunchImage-iphone-retina4.png", 640, 1136 },
  2022. { "portrait", "ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-portrait-1x.png", 768, 1024 },
  2023. { "landscape","ipad", nullptr, "full-screen", "1x", "LaunchImage-ipad-landscape-1x.png", 1024, 768 },
  2024. { "portrait", "ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-portrait-2x.png", 1536, 2048 },
  2025. { "landscape","ipad", nullptr, "full-screen", "2x", "LaunchImage-ipad-landscape-2x.png", 2048, 1536 }
  2026. };
  2027. return Array<ImageType> (types, numElementsInArray (types));
  2028. }
  2029. static String getiOSLaunchImageContents()
  2030. {
  2031. var images;
  2032. for (auto& type : getiOSLaunchImageTypes())
  2033. {
  2034. DynamicObject::Ptr d = new DynamicObject();
  2035. d->setProperty ("orientation", type.orientation);
  2036. d->setProperty ("idiom", type.idiom);
  2037. d->setProperty ("extent", type.extent);
  2038. d->setProperty ("minimum-system-version", "7.0");
  2039. d->setProperty ("scale", type.scale);
  2040. d->setProperty ("filename", type.filename);
  2041. if (type.subtype != nullptr)
  2042. d->setProperty ("subtype", type.subtype);
  2043. images.append (var (d.get()));
  2044. }
  2045. return getiOSAssetContents (images);
  2046. }
  2047. static void createiOSLaunchImageFiles (const File& launchImageSet)
  2048. {
  2049. for (auto& type : getiOSLaunchImageTypes())
  2050. {
  2051. Image image (Image::ARGB, type.width, type.height, true); // (empty black image)
  2052. image.clear (image.getBounds(), Colours::black);
  2053. MemoryOutputStream pngData;
  2054. PNGImageFormat pngFormat;
  2055. pngFormat.writeImageToStream (image, pngData);
  2056. overwriteFileIfDifferentOrThrow (launchImageSet.getChildFile (type.filename), pngData);
  2057. }
  2058. }
  2059. //==============================================================================
  2060. static String getiOSAssetContents (var images)
  2061. {
  2062. DynamicObject::Ptr v (new DynamicObject());
  2063. var info (new DynamicObject());
  2064. info.getDynamicObject()->setProperty ("version", 1);
  2065. info.getDynamicObject()->setProperty ("author", "xcode");
  2066. v->setProperty ("images", images);
  2067. v->setProperty ("info", info);
  2068. return JSON::toString (var (v.get()));
  2069. }
  2070. void createXcassetsFolderFromIcons() const
  2071. {
  2072. const File assets (getTargetFolder().getChildFile (project.getProjectFilenameRoot())
  2073. .getChildFile ("Images.xcassets"));
  2074. const File iconSet (assets.getChildFile ("AppIcon.appiconset"));
  2075. const File launchImage (assets.getChildFile ("LaunchImage.launchimage"));
  2076. overwriteFileIfDifferentOrThrow (iconSet.getChildFile ("Contents.json"), getiOSAppIconContents());
  2077. createiOSIconFiles (iconSet);
  2078. overwriteFileIfDifferentOrThrow (launchImage.getChildFile ("Contents.json"), getiOSLaunchImageContents());
  2079. createiOSLaunchImageFiles (launchImage);
  2080. RelativePath assetsPath (assets, getTargetFolder(), RelativePath::buildTargetFolder);
  2081. addFileReference (assetsPath.toUnixStyle());
  2082. resourceIDs.add (addBuildFile (assetsPath, false, false));
  2083. resourceFileRefs.add (createFileRefID (assetsPath));
  2084. }
  2085. //==============================================================================
  2086. static String indentBracedList (const StringArray& list) { return "{" + indentList (list, ";", 0, true) + " }"; }
  2087. static String indentParenthesisedList (const StringArray& list) { return "(" + indentList (list, ",", 1, false) + " )"; }
  2088. static String indentList (const StringArray& list, const String& separator, int extraTabs, bool shouldSort)
  2089. {
  2090. if (list.size() == 0)
  2091. return " ";
  2092. const String tabs ("\n" + String::repeatedString ("\t", extraTabs + 4));
  2093. if (shouldSort)
  2094. {
  2095. StringArray sorted (list);
  2096. sorted.sort (true);
  2097. return tabs + sorted.joinIntoString (separator + tabs) + separator;
  2098. }
  2099. return tabs + list.joinIntoString (separator + tabs) + separator;
  2100. }
  2101. String createID (String rootString) const
  2102. {
  2103. if (rootString.startsWith ("${"))
  2104. rootString = rootString.fromFirstOccurrenceOf ("}/", false, false);
  2105. rootString += project.getProjectUID();
  2106. return MD5 (rootString.toUTF8()).toHexString().substring (0, 24).toUpperCase();
  2107. }
  2108. String createFileRefID (const RelativePath& path) const { return createFileRefID (path.toUnixStyle()); }
  2109. String createFileRefID (const String& path) const { return createID ("__fileref_" + path); }
  2110. String getIDForGroup (const Project::Item& item) const { return createID (item.getID()); }
  2111. bool shouldFileBeCompiledByDefault (const RelativePath& file) const override
  2112. {
  2113. return file.hasFileExtension (sourceFileExtensions);
  2114. }
  2115. static String getOSXVersionName (int version)
  2116. {
  2117. jassert (version >= 4);
  2118. return "10." + String (version);
  2119. }
  2120. static String getSDKName (int version)
  2121. {
  2122. return getOSXVersionName (version) + " SDK";
  2123. }
  2124. void initialiseDependencyPathValues()
  2125. {
  2126. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder), Ids::vst3Path, TargetOS::osx)));
  2127. aaxPath. referTo (Value (new DependencyPathValueSource (getSetting (Ids::aaxFolder), Ids::aaxPath, TargetOS::osx)));
  2128. rtasPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::rtasFolder), Ids::rtasPath, TargetOS::osx)));
  2129. }
  2130. JUCE_DECLARE_NON_COPYABLE (XCodeProjectExporter)
  2131. };