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.

2653 lines
116KB

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