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.

1050 lines
47KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__
  20. #include "jucer_ProjectExporter.h"
  21. //==============================================================================
  22. class XCodeProjectExporter : public ProjectExporter
  23. {
  24. public:
  25. //==============================================================================
  26. static const char* getNameMac() { return "XCode (MacOSX)"; }
  27. static const char* getNameiPhone() { return "XCode (iPhone)"; }
  28. static const char* getValueTreeTypeName (bool iPhone) { return iPhone ? "XCODE_IPHONE" : "XCODE_MAC"; }
  29. //==============================================================================
  30. XCodeProjectExporter (Project& project_, const ValueTree& settings_, const bool iPhone_)
  31. : ProjectExporter (project_, settings_),
  32. iPhone (iPhone_)
  33. {
  34. name = iPhone ? getNameiPhone() : getNameMac();
  35. projectIDSalt = hashCode64 (project.getProjectUID());
  36. if (getTargetLocation().toString().isEmpty())
  37. getTargetLocation() = getDefaultBuildsRootFolder() + (iPhone ? "iPhone" : "MacOSX");
  38. if (getVSTFolder().toString().isEmpty())
  39. getVSTFolder() = "~/SDKs/vstsdk2.4";
  40. if (getRTASFolder().toString().isEmpty())
  41. getRTASFolder() = "~/SDKs/PT_80_SDK";
  42. }
  43. ~XCodeProjectExporter()
  44. {
  45. }
  46. static XCodeProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  47. {
  48. if (settings.hasType (getValueTreeTypeName (false)))
  49. return new XCodeProjectExporter (project, settings, false);
  50. else if (settings.hasType (getValueTreeTypeName (true)))
  51. return new XCodeProjectExporter (project, settings, true);
  52. return 0;
  53. }
  54. //==============================================================================
  55. bool isDefaultFormatForCurrentOS()
  56. {
  57. #if JUCE_MAC
  58. return ! iPhone;
  59. #else
  60. return false;
  61. #endif
  62. }
  63. bool isPossibleForCurrentProject() { return project.isGUIApplication() || ! iPhone; }
  64. const String getOSTestMacro() { return "(defined(__APPLE_CPP__) || defined(__APPLE_CC__))"; }
  65. bool usesMMFiles() const { return true; }
  66. void createPropertyEditors (Array <PropertyComponent*>& props)
  67. {
  68. ProjectExporter::createPropertyEditors (props);
  69. props.add (new TextPropertyComponent (getSetting ("objCExtraSuffix"), "Objective-C class name suffix", 64, false));
  70. props.getLast()->setTooltip ("Because objective-C linkage is done by string-matching, you can get horrible linkage mix-ups when different modules containing the "
  71. "same class-names are loaded simultaneously. This setting lets you provide a unique string that will be used in naming the obj-C classes in your executable to avoid this.");
  72. if (! iPhone)
  73. {
  74. props.add (new TextPropertyComponent (getSetting ("documentExtensions"), "Document file extensions", 128, false));
  75. props.getLast()->setTooltip ("A comma-separated list of file extensions for documents that your app can open.");
  76. }
  77. }
  78. void launchProject()
  79. {
  80. getProjectBundle().startAsProcess();
  81. }
  82. //==============================================================================
  83. const String create()
  84. {
  85. infoPlistFile = getTargetFolder().getChildFile ("Info.plist");
  86. File projectBundle (getProjectBundle());
  87. if (! projectBundle.createDirectory())
  88. return "Can't write to the target directory";
  89. createObjects();
  90. File projectFile (projectBundle.getChildFile ("project.pbxproj"));
  91. {
  92. MemoryOutputStream mo;
  93. writeProjectFile (mo);
  94. if (! overwriteFileWithNewDataIfDifferent (projectFile, mo))
  95. return "Can't write to file: " + projectFile.getFullPathName();
  96. }
  97. if (! writeInfoPlistFile())
  98. return "Can't write the Info.plist file";
  99. return String::empty;
  100. }
  101. private:
  102. OwnedArray<ValueTree> pbxBuildFiles, pbxFileReferences, groups, misc, projectConfigs, targetConfigs;
  103. StringArray buildPhaseIDs, resourceIDs, sourceIDs, frameworkIDs;
  104. StringArray frameworkFileIDs, rezFileIDs, resourceFileRefs;
  105. File infoPlistFile;
  106. int64 projectIDSalt;
  107. const bool iPhone;
  108. static const String sanitisePath (const String& path)
  109. {
  110. if (path.startsWithChar ('~'))
  111. return "$(HOME)" + path.substring (1);
  112. return path;
  113. }
  114. const File getProjectBundle() const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (".xcodeproj"); }
  115. const RelativePath getJuceLibFile() const { return getJucePathFromTargetFolder().getChildFile ("bin/libjucedebug.a"); }
  116. bool hasPList() const { return ! (project.isLibrary() || project.isCommandLineApp()); }
  117. const String getAudioPluginBundleExtension() const { return "component"; }
  118. //==============================================================================
  119. void createObjects()
  120. {
  121. if (! project.isLibrary())
  122. addFrameworks();
  123. const String productName (project.getConfiguration (0).getTargetBinaryName().toString());
  124. if (project.isGUIApplication())
  125. addBuildProduct ("wrapper.application", productName + ".app");
  126. else if (project.isCommandLineApp())
  127. addBuildProduct ("compiled.mach-o.executable", productName);
  128. else if (project.isLibrary())
  129. addBuildProduct ("archive.ar", getLibbedFilename (productName));
  130. else if (project.isAudioPlugin())
  131. addBuildProduct ("wrapper.cfbundle", productName + "." + getAudioPluginBundleExtension());
  132. else if (project.isBrowserPlugin())
  133. addBuildProduct ("wrapper.cfbundle", productName + ".plugin");
  134. else
  135. jassert (productName.isEmpty());
  136. if (hasPList())
  137. {
  138. RelativePath plistPath (infoPlistFile, getTargetFolder(), RelativePath::buildTargetFolder);
  139. addFileReference (plistPath);
  140. resourceFileRefs.add (createID (plistPath));
  141. }
  142. addProjectItem (project.getMainGroup());
  143. for (int i = 0; i < project.getNumConfigurations(); ++i)
  144. {
  145. Project::BuildConfiguration config (project.getConfiguration (i));
  146. addProjectConfig (config.getName().getValue(), getProjectSettings (config));
  147. addTargetConfig (config.getName().getValue(), getTargetSettings (config));
  148. }
  149. addConfigList (projectConfigs, createID ("__projList"));
  150. addConfigList (targetConfigs, createID ("__configList"));
  151. if (! project.isLibrary())
  152. addBuildPhase ("PBXResourcesBuildPhase", resourceIDs);
  153. if (rezFileIDs.size() > 0)
  154. addBuildPhase ("PBXRezBuildPhase", rezFileIDs);
  155. addBuildPhase ("PBXSourcesBuildPhase", sourceIDs);
  156. if (! project.isLibrary())
  157. addBuildPhase ("PBXFrameworksBuildPhase", frameworkIDs);
  158. if (project.isAudioPlugin())
  159. addPluginShellScriptPhase();
  160. addTargetObject();
  161. addProjectObject();
  162. }
  163. bool writeInfoPlistFile()
  164. {
  165. if (! hasPList())
  166. return true;
  167. XmlElement plist ("plist");
  168. XmlElement* dict = plist.createNewChildElement ("dict");
  169. addPlistDictionaryKey (dict, "CFBundleExecutable", "${EXECUTABLE_NAME}");
  170. addPlistDictionaryKey (dict, "CFBundleIconFile", "");
  171. addPlistDictionaryKey (dict, "CFBundleIdentifier", project.getBundleIdentifier().toString());
  172. addPlistDictionaryKey (dict, "CFBundleName", project.getProjectName().toString());
  173. if (project.isAudioPlugin())
  174. {
  175. addPlistDictionaryKey (dict, "CFBundlePackageType", "TDMw");
  176. addPlistDictionaryKey (dict, "CFBundleSignature", "PTul");
  177. }
  178. else
  179. {
  180. addPlistDictionaryKey (dict, "CFBundlePackageType", "APPL");
  181. addPlistDictionaryKey (dict, "CFBundleSignature", "????");
  182. }
  183. addPlistDictionaryKey (dict, "CFBundleShortVersionString", project.getVersion().toString());
  184. addPlistDictionaryKey (dict, "CFBundleVersion", project.getVersion().toString());
  185. StringArray documentExtensions;
  186. documentExtensions.addTokens (getSetting ("documentExtensions").toString(), ",", String::empty);
  187. documentExtensions.trim();
  188. documentExtensions.removeEmptyStrings (true);
  189. if (documentExtensions.size() > 0)
  190. {
  191. dict->createNewChildElement ("key")->addTextElement ("CFBundleDocumentTypes");
  192. XmlElement* dict2 = dict->createNewChildElement ("array")->createNewChildElement ("dict");
  193. for (int i = 0; i < documentExtensions.size(); ++i)
  194. {
  195. String ex (documentExtensions[i]);
  196. if (ex.startsWithChar ('.'))
  197. ex = ex.substring (1);
  198. dict2->createNewChildElement ("key")->addTextElement ("CFBundleTypeExtensions");
  199. dict2->createNewChildElement ("array")->createNewChildElement ("string")->addTextElement (ex);
  200. addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
  201. addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
  202. addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");
  203. }
  204. }
  205. MemoryOutputStream mo;
  206. plist.writeToStream (mo, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  207. return overwriteFileWithNewDataIfDifferent (infoPlistFile, mo);
  208. }
  209. const StringArray getHeaderSearchPaths (const Project::BuildConfiguration& config)
  210. {
  211. StringArray searchPaths (config.getHeaderSearchPaths());
  212. if (project.shouldAddVSTFolderToPath() && getVSTFolder().toString().isNotEmpty())
  213. searchPaths.add (RelativePath (getVSTFolder().toString(), RelativePath::projectFolder)
  214. .rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder)
  215. .toUnixStyle());
  216. if (project.isAudioPlugin())
  217. {
  218. if (isAU())
  219. {
  220. searchPaths.add ("$(DEVELOPER_DIR)/Extras/CoreAudio/PublicUtility");
  221. searchPaths.add ("$(DEVELOPER_DIR)/Extras/CoreAudio/AudioUnits/AUPublic/Utility");
  222. }
  223. if (isRTAS())
  224. {
  225. searchPaths.add ("/Developer/Headers/FlatCarbon");
  226. static const char* rtasIncludePaths[] = { "AlturaPorts/TDMPlugIns/PlugInLibrary/Controls",
  227. "AlturaPorts/TDMPlugIns/PlugInLibrary/CoreClasses",
  228. "AlturaPorts/TDMPlugIns/PlugInLibrary/DSPClasses",
  229. "AlturaPorts/TDMPlugIns/PlugInLibrary/EffectClasses",
  230. "AlturaPorts/TDMPlugIns/PlugInLibrary/MacBuild",
  231. "AlturaPorts/TDMPlugIns/PlugInLibrary/Meters",
  232. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses",
  233. "AlturaPorts/TDMPlugIns/PlugInLibrary/ProcessClasses/Interfaces",
  234. "AlturaPorts/TDMPlugIns/PlugInLibrary/RTASP_Adapt",
  235. "AlturaPorts/TDMPlugIns/PlugInLibrary/Utilities",
  236. "AlturaPorts/TDMPlugIns/PlugInLibrary/ViewClasses",
  237. "AlturaPorts/TDMPlugIns/DSPManager/**",
  238. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/Encryption",
  239. "AlturaPorts/TDMPlugIns/SupplementalPlugInLib/GraphicsExtensions",
  240. "AlturaPorts/TDMPlugIns/common",
  241. "AlturaPorts/TDMPlugIns/common/PI_LibInterface",
  242. "AlturaPorts/TDMPlugIns/PACEProtection/**",
  243. "AlturaPorts/TDMPlugIns/SignalProcessing/**",
  244. "AlturaPorts/OMS/Headers",
  245. "AlturaPorts/Fic/Interfaces/**",
  246. "AlturaPorts/Fic/Source/SignalNets",
  247. "AlturaPorts/DSIPublicInterface/PublicHeaders",
  248. "DAEWin/Include",
  249. "AlturaPorts/DigiPublic/Interfaces",
  250. "AlturaPorts/DigiPublic",
  251. "AlturaPorts/NewFileLibs/DOA",
  252. "AlturaPorts/NewFileLibs/Cmn",
  253. "xplat/AVX/avx2/avx2sdk/inc",
  254. "xplat/AVX/avx2/avx2sdk/utils" };
  255. RelativePath sdkFolder (getRTASFolder().toString(), RelativePath::projectFolder);
  256. sdkFolder = sdkFolder.rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder);
  257. for (int i = 0; i < numElementsInArray (rtasIncludePaths); ++i)
  258. searchPaths.add (sdkFolder.getChildFile (rtasIncludePaths[i]).toUnixStyle());
  259. }
  260. }
  261. return searchPaths;
  262. }
  263. void getLinkerFlagsForStaticLibrary (const RelativePath& library, StringArray& flags, StringArray& librarySearchPaths)
  264. {
  265. jassert (library.getFileNameWithoutExtension().substring (0, 3) == "lib");
  266. flags.add ("-l" + library.getFileNameWithoutExtension().substring (3));
  267. String searchPath (library.toUnixStyle().upToLastOccurrenceOf ("/", false, false));
  268. if (! library.isAbsolute())
  269. searchPath = "$(SRCROOT)/" + searchPath;
  270. librarySearchPaths.add (sanitisePath (searchPath));
  271. }
  272. void getLinkerFlags (const Project::BuildConfiguration& config, StringArray& flags, StringArray& librarySearchPaths)
  273. {
  274. if (project.isAudioPlugin())
  275. {
  276. flags.add ("-bundle");
  277. if (isRTAS() && getRTASFolder().toString().isNotEmpty())
  278. {
  279. getLinkerFlagsForStaticLibrary (RelativePath (getRTASFolder().toString(), RelativePath::buildTargetFolder)
  280. .getChildFile (config.isDebug().getValue() ? "MacBag/Libs/Debug/libPluginLibrary.a"
  281. : "MacBag/Libs/Release/libPluginLibrary.a"),
  282. flags, librarySearchPaths);
  283. }
  284. }
  285. if (project.getJuceLinkageMode() == Project::useLinkedJuce)
  286. getLinkerFlagsForStaticLibrary (getJuceLibFile(), flags, librarySearchPaths);
  287. flags.add (getExtraLinkerFlags().toString());
  288. flags.removeEmptyStrings (true);
  289. }
  290. const StringArray getProjectSettings (const Project::BuildConfiguration& config)
  291. {
  292. StringArray settings;
  293. settings.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  294. settings.add ("GCC_C_LANGUAGE_STANDARD = c99");
  295. settings.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  296. settings.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  297. settings.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  298. settings.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  299. settings.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  300. settings.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  301. settings.add ("GCC_MODEL_TUNING = G5");
  302. settings.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  303. settings.add ("ZERO_LINK = NO");
  304. settings.add ("DEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\"");
  305. settings.add ("PRODUCT_NAME = \"" + config.getTargetBinaryName().toString() + "\"");
  306. return settings;
  307. }
  308. const StringArray getTargetSettings (const Project::BuildConfiguration& config)
  309. {
  310. StringArray settings;
  311. settings.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  312. settings.add ("PREBINDING = NO");
  313. settings.add ("HEADER_SEARCH_PATHS = \"" + getHeaderSearchPaths (config).joinIntoString (" ") + " $(inherited)\"");
  314. settings.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  315. settings.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  316. if (getExtraCompilerFlags().toString().isNotEmpty())
  317. settings.add ("OTHER_CPLUSPLUSFLAGS = " + getExtraCompilerFlags().toString());
  318. switch ((int) project.getProjectType().getValue())
  319. {
  320. case Project::application:
  321. settings.add ("INSTALL_PATH = \"$(HOME)/Applications\"");
  322. break;
  323. case Project::commandLineApp:
  324. break;
  325. case Project::audioPlugin:
  326. settings.add ("LIBRARY_STYLE = Bundle");
  327. settings.add ("INSTALL_PATH = \"$(HOME)/Library/Audio/Plug-Ins/Components/\"");
  328. settings.add ("WRAPPER_EXTENSION = " + getAudioPluginBundleExtension());
  329. settings.add ("GENERATE_PKGINFO_FILE = YES");
  330. settings.add ("OTHER_REZFLAGS = \"-d ppc_$ppc -d i386_$i386 -d ppc64_$ppc64 -d x86_64_$x86_64"
  331. " -I /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Versions/A/Headers"
  332. " -I \\\"$(DEVELOPER_DIR)/Extras/CoreAudio/AudioUnits/AUPublic/AUBase\\\"\"");
  333. break;
  334. case Project::browserPlugin:
  335. settings.add ("LIBRARY_STYLE = Bundle");
  336. settings.add ("INSTALL_PATH = \"/Library/Internet Plug-Ins/\"");
  337. break;
  338. case Project::library:
  339. if (config.getTargetBinaryRelativePath().toString().isNotEmpty())
  340. {
  341. RelativePath binaryPath (config.getTargetBinaryRelativePath().toString(), RelativePath::projectFolder);
  342. binaryPath = binaryPath.rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder);
  343. settings.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  344. settings.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  345. }
  346. settings.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  347. settings.add ("DEPLOYMENT_LOCATION = YES");
  348. break;
  349. default:
  350. jassertfalse; break;
  351. }
  352. if (iPhone)
  353. {
  354. settings.add ("SDKROOT = iphonesimulator3.0");
  355. }
  356. else
  357. {
  358. switch ((int) config.getMacSDKVersion().getValue())
  359. {
  360. case 2: settings.add ("SDKROOT = macosx10.4"); settings.add ("GCC_VERSION = 4.0"); break;
  361. case 3: settings.add ("SDKROOT = macosx10.5"); break;
  362. case 4: settings.add ("SDKROOT = macosx10.6"); break;
  363. default: break;
  364. }
  365. switch ((int) config.getMacCompatibilityVersion().getValue())
  366. {
  367. case 2: settings.add ("MACOSX_DEPLOYMENT_TARGET = 10.4"); break;
  368. case 3: settings.add ("MACOSX_DEPLOYMENT_TARGET = 10.5"); break;
  369. case 4: settings.add ("MACOSX_DEPLOYMENT_TARGET = 10.6"); break;
  370. default: break;
  371. }
  372. settings.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  373. }
  374. {
  375. StringArray linkerFlags, librarySearchPaths;
  376. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  377. if (linkerFlags.size() > 0)
  378. settings.add ("OTHER_LDFLAGS = \"" + linkerFlags.joinIntoString (" ") + "\"");
  379. if (librarySearchPaths.size() > 0)
  380. {
  381. String libPaths ("LIBRARY_SEARCH_PATHS = (\"$(inherited)\"");
  382. for (int i = 0; i < librarySearchPaths.size(); ++i)
  383. libPaths += ", \"\\\"" + librarySearchPaths[i] + "\\\"\"";
  384. settings.add (libPaths + ")");
  385. }
  386. }
  387. StringArray defines;
  388. if (config.isDebug().getValue())
  389. {
  390. defines.add ("_DEBUG=1");
  391. defines.add ("DEBUG=1 ");
  392. settings.add ("ONLY_ACTIVE_ARCH = YES");
  393. settings.add ("COPY_PHASE_STRIP = NO");
  394. settings.add ("GCC_DYNAMIC_NO_PIC = NO");
  395. settings.add ("GCC_ENABLE_FIX_AND_CONTINUE = YES");
  396. }
  397. else
  398. {
  399. defines.add ("_NDEBUG=1");
  400. defines.add ("NDEBUG=1 ");
  401. settings.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  402. settings.add ("GCC_SYMBOLS_PRIVATE_EXTERN = YES");
  403. }
  404. {
  405. const String objCSuffix (getSetting ("objCExtraSuffix").toString().trim());
  406. if (objCSuffix.isNotEmpty())
  407. defines.add ("JUCE_ObjCExtraSuffix=" + objCSuffix);
  408. }
  409. {
  410. defines.addArray (config.parsePreprocessorDefs());
  411. for (int i = defines.size(); --i >= 0;)
  412. defines.set (i, defines[i].quoted());
  413. settings.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defines, ",") + ")");
  414. }
  415. return settings;
  416. }
  417. void addFrameworks()
  418. {
  419. StringArray s;
  420. if (iPhone)
  421. {
  422. s.addTokens ("UIKit Foundation CoreGraphics AudioToolbox QuartzCore OpenGLES", false);
  423. }
  424. else
  425. {
  426. s.addTokens ("Cocoa Carbon IOKit CoreAudio CoreMIDI WebKit DiscRecording OpenGL QuartzCore QTKit QuickTime", false);
  427. if (isAU())
  428. s.addTokens ("AudioUnit CoreAudioKit AudioToolbox", false);
  429. else if ((int) project.getJuceConfigFlag ("JUCE_PLUGINHOST_AU").getValue() == 1)
  430. s.addTokens ("AudioUnit CoreAudioKit", false);
  431. }
  432. for (int i = 0; i < s.size(); ++i)
  433. addFramework (s[i]);
  434. }
  435. //==============================================================================
  436. void writeProjectFile (OutputStream& output)
  437. {
  438. output << "// !$*UTF8*$!\n{\n"
  439. "\tarchiveVersion = 1;\n"
  440. "\tclasses = {\n\t};\n"
  441. "\tobjectVersion = 44;\n"
  442. "\tobjects = {\n\n";
  443. Array <ValueTree*> objects;
  444. objects.addArray (pbxBuildFiles);
  445. objects.addArray (pbxFileReferences);
  446. objects.addArray (groups);
  447. objects.addArray (targetConfigs);
  448. objects.addArray (projectConfigs);
  449. objects.addArray (misc);
  450. for (int i = 0; i < objects.size(); ++i)
  451. {
  452. ValueTree& o = *objects.getUnchecked(i);
  453. output << "\t\t" << o.getType() << " = { ";
  454. for (int j = 0; j < o.getNumProperties(); ++j)
  455. {
  456. const var::identifier name (o.getPropertyName(j));
  457. String val (o.getProperty (name).toString());
  458. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,-\r\n")
  459. && ! (val.trimStart().startsWithChar ('(')
  460. || val.trimStart().startsWithChar ('{'))))
  461. val = val.quoted();
  462. output << name.name << " = " << val << "; ";
  463. }
  464. output << "};\n";
  465. }
  466. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  467. }
  468. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  469. {
  470. xml->createNewChildElement ("key")->addTextElement (key);
  471. xml->createNewChildElement ("string")->addTextElement (value);
  472. }
  473. const String addBuildFile (const RelativePath& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings)
  474. {
  475. String fileID (createID (path.toUnixStyle() + "buildref"));
  476. if (addToSourceBuildPhase)
  477. sourceIDs.add (fileID);
  478. ValueTree* v = new ValueTree (fileID);
  479. v->setProperty ("isa", "PBXBuildFile", 0);
  480. v->setProperty ("fileRef", fileRefID, 0);
  481. if (inhibitWarnings)
  482. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", 0);
  483. pbxBuildFiles.add (v);
  484. return fileID;
  485. }
  486. const String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings)
  487. {
  488. return addBuildFile (path, createID (path), addToSourceBuildPhase, inhibitWarnings);
  489. }
  490. void addFileReference (const RelativePath& path, const String& sourceTree, const String& lastKnownFileType, const String& fileRefID)
  491. {
  492. ValueTree* v = new ValueTree (fileRefID);
  493. v->setProperty ("isa", "PBXFileReference", 0);
  494. v->setProperty ("lastKnownFileType", lastKnownFileType, 0);
  495. v->setProperty ("name", path.getFileName(), 0);
  496. v->setProperty ("path", sanitisePath (path.toUnixStyle()), 0);
  497. v->setProperty ("sourceTree", sourceTree, 0);
  498. pbxFileReferences.add (v);
  499. }
  500. const String addFileReference (const RelativePath& path)
  501. {
  502. const String fileRefID (createID (path));
  503. jassert (path.isAbsolute() || path.getRoot() == RelativePath::buildTargetFolder);
  504. addFileReference (path, path.isAbsolute() ? "<absolute>" : "SOURCE_ROOT",
  505. getFileType (path), fileRefID);
  506. return fileRefID;
  507. }
  508. static const String getFileType (const RelativePath& file)
  509. {
  510. if (file.hasFileExtension (".cpp")) return "sourcecode.cpp.cpp";
  511. else if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  512. else if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  513. else if (file.hasFileExtension (".h;.hpp")) return "sourcecode.c.h";
  514. else if (file.hasFileExtension (".framework")) return "wrapper.framework";
  515. else if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  516. else if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  517. else if (file.hasFileExtension ("html;htm")) return "text.html";
  518. else if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  519. else if (file.hasFileExtension ("plist")) return "text.plist.xml";
  520. else if (file.hasFileExtension ("app")) return "wrapper.application";
  521. else if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  522. else if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  523. else if (file.hasFileExtension ("a")) return "archive.ar";
  524. return "file" + file.getFileExtension();
  525. }
  526. const String addFile (const RelativePath& path, bool shouldBeCompiled, bool inhibitWarnings)
  527. {
  528. if (shouldBeCompiled)
  529. addBuildFile (path, true, inhibitWarnings);
  530. else if (path.hasFileExtension (".r"))
  531. rezFileIDs.add (addBuildFile (path, false, inhibitWarnings));
  532. return addFileReference (path);
  533. }
  534. const String addProjectItem (const Project::Item& projectItem)
  535. {
  536. if (projectItem.isGroup())
  537. {
  538. StringArray childIDs;
  539. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  540. {
  541. const String childID (addProjectItem (projectItem.getChild(i)));
  542. if (childID.isNotEmpty())
  543. childIDs.add (childID);
  544. }
  545. return addGroup (projectItem, childIDs);
  546. }
  547. else
  548. {
  549. if (projectItem.shouldBeAddedToTargetProject())
  550. {
  551. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  552. return addFile (path, projectItem.shouldBeCompiled(), false);
  553. }
  554. }
  555. return String::empty;
  556. }
  557. void addFramework (const String& frameworkName)
  558. {
  559. const RelativePath path ("System/Library/Frameworks/" + frameworkName + ".framework", RelativePath::unknown);
  560. const String fileRefID (createID (path));
  561. addFileReference (path, "SDKROOT", getFileType (path), fileRefID);
  562. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  563. frameworkFileIDs.add (fileRefID);
  564. }
  565. void addGroup (const String& groupID, const String& name, const StringArray& childIDs)
  566. {
  567. ValueTree* v = new ValueTree (groupID);
  568. v->setProperty ("isa", "PBXGroup", 0);
  569. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", 0);
  570. v->setProperty ("name", name, 0);
  571. v->setProperty ("sourceTree", "<group>", 0);
  572. groups.add (v);
  573. }
  574. const String createGroup (const Array<RelativePath>& files, const String& groupName, const String& groupIDName, bool inhibitWarnings)
  575. {
  576. StringArray fileIDs;
  577. for (int i = 0; i < files.size(); ++i)
  578. {
  579. addFile (files.getReference(i), shouldFileBeCompiledByDefault (files.getReference(i)), inhibitWarnings);
  580. fileIDs.add (createID (files.getReference(i)));
  581. }
  582. const String groupID (createID (groupIDName));
  583. addGroup (groupID, groupName, fileIDs);
  584. return groupID;
  585. }
  586. const String addGroup (const Project::Item& item, StringArray& childIDs)
  587. {
  588. String groupName (item.getName().toString());
  589. if (item.isMainGroup())
  590. {
  591. groupName = "Source";
  592. // Add 'Juce Library Code' group
  593. if (juceWrapperFiles.size() > 0)
  594. childIDs.add (createGroup (juceWrapperFiles, project.getJuceCodeGroupName(), "__jucelibfiles", false));
  595. if (isVST())
  596. childIDs.add (createGroup (getVSTFilesRequired(), "Juce VST Wrapper", "__jucevstfiles", false));
  597. if (isAU())
  598. childIDs.add (createAUWrappersGroup());
  599. if (isRTAS())
  600. childIDs.add (createGroup (getRTASFilesRequired(), "Juce RTAS Wrapper", "__jucertasfiles", true));
  601. { // Add 'resources' group
  602. String resourcesGroupID (createID ("__resources"));
  603. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  604. childIDs.add (resourcesGroupID);
  605. }
  606. { // Add 'frameworks' group
  607. String frameworksGroupID (createID ("__frameworks"));
  608. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  609. childIDs.add (frameworksGroupID);
  610. }
  611. { // Add 'products' group
  612. String productsGroupID (createID ("__products"));
  613. StringArray products;
  614. products.add (createID ("__productFileID"));
  615. addGroup (productsGroupID, "Products", products);
  616. childIDs.add (productsGroupID);
  617. }
  618. }
  619. String groupID (getIDForGroup (item));
  620. addGroup (groupID, groupName, childIDs);
  621. return groupID;
  622. }
  623. void addBuildProduct (const String& fileType, const String& binaryName)
  624. {
  625. ValueTree* v = new ValueTree (createID ("__productFileID"));
  626. v->setProperty ("isa", "PBXFileReference", 0);
  627. v->setProperty ("explicitFileType", fileType, 0);
  628. v->setProperty ("includeInIndex", (int) 0, 0);
  629. v->setProperty ("path", sanitisePath (binaryName), 0);
  630. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", 0);
  631. pbxFileReferences.add (v);
  632. }
  633. void addTargetConfig (const String& name, const StringArray& settings)
  634. {
  635. ValueTree* v = new ValueTree (createID ("targetconfigid_" + name));
  636. v->setProperty ("isa", "XCBuildConfiguration", 0);
  637. v->setProperty ("buildSettings", "{" + indentList (settings, ";") + " }", 0);
  638. v->setProperty ("name", name, 0);
  639. targetConfigs.add (v);
  640. }
  641. void addProjectConfig (const String& name, const StringArray& settings)
  642. {
  643. ValueTree* v = new ValueTree (createID ("projectconfigid_" + name));
  644. v->setProperty ("isa", "XCBuildConfiguration", 0);
  645. v->setProperty ("buildSettings", "{" + indentList (settings, ";") + " }", 0);
  646. v->setProperty ("name", name, 0);
  647. projectConfigs.add (v);
  648. }
  649. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID)
  650. {
  651. StringArray configIDs;
  652. for (int i = 0; i < configsToUse.size(); ++i)
  653. configIDs.add (configsToUse[i]->getType());
  654. ValueTree* v = new ValueTree (listID);
  655. v->setProperty ("isa", "XCConfigurationList", 0);
  656. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", 0);
  657. v->setProperty ("defaultConfigurationIsVisible", (int) 0, 0);
  658. if (configsToUse[0] != 0)
  659. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty ("name"), 0);
  660. misc.add (v);
  661. }
  662. ValueTree* addBuildPhase (const String& phaseType, const StringArray& fileIds)
  663. {
  664. String phaseId (createID (phaseType + "resbuildphase"));
  665. buildPhaseIDs.add (phaseId);
  666. ValueTree* v = new ValueTree (phaseId);
  667. v->setProperty ("isa", phaseType, 0);
  668. v->setProperty ("buildActionMask", "2147483647", 0);
  669. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", 0);
  670. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, 0);
  671. misc.add (v);
  672. return v;
  673. }
  674. void addTargetObject()
  675. {
  676. ValueTree* v = new ValueTree (createID ("__target"));
  677. v->setProperty ("isa", "PBXNativeTarget", 0);
  678. v->setProperty ("buildConfigurationList", createID ("__configList"), 0);
  679. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", 0);
  680. v->setProperty ("buildRules", "( )", 0);
  681. v->setProperty ("dependencies", "( )", 0);
  682. v->setProperty ("name", project.getDocumentTitle(), 0);
  683. v->setProperty ("productName", project.getDocumentTitle(), 0);
  684. v->setProperty ("productReference", createID ("__productFileID"), 0);
  685. if (project.isGUIApplication())
  686. {
  687. v->setProperty ("productInstallPath", "$(HOME)/Applications", 0);
  688. v->setProperty ("productType", "com.apple.product-type.application", 0);
  689. }
  690. else if (project.isCommandLineApp())
  691. {
  692. v->setProperty ("productInstallPath", "/usr/bin", 0);
  693. v->setProperty ("productType", "com.apple.product-type.tool", 0);
  694. }
  695. else if (project.isAudioPlugin() || project.isBrowserPlugin())
  696. {
  697. v->setProperty ("productInstallPath", "$(HOME)/Library/Audio/Plug-Ins/Components/", 0);
  698. v->setProperty ("productType", "com.apple.product-type.bundle", 0);
  699. }
  700. else if (project.isLibrary())
  701. {
  702. v->setProperty ("productType", "com.apple.product-type.library.static", 0);
  703. }
  704. else
  705. jassertfalse; //xxx
  706. misc.add (v);
  707. }
  708. void addProjectObject()
  709. {
  710. ValueTree* v = new ValueTree (createID ("__root"));
  711. v->setProperty ("isa", "PBXProject", 0);
  712. v->setProperty ("buildConfigurationList", createID ("__projList"), 0);
  713. v->setProperty ("compatibilityVersion", "Xcode 3.0", 0);
  714. v->setProperty ("hasScannedForEncodings", (int) 0, 0);
  715. v->setProperty ("mainGroup", getIDForGroup (project.getMainGroup()), 0);
  716. v->setProperty ("projectDirPath", "\"\"", 0);
  717. v->setProperty ("projectRoot", "\"\"", 0);
  718. v->setProperty ("targets", "( " + createID ("__target") + " )", 0);
  719. misc.add (v);
  720. }
  721. void addPluginShellScriptPhase()
  722. {
  723. ValueTree* v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  724. v->setProperty ("name", "Copy to the different plugin folders", 0);
  725. v->setProperty ("shellPath", "/bin/sh", 0);
  726. v->setProperty ("shellScript", String::fromUTF8 (BinaryData::AudioPluginXCodeScript_txt, BinaryData::AudioPluginXCodeScript_txtSize)
  727. .replace ("\\", "\\\\")
  728. .replace ("\"", "\\\"")
  729. .replace ("\r\n", "\\n")
  730. .replace ("\n", "\\n"), 0);
  731. }
  732. //==============================================================================
  733. static const String indentList (const StringArray& list, const String& separator)
  734. {
  735. if (list.size() == 0)
  736. return " ";
  737. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  738. + (separator == ";" ? separator : String::empty);
  739. }
  740. const String createID (const RelativePath& path) const
  741. {
  742. return createID (path.toUnixStyle());
  743. }
  744. const String createID (const String& name) const
  745. {
  746. static const char digits[] = "0123456789ABCDEF";
  747. char n[24];
  748. Random ran (projectIDSalt + hashCode64 (name));
  749. for (int i = 0; i < numElementsInArray (n); ++i)
  750. n[i] = digits [ran.nextInt (16)];
  751. return String (n, numElementsInArray (n));
  752. }
  753. const String getIDForGroup (const Project::Item& item) const
  754. {
  755. return createID (item.getID());
  756. }
  757. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  758. {
  759. return file.hasFileExtension ("cpp;mm;c;m");
  760. }
  761. //==============================================================================
  762. const Array<RelativePath> getRTASFilesRequired() const
  763. {
  764. Array<RelativePath> s;
  765. if (isRTAS())
  766. {
  767. const char* files[] = { "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode1.cpp",
  768. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode2.cpp",
  769. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode3.cpp",
  770. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode_Header.h",
  771. "extras/audio plugins/wrapper/RTAS/juce_RTAS_MacResources.r",
  772. "extras/audio plugins/wrapper/RTAS/juce_RTAS_MacUtilities.mm",
  773. "extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp" };
  774. for (int i = 0; i < numElementsInArray (files); ++i)
  775. s.add (getJucePathFromTargetFolder().getChildFile (files[i]));
  776. }
  777. return s;
  778. }
  779. const String createAUWrappersGroup()
  780. {
  781. Array<RelativePath> auWrappers;
  782. const char* files[] = { "extras/audio plugins/wrapper/AU/juce_AU_Resources.r",
  783. "extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm" };
  784. int i;
  785. for (i = 0; i < numElementsInArray (files); ++i)
  786. auWrappers.add (getJucePathFromTargetFolder().getChildFile (files[i]));
  787. const char* appleAUFiles[] = { "Extras/CoreAudio/PublicUtility/CADebugMacros.h",
  788. "Extras/CoreAudio/PublicUtility/CAAUParameter.cpp",
  789. "Extras/CoreAudio/PublicUtility/CAAUParameter.h",
  790. "Extras/CoreAudio/PublicUtility/CAAudioChannelLayout.cpp",
  791. "Extras/CoreAudio/PublicUtility/CAAudioChannelLayout.h",
  792. "Extras/CoreAudio/PublicUtility/CAMutex.cpp",
  793. "Extras/CoreAudio/PublicUtility/CAMutex.h",
  794. "Extras/CoreAudio/PublicUtility/CAStreamBasicDescription.cpp",
  795. "Extras/CoreAudio/PublicUtility/CAStreamBasicDescription.h",
  796. "Extras/CoreAudio/PublicUtility/CAVectorUnitTypes.h",
  797. "Extras/CoreAudio/PublicUtility/CAVectorUnit.cpp",
  798. "Extras/CoreAudio/PublicUtility/CAVectorUnit.h",
  799. "Extras/CoreAudio/AudioUnits/AUPublic/AUViewBase/AUViewLocalizedStringKeys.h",
  800. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewDispatch.cpp",
  801. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewControl.cpp",
  802. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewControl.h",
  803. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/CarbonEventHandler.cpp",
  804. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/CarbonEventHandler.h",
  805. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewBase.cpp",
  806. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewBase.h",
  807. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUBase.cpp",
  808. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUBase.h",
  809. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUDispatch.cpp",
  810. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUDispatch.h",
  811. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUInputElement.cpp",
  812. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUInputElement.h",
  813. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUOutputElement.cpp",
  814. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUOutputElement.h",
  815. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUResources.r",
  816. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUScopeElement.cpp",
  817. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUScopeElement.h",
  818. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/ComponentBase.cpp",
  819. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/ComponentBase.h",
  820. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIBase.cpp",
  821. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIBase.h",
  822. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIEffectBase.cpp",
  823. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIEffectBase.h",
  824. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUOutputBase.cpp",
  825. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUOutputBase.h",
  826. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/MusicDeviceBase.cpp",
  827. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/MusicDeviceBase.h",
  828. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUEffectBase.cpp",
  829. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUEffectBase.h",
  830. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUBuffer.cpp",
  831. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUBuffer.h",
  832. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUDebugDispatcher.cpp",
  833. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUDebugDispatcher.h",
  834. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUInputFormatConverter.h",
  835. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUSilentTimeout.h",
  836. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUTimestampGenerator.h" };
  837. StringArray fileIDs, appleFileIDs;
  838. for (i = 0; i < auWrappers.size(); ++i)
  839. {
  840. addFile (auWrappers.getReference(i), shouldFileBeCompiledByDefault (auWrappers.getReference(i)), false);
  841. fileIDs.add (createID (auWrappers.getReference(i)));
  842. }
  843. for (i = 0; i < numElementsInArray (appleAUFiles); ++i)
  844. {
  845. RelativePath file (appleAUFiles[i], RelativePath::unknown);
  846. const String fileRefID (createID (file));
  847. addFileReference (file, "DEVELOPER_DIR", getFileType (file), fileRefID);
  848. if (shouldFileBeCompiledByDefault (file))
  849. addBuildFile (file, fileRefID, true, true);
  850. appleFileIDs.add (fileRefID);
  851. }
  852. const String appleGroupID (createID ("__juceappleaufiles"));
  853. addGroup (appleGroupID, "Apple AU Files", appleFileIDs);
  854. fileIDs.add (appleGroupID);
  855. const String groupID (createID ("__juceaufiles"));
  856. addGroup (groupID, "Juce AU Wrapper", fileIDs);
  857. return groupID;
  858. }
  859. };
  860. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__