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.

2749 lines
120KB

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