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.

2753 lines
118KB

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