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.

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