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.

2764 lines
121KB

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