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.

1047 lines
47KB

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