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.

1051 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 (project.isGUIApplication() && ! 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 (! FileHelpers::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 FileHelpers::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 s;
  293. s.add ("ALWAYS_SEARCH_USER_PATHS = NO");
  294. s.add ("GCC_C_LANGUAGE_STANDARD = c99");
  295. s.add ("GCC_WARN_ABOUT_RETURN_TYPE = YES");
  296. s.add ("GCC_WARN_CHECK_SWITCH_STATEMENTS = YES");
  297. s.add ("GCC_WARN_UNUSED_VARIABLE = YES");
  298. s.add ("GCC_WARN_MISSING_PARENTHESES = YES");
  299. s.add ("GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES");
  300. s.add ("GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES");
  301. s.add ("GCC_MODEL_TUNING = G5");
  302. s.add ("GCC_INLINES_ARE_PRIVATE_EXTERN = YES");
  303. s.add ("ZERO_LINK = NO");
  304. s.add ("DEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\"");
  305. s.add ("PRODUCT_NAME = \"" + config.getTargetBinaryName().toString() + "\"");
  306. return s;
  307. }
  308. const StringArray getTargetSettings (const Project::BuildConfiguration& config)
  309. {
  310. StringArray s;
  311. s.add ("ARCHS = \"$(ARCHS_STANDARD_32_BIT)\"");
  312. s.add ("PREBINDING = NO");
  313. s.add ("HEADER_SEARCH_PATHS = \"" + getHeaderSearchPaths (config).joinIntoString (" ") + " $(inherited)\"");
  314. s.add ("GCC_OPTIMIZATION_LEVEL = " + config.getGCCOptimisationFlag());
  315. s.add ("INFOPLIST_FILE = " + infoPlistFile.getFileName());
  316. if (getExtraCompilerFlags().toString().isNotEmpty())
  317. s.add ("OTHER_CPLUSPLUSFLAGS = " + getExtraCompilerFlags().toString());
  318. switch ((int) project.getProjectType().getValue())
  319. {
  320. case Project::application:
  321. s.add ("INSTALL_PATH = \"$(HOME)/Applications\"");
  322. break;
  323. case Project::commandLineApp:
  324. break;
  325. case Project::audioPlugin:
  326. s.add ("LIBRARY_STYLE = Bundle");
  327. s.add ("INSTALL_PATH = \"$(HOME)/Library/Audio/Plug-Ins/Components/\"");
  328. s.add ("WRAPPER_EXTENSION = " + getAudioPluginBundleExtension());
  329. s.add ("GENERATE_PKGINFO_FILE = YES");
  330. s.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. s.add ("LIBRARY_STYLE = Bundle");
  336. s.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. s.add ("DSTROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  344. s.add ("SYMROOT = " + sanitisePath (binaryPath.toUnixStyle()));
  345. }
  346. s.add ("CONFIGURATION_BUILD_DIR = \"$(BUILD_DIR)\"");
  347. s.add ("DEPLOYMENT_LOCATION = YES");
  348. break;
  349. default:
  350. jassertfalse; break;
  351. }
  352. if (iPhone)
  353. {
  354. s.add ("SDKROOT = iphonesimulator3.0");
  355. }
  356. else
  357. {
  358. switch ((int) config.getMacSDKVersion().getValue())
  359. {
  360. case 2: s.add ("SDKROOT = macosx10.4"); s.add ("GCC_VERSION = 4.0"); break;
  361. case 3: s.add ("SDKROOT = macosx10.5"); break;
  362. case 4: s.add ("SDKROOT = macosx10.6"); break;
  363. default: break;
  364. }
  365. switch ((int) config.getMacCompatibilityVersion().getValue())
  366. {
  367. case 2: s.add ("MACOSX_DEPLOYMENT_TARGET = 10.4"); break;
  368. case 3: s.add ("MACOSX_DEPLOYMENT_TARGET = 10.5"); break;
  369. case 4: s.add ("MACOSX_DEPLOYMENT_TARGET = 10.6"); break;
  370. default: break;
  371. }
  372. s.add ("MACOSX_DEPLOYMENT_TARGET_ppc = 10.4");
  373. }
  374. {
  375. StringArray linkerFlags, librarySearchPaths;
  376. getLinkerFlags (config, linkerFlags, librarySearchPaths);
  377. if (linkerFlags.size() > 0)
  378. s.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. s.add (libPaths + ")");
  385. }
  386. }
  387. StringArray defines;
  388. if (config.isDebug().getValue())
  389. {
  390. defines.add ("_DEBUG=1");
  391. defines.add ("DEBUG=1 ");
  392. s.add ("ONLY_ACTIVE_ARCH = YES");
  393. s.add ("COPY_PHASE_STRIP = NO");
  394. s.add ("GCC_DYNAMIC_NO_PIC = NO");
  395. s.add ("GCC_ENABLE_FIX_AND_CONTINUE = YES");
  396. }
  397. else
  398. {
  399. defines.add ("_NDEBUG=1");
  400. defines.add ("NDEBUG=1 ");
  401. s.add ("GCC_GENERATE_DEBUGGING_SYMBOLS = NO");
  402. s.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. defines.addArray (parsePreprocessorDefs());
  412. for (int i = defines.size(); --i >= 0;)
  413. defines.set (i, defines[i].quoted());
  414. s.add ("GCC_PREPROCESSOR_DEFINITIONS = (" + indentList (defines, ",") + ")");
  415. }
  416. return s;
  417. }
  418. void addFrameworks()
  419. {
  420. StringArray s;
  421. if (iPhone)
  422. {
  423. s.addTokens ("UIKit Foundation CoreGraphics AudioToolbox QuartzCore OpenGLES", false);
  424. }
  425. else
  426. {
  427. s.addTokens ("Cocoa Carbon IOKit CoreAudio CoreMIDI WebKit DiscRecording OpenGL QuartzCore QTKit QuickTime", false);
  428. if (isAU())
  429. s.addTokens ("AudioUnit CoreAudioKit AudioToolbox", false);
  430. else if ((int) project.getJuceConfigFlag ("JUCE_PLUGINHOST_AU").getValue() == 1)
  431. s.addTokens ("AudioUnit CoreAudioKit", false);
  432. }
  433. for (int i = 0; i < s.size(); ++i)
  434. addFramework (s[i]);
  435. }
  436. //==============================================================================
  437. void writeProjectFile (OutputStream& output)
  438. {
  439. output << "// !$*UTF8*$!\n{\n"
  440. "\tarchiveVersion = 1;\n"
  441. "\tclasses = {\n\t};\n"
  442. "\tobjectVersion = 44;\n"
  443. "\tobjects = {\n\n";
  444. Array <ValueTree*> objects;
  445. objects.addArray (pbxBuildFiles);
  446. objects.addArray (pbxFileReferences);
  447. objects.addArray (groups);
  448. objects.addArray (targetConfigs);
  449. objects.addArray (projectConfigs);
  450. objects.addArray (misc);
  451. for (int i = 0; i < objects.size(); ++i)
  452. {
  453. ValueTree& o = *objects.getUnchecked(i);
  454. output << "\t\t" << o.getType() << " = { ";
  455. for (int j = 0; j < o.getNumProperties(); ++j)
  456. {
  457. const Identifier propertyName (o.getPropertyName(j));
  458. String val (o.getProperty (propertyName).toString());
  459. if (val.isEmpty() || (val.containsAnyOf (" \t;<>()=,-\r\n")
  460. && ! (val.trimStart().startsWithChar ('(')
  461. || val.trimStart().startsWithChar ('{'))))
  462. val = val.quoted();
  463. output << propertyName.toString() << " = " << val << "; ";
  464. }
  465. output << "};\n";
  466. }
  467. output << "\t};\n\trootObject = " << createID ("__root") << ";\n}\n";
  468. }
  469. static void addPlistDictionaryKey (XmlElement* xml, const String& key, const String& value)
  470. {
  471. xml->createNewChildElement ("key")->addTextElement (key);
  472. xml->createNewChildElement ("string")->addTextElement (value);
  473. }
  474. const String addBuildFile (const RelativePath& path, const String& fileRefID, bool addToSourceBuildPhase, bool inhibitWarnings)
  475. {
  476. String fileID (createID (path.toUnixStyle() + "buildref"));
  477. if (addToSourceBuildPhase)
  478. sourceIDs.add (fileID);
  479. ValueTree* v = new ValueTree (fileID);
  480. v->setProperty ("isa", "PBXBuildFile", 0);
  481. v->setProperty ("fileRef", fileRefID, 0);
  482. if (inhibitWarnings)
  483. v->setProperty ("settings", "{COMPILER_FLAGS = \"-w\"; }", 0);
  484. pbxBuildFiles.add (v);
  485. return fileID;
  486. }
  487. const String addBuildFile (const RelativePath& path, bool addToSourceBuildPhase, bool inhibitWarnings)
  488. {
  489. return addBuildFile (path, createID (path), addToSourceBuildPhase, inhibitWarnings);
  490. }
  491. void addFileReference (const RelativePath& path, const String& sourceTree, const String& lastKnownFileType, const String& fileRefID)
  492. {
  493. ValueTree* v = new ValueTree (fileRefID);
  494. v->setProperty ("isa", "PBXFileReference", 0);
  495. v->setProperty ("lastKnownFileType", lastKnownFileType, 0);
  496. v->setProperty ("name", path.getFileName(), 0);
  497. v->setProperty ("path", sanitisePath (path.toUnixStyle()), 0);
  498. v->setProperty ("sourceTree", sourceTree, 0);
  499. pbxFileReferences.add (v);
  500. }
  501. const String addFileReference (const RelativePath& path)
  502. {
  503. const String fileRefID (createID (path));
  504. jassert (path.isAbsolute() || path.getRoot() == RelativePath::buildTargetFolder);
  505. addFileReference (path, path.isAbsolute() ? "<absolute>" : "SOURCE_ROOT",
  506. getFileType (path), fileRefID);
  507. return fileRefID;
  508. }
  509. static const String getFileType (const RelativePath& file)
  510. {
  511. if (file.hasFileExtension (".cpp")) return "sourcecode.cpp.cpp";
  512. else if (file.hasFileExtension (".mm")) return "sourcecode.cpp.objcpp";
  513. else if (file.hasFileExtension (".m")) return "sourcecode.c.objc";
  514. else if (file.hasFileExtension (".h;.hpp")) return "sourcecode.c.h";
  515. else if (file.hasFileExtension (".framework")) return "wrapper.framework";
  516. else if (file.hasFileExtension (".jpeg;.jpg")) return "image.jpeg";
  517. else if (file.hasFileExtension ("png;gif")) return "image" + file.getFileExtension();
  518. else if (file.hasFileExtension ("html;htm")) return "text.html";
  519. else if (file.hasFileExtension ("txt;rtf")) return "text" + file.getFileExtension();
  520. else if (file.hasFileExtension ("plist")) return "text.plist.xml";
  521. else if (file.hasFileExtension ("app")) return "wrapper.application";
  522. else if (file.hasFileExtension ("component;vst;plugin")) return "wrapper.cfbundle";
  523. else if (file.hasFileExtension ("xcodeproj")) return "wrapper.pb-project";
  524. else if (file.hasFileExtension ("a")) return "archive.ar";
  525. return "file" + file.getFileExtension();
  526. }
  527. const String addFile (const RelativePath& path, bool shouldBeCompiled, bool inhibitWarnings)
  528. {
  529. if (shouldBeCompiled)
  530. addBuildFile (path, true, inhibitWarnings);
  531. else if (path.hasFileExtension (".r"))
  532. rezFileIDs.add (addBuildFile (path, false, inhibitWarnings));
  533. return addFileReference (path);
  534. }
  535. const String addProjectItem (const Project::Item& projectItem)
  536. {
  537. if (projectItem.isGroup())
  538. {
  539. StringArray childIDs;
  540. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  541. {
  542. const String childID (addProjectItem (projectItem.getChild(i)));
  543. if (childID.isNotEmpty())
  544. childIDs.add (childID);
  545. }
  546. return addGroup (projectItem, childIDs);
  547. }
  548. else
  549. {
  550. if (projectItem.shouldBeAddedToTargetProject())
  551. {
  552. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  553. return addFile (path, projectItem.shouldBeCompiled(), false);
  554. }
  555. }
  556. return String::empty;
  557. }
  558. void addFramework (const String& frameworkName)
  559. {
  560. const RelativePath path ("System/Library/Frameworks/" + frameworkName + ".framework", RelativePath::unknown);
  561. const String fileRefID (createID (path));
  562. addFileReference (path, "SDKROOT", getFileType (path), fileRefID);
  563. frameworkIDs.add (addBuildFile (path, fileRefID, false, false));
  564. frameworkFileIDs.add (fileRefID);
  565. }
  566. void addGroup (const String& groupID, const String& groupName, const StringArray& childIDs)
  567. {
  568. ValueTree* v = new ValueTree (groupID);
  569. v->setProperty ("isa", "PBXGroup", 0);
  570. v->setProperty ("children", "(" + indentList (childIDs, ",") + " )", 0);
  571. v->setProperty ("name", groupName, 0);
  572. v->setProperty ("sourceTree", "<group>", 0);
  573. groups.add (v);
  574. }
  575. const String createGroup (const Array<RelativePath>& files, const String& groupName, const String& groupIDName, bool inhibitWarnings)
  576. {
  577. StringArray fileIDs;
  578. for (int i = 0; i < files.size(); ++i)
  579. {
  580. addFile (files.getReference(i), shouldFileBeCompiledByDefault (files.getReference(i)), inhibitWarnings);
  581. fileIDs.add (createID (files.getReference(i)));
  582. }
  583. const String groupID (createID (groupIDName));
  584. addGroup (groupID, groupName, fileIDs);
  585. return groupID;
  586. }
  587. const String addGroup (const Project::Item& item, StringArray& childIDs)
  588. {
  589. String groupName (item.getName().toString());
  590. if (item.isMainGroup())
  591. {
  592. groupName = "Source";
  593. // Add 'Juce Library Code' group
  594. if (juceWrapperFiles.size() > 0)
  595. childIDs.add (createGroup (juceWrapperFiles, project.getJuceCodeGroupName(), "__jucelibfiles", false));
  596. if (isVST())
  597. childIDs.add (createGroup (getVSTFilesRequired(), "Juce VST Wrapper", "__jucevstfiles", false));
  598. if (isAU())
  599. childIDs.add (createAUWrappersGroup());
  600. if (isRTAS())
  601. childIDs.add (createGroup (getRTASFilesRequired(), "Juce RTAS Wrapper", "__jucertasfiles", true));
  602. { // Add 'resources' group
  603. String resourcesGroupID (createID ("__resources"));
  604. addGroup (resourcesGroupID, "Resources", resourceFileRefs);
  605. childIDs.add (resourcesGroupID);
  606. }
  607. { // Add 'frameworks' group
  608. String frameworksGroupID (createID ("__frameworks"));
  609. addGroup (frameworksGroupID, "Frameworks", frameworkFileIDs);
  610. childIDs.add (frameworksGroupID);
  611. }
  612. { // Add 'products' group
  613. String productsGroupID (createID ("__products"));
  614. StringArray products;
  615. products.add (createID ("__productFileID"));
  616. addGroup (productsGroupID, "Products", products);
  617. childIDs.add (productsGroupID);
  618. }
  619. }
  620. String groupID (getIDForGroup (item));
  621. addGroup (groupID, groupName, childIDs);
  622. return groupID;
  623. }
  624. void addBuildProduct (const String& fileType, const String& binaryName)
  625. {
  626. ValueTree* v = new ValueTree (createID ("__productFileID"));
  627. v->setProperty ("isa", "PBXFileReference", 0);
  628. v->setProperty ("explicitFileType", fileType, 0);
  629. v->setProperty ("includeInIndex", (int) 0, 0);
  630. v->setProperty ("path", sanitisePath (binaryName), 0);
  631. v->setProperty ("sourceTree", "BUILT_PRODUCTS_DIR", 0);
  632. pbxFileReferences.add (v);
  633. }
  634. void addTargetConfig (const String& configName, const StringArray& buildSettings)
  635. {
  636. ValueTree* v = new ValueTree (createID ("targetconfigid_" + configName));
  637. v->setProperty ("isa", "XCBuildConfiguration", 0);
  638. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  639. v->setProperty ("name", configName, 0);
  640. targetConfigs.add (v);
  641. }
  642. void addProjectConfig (const String& configName, const StringArray& buildSettings)
  643. {
  644. ValueTree* v = new ValueTree (createID ("projectconfigid_" + configName));
  645. v->setProperty ("isa", "XCBuildConfiguration", 0);
  646. v->setProperty ("buildSettings", "{" + indentList (buildSettings, ";") + " }", 0);
  647. v->setProperty ("name", configName, 0);
  648. projectConfigs.add (v);
  649. }
  650. void addConfigList (const OwnedArray <ValueTree>& configsToUse, const String& listID)
  651. {
  652. StringArray configIDs;
  653. for (int i = 0; i < configsToUse.size(); ++i)
  654. configIDs.add (configsToUse[i]->getType());
  655. ValueTree* v = new ValueTree (listID);
  656. v->setProperty ("isa", "XCConfigurationList", 0);
  657. v->setProperty ("buildConfigurations", "(" + indentList (configIDs, ",") + " )", 0);
  658. v->setProperty ("defaultConfigurationIsVisible", (int) 0, 0);
  659. if (configsToUse[0] != 0)
  660. v->setProperty ("defaultConfigurationName", configsToUse[0]->getProperty ("name"), 0);
  661. misc.add (v);
  662. }
  663. ValueTree* addBuildPhase (const String& phaseType, const StringArray& fileIds)
  664. {
  665. String phaseId (createID (phaseType + "resbuildphase"));
  666. buildPhaseIDs.add (phaseId);
  667. ValueTree* v = new ValueTree (phaseId);
  668. v->setProperty ("isa", phaseType, 0);
  669. v->setProperty ("buildActionMask", "2147483647", 0);
  670. v->setProperty ("files", "(" + indentList (fileIds, ",") + " )", 0);
  671. v->setProperty ("runOnlyForDeploymentPostprocessing", (int) 0, 0);
  672. misc.add (v);
  673. return v;
  674. }
  675. void addTargetObject()
  676. {
  677. ValueTree* v = new ValueTree (createID ("__target"));
  678. v->setProperty ("isa", "PBXNativeTarget", 0);
  679. v->setProperty ("buildConfigurationList", createID ("__configList"), 0);
  680. v->setProperty ("buildPhases", "(" + indentList (buildPhaseIDs, ",") + " )", 0);
  681. v->setProperty ("buildRules", "( )", 0);
  682. v->setProperty ("dependencies", "( )", 0);
  683. v->setProperty ("name", project.getDocumentTitle(), 0);
  684. v->setProperty ("productName", project.getDocumentTitle(), 0);
  685. v->setProperty ("productReference", createID ("__productFileID"), 0);
  686. if (project.isGUIApplication())
  687. {
  688. v->setProperty ("productInstallPath", "$(HOME)/Applications", 0);
  689. v->setProperty ("productType", "com.apple.product-type.application", 0);
  690. }
  691. else if (project.isCommandLineApp())
  692. {
  693. v->setProperty ("productInstallPath", "/usr/bin", 0);
  694. v->setProperty ("productType", "com.apple.product-type.tool", 0);
  695. }
  696. else if (project.isAudioPlugin() || project.isBrowserPlugin())
  697. {
  698. v->setProperty ("productInstallPath", "$(HOME)/Library/Audio/Plug-Ins/Components/", 0);
  699. v->setProperty ("productType", "com.apple.product-type.bundle", 0);
  700. }
  701. else if (project.isLibrary())
  702. {
  703. v->setProperty ("productType", "com.apple.product-type.library.static", 0);
  704. }
  705. else
  706. jassertfalse; //xxx
  707. misc.add (v);
  708. }
  709. void addProjectObject()
  710. {
  711. ValueTree* v = new ValueTree (createID ("__root"));
  712. v->setProperty ("isa", "PBXProject", 0);
  713. v->setProperty ("buildConfigurationList", createID ("__projList"), 0);
  714. v->setProperty ("compatibilityVersion", "Xcode 3.0", 0);
  715. v->setProperty ("hasScannedForEncodings", (int) 0, 0);
  716. v->setProperty ("mainGroup", getIDForGroup (project.getMainGroup()), 0);
  717. v->setProperty ("projectDirPath", "\"\"", 0);
  718. v->setProperty ("projectRoot", "\"\"", 0);
  719. v->setProperty ("targets", "( " + createID ("__target") + " )", 0);
  720. misc.add (v);
  721. }
  722. void addPluginShellScriptPhase()
  723. {
  724. ValueTree* v = addBuildPhase ("PBXShellScriptBuildPhase", StringArray());
  725. v->setProperty ("name", "Copy to the different plugin folders", 0);
  726. v->setProperty ("shellPath", "/bin/sh", 0);
  727. v->setProperty ("shellScript", String::fromUTF8 (BinaryData::AudioPluginXCodeScript_txt, BinaryData::AudioPluginXCodeScript_txtSize)
  728. .replace ("\\", "\\\\")
  729. .replace ("\"", "\\\"")
  730. .replace ("\r\n", "\\n")
  731. .replace ("\n", "\\n"), 0);
  732. }
  733. //==============================================================================
  734. static const String indentList (const StringArray& list, const String& separator)
  735. {
  736. if (list.size() == 0)
  737. return " ";
  738. return "\n\t\t\t\t" + list.joinIntoString (separator + "\n\t\t\t\t")
  739. + (separator == ";" ? separator : String::empty);
  740. }
  741. const String createID (const RelativePath& path) const
  742. {
  743. return createID (path.toUnixStyle());
  744. }
  745. const String createID (const String& rootString) const
  746. {
  747. static const char digits[] = "0123456789ABCDEF";
  748. char n[24];
  749. Random ran (projectIDSalt + hashCode64 (rootString));
  750. for (int i = 0; i < numElementsInArray (n); ++i)
  751. n[i] = digits [ran.nextInt (16)];
  752. return String (n, numElementsInArray (n));
  753. }
  754. const String getIDForGroup (const Project::Item& item) const
  755. {
  756. return createID (item.getID());
  757. }
  758. bool shouldFileBeCompiledByDefault (const RelativePath& file) const
  759. {
  760. return file.hasFileExtension ("cpp;mm;c;m");
  761. }
  762. //==============================================================================
  763. const Array<RelativePath> getRTASFilesRequired() const
  764. {
  765. Array<RelativePath> s;
  766. if (isRTAS())
  767. {
  768. const char* files[] = { "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode1.cpp",
  769. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode2.cpp",
  770. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode3.cpp",
  771. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode_Header.h",
  772. "extras/audio plugins/wrapper/RTAS/juce_RTAS_MacResources.r",
  773. "extras/audio plugins/wrapper/RTAS/juce_RTAS_MacUtilities.mm",
  774. "extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp" };
  775. for (int i = 0; i < numElementsInArray (files); ++i)
  776. s.add (getJucePathFromTargetFolder().getChildFile (files[i]));
  777. }
  778. return s;
  779. }
  780. const String createAUWrappersGroup()
  781. {
  782. Array<RelativePath> auWrappers;
  783. const char* files[] = { "extras/audio plugins/wrapper/AU/juce_AU_Resources.r",
  784. "extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm" };
  785. int i;
  786. for (i = 0; i < numElementsInArray (files); ++i)
  787. auWrappers.add (getJucePathFromTargetFolder().getChildFile (files[i]));
  788. const char* appleAUFiles[] = { "Extras/CoreAudio/PublicUtility/CADebugMacros.h",
  789. "Extras/CoreAudio/PublicUtility/CAAUParameter.cpp",
  790. "Extras/CoreAudio/PublicUtility/CAAUParameter.h",
  791. "Extras/CoreAudio/PublicUtility/CAAudioChannelLayout.cpp",
  792. "Extras/CoreAudio/PublicUtility/CAAudioChannelLayout.h",
  793. "Extras/CoreAudio/PublicUtility/CAMutex.cpp",
  794. "Extras/CoreAudio/PublicUtility/CAMutex.h",
  795. "Extras/CoreAudio/PublicUtility/CAStreamBasicDescription.cpp",
  796. "Extras/CoreAudio/PublicUtility/CAStreamBasicDescription.h",
  797. "Extras/CoreAudio/PublicUtility/CAVectorUnitTypes.h",
  798. "Extras/CoreAudio/PublicUtility/CAVectorUnit.cpp",
  799. "Extras/CoreAudio/PublicUtility/CAVectorUnit.h",
  800. "Extras/CoreAudio/AudioUnits/AUPublic/AUViewBase/AUViewLocalizedStringKeys.h",
  801. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewDispatch.cpp",
  802. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewControl.cpp",
  803. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewControl.h",
  804. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/CarbonEventHandler.cpp",
  805. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/CarbonEventHandler.h",
  806. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewBase.cpp",
  807. "Extras/CoreAudio/AudioUnits/AUPublic/AUCarbonViewBase/AUCarbonViewBase.h",
  808. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUBase.cpp",
  809. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUBase.h",
  810. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUDispatch.cpp",
  811. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUDispatch.h",
  812. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUInputElement.cpp",
  813. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUInputElement.h",
  814. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUOutputElement.cpp",
  815. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUOutputElement.h",
  816. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUResources.r",
  817. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUScopeElement.cpp",
  818. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/AUScopeElement.h",
  819. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/ComponentBase.cpp",
  820. "Extras/CoreAudio/AudioUnits/AUPublic/AUBase/ComponentBase.h",
  821. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIBase.cpp",
  822. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIBase.h",
  823. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIEffectBase.cpp",
  824. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUMIDIEffectBase.h",
  825. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUOutputBase.cpp",
  826. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUOutputBase.h",
  827. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/MusicDeviceBase.cpp",
  828. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/MusicDeviceBase.h",
  829. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUEffectBase.cpp",
  830. "Extras/CoreAudio/AudioUnits/AUPublic/OtherBases/AUEffectBase.h",
  831. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUBuffer.cpp",
  832. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUBuffer.h",
  833. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUDebugDispatcher.cpp",
  834. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUDebugDispatcher.h",
  835. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUInputFormatConverter.h",
  836. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUSilentTimeout.h",
  837. "Extras/CoreAudio/AudioUnits/AUPublic/Utility/AUTimestampGenerator.h" };
  838. StringArray fileIDs, appleFileIDs;
  839. for (i = 0; i < auWrappers.size(); ++i)
  840. {
  841. addFile (auWrappers.getReference(i), shouldFileBeCompiledByDefault (auWrappers.getReference(i)), false);
  842. fileIDs.add (createID (auWrappers.getReference(i)));
  843. }
  844. for (i = 0; i < numElementsInArray (appleAUFiles); ++i)
  845. {
  846. RelativePath file (appleAUFiles[i], RelativePath::unknown);
  847. const String fileRefID (createID (file));
  848. addFileReference (file, "DEVELOPER_DIR", getFileType (file), fileRefID);
  849. if (shouldFileBeCompiledByDefault (file))
  850. addBuildFile (file, fileRefID, true, true);
  851. appleFileIDs.add (fileRefID);
  852. }
  853. const String appleGroupID (createID ("__juceappleaufiles"));
  854. addGroup (appleGroupID, "Apple AU Files", appleFileIDs);
  855. fileIDs.add (appleGroupID);
  856. const String groupID (createID ("__juceaufiles"));
  857. addGroup (groupID, "Juce AU Wrapper", fileIDs);
  858. return groupID;
  859. }
  860. };
  861. #endif // __JUCER_PROJECTEXPORT_XCODE_JUCEHEADER__