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.

1017 lines
46KB

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