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.

932 lines
34KB

  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. #include "jucer_Project.h"
  19. #include "jucer_ProjectExporter.h"
  20. #include "jucer_ResourceFile.h"
  21. #include "jucer_ProjectSaver.h"
  22. #include "../ui/jucer_OpenDocumentManager.h"
  23. //==============================================================================
  24. namespace Tags
  25. {
  26. const char* const projectRoot = "JUCERPROJECT";
  27. const char* const projectMainGroup = "MAINGROUP";
  28. const char* const group = "GROUP";
  29. const char* const file = "FILE";
  30. const char* const configurations = "CONFIGURATIONS";
  31. const char* const configuration = "CONFIGURATION";
  32. const char* const exporters = "EXPORTFORMATS";
  33. }
  34. const char* Project::projectFileExtension = ".jucer";
  35. //==============================================================================
  36. Project::Project (const File& file_)
  37. : FileBasedDocument (projectFileExtension,
  38. String ("*") + projectFileExtension,
  39. "Choose a Jucer project to load",
  40. "Save Jucer project"),
  41. projectRoot (Tags::projectRoot)
  42. {
  43. setFile (file_);
  44. setMissingDefaultValues();
  45. setChangedFlag (false);
  46. projectRoot.addListener (this);
  47. }
  48. Project::~Project()
  49. {
  50. projectRoot.removeListener (this);
  51. OpenDocumentManager::getInstance()->closeAllDocumentsUsingProject (*this, false);
  52. }
  53. //==============================================================================
  54. void Project::setTitle (const String& newTitle)
  55. {
  56. projectRoot.setProperty ("name", newTitle, getUndoManagerFor (projectRoot));
  57. getMainGroup().getName() = newTitle;
  58. }
  59. const String Project::getDocumentTitle()
  60. {
  61. return getProjectName().toString();
  62. }
  63. void Project::updateProjectSettings()
  64. {
  65. projectRoot.setProperty ("jucerVersion", ProjectInfo::versionString, 0);
  66. projectRoot.setProperty ("name", getDocumentTitle(), 0);
  67. }
  68. void Project::setMissingDefaultValues()
  69. {
  70. if (! projectRoot.hasProperty ("id"))
  71. projectRoot.setProperty ("id", createAlphaNumericUID(), 0);
  72. // Create main file group if missing
  73. if (! projectRoot.getChildWithName (Tags::projectMainGroup).isValid())
  74. {
  75. Item mainGroup (*this, ValueTree (Tags::projectMainGroup));
  76. mainGroup.createUIDIfMissing();
  77. projectRoot.addChild (mainGroup.getNode(), 0, 0);
  78. }
  79. if (getDocumentTitle().isEmpty())
  80. setTitle ("Juce Project");
  81. if (! projectRoot.hasProperty ("projectType"))
  82. getProjectType() = (int) application;
  83. if (! projectRoot.hasProperty ("version"))
  84. getVersion() = "1.0.0";
  85. if (! projectRoot.hasProperty ("juceLinkage"))
  86. getJuceLinkageModeValue() = (int) useAmalgamatedJuceViaMultipleTemplates;
  87. const String juceFolderPath (getRelativePathForFile (StoredSettings::getInstance()->getLastKnownJuceFolder()));
  88. // Create configs group
  89. if (! projectRoot.getChildWithName (Tags::configurations).isValid())
  90. {
  91. projectRoot.addChild (ValueTree (Tags::configurations), 0, 0);
  92. createDefaultConfigs();
  93. }
  94. if (! projectRoot.getChildWithName (Tags::exporters).isValid())
  95. createDefaultExporters();
  96. const String sanitisedProjectName (makeValidCppIdentifier (getProjectName().toString(), false, true, false));
  97. if (! projectRoot.hasProperty ("buildVST"))
  98. {
  99. shouldBuildVST() = true;
  100. shouldBuildRTAS() = false;
  101. shouldBuildAU() = true;
  102. getPluginName() = getProjectName().toString();
  103. getPluginDesc() = getProjectName().toString();
  104. getPluginManufacturer() = "yourcompany";
  105. getPluginManufacturerCode() = "abcd";
  106. getPluginCode() = "Abcd";
  107. getPluginChannelConfigs() = "{1, 1}, {2, 2}";
  108. getPluginIsSynth() = false;
  109. getPluginWantsMidiInput() = false;
  110. getPluginProducesMidiOut() = false;
  111. getPluginSilenceInProducesSilenceOut() = false;
  112. getPluginTailLengthSeconds() = 0;
  113. getPluginEditorNeedsKeyFocus() = false;
  114. getPluginAUExportPrefix() = sanitisedProjectName + "AU";
  115. getPluginAUCocoaViewClassName() = sanitisedProjectName + "AU_V1";
  116. getPluginRTASCategory() = String::empty;
  117. }
  118. if (! projectRoot.hasProperty ("bundleIdentifier"))
  119. setBundleIdentifierToDefault();
  120. }
  121. //==============================================================================
  122. const String Project::loadDocument (const File& file)
  123. {
  124. XmlDocument doc (file);
  125. ScopedPointer <XmlElement> xml (doc.getDocumentElement());
  126. if (xml == 0 || ! xml->hasTagName (Tags::projectRoot))
  127. return "Not a valid Jucer project!";
  128. ValueTree newTree (ValueTree::fromXml (*xml));
  129. if (! newTree.hasType (Tags::projectRoot))
  130. return "The document contains errors and couldn't be parsed!";
  131. StoredSettings::getInstance()->recentFiles.addFile (file);
  132. StoredSettings::getInstance()->flush();
  133. projectRoot = newTree;
  134. setMissingDefaultValues();
  135. return String::empty;
  136. }
  137. const String Project::saveDocument (const File& file)
  138. {
  139. updateProjectSettings();
  140. {
  141. // (getting these forces the values to be sanitised)
  142. OwnedArray <Project::JuceConfigFlag> flags;
  143. getJuceConfigFlags (flags);
  144. }
  145. if (isJuceFolder (getLocalJuceFolder()))
  146. StoredSettings::getInstance()->setLastKnownJuceFolder (getLocalJuceFolder().getFullPathName());
  147. StoredSettings::getInstance()->recentFiles.addFile (file);
  148. ProjectSaver saver (*this, file);
  149. return saver.save();
  150. }
  151. //==============================================================================
  152. File Project::lastDocumentOpened;
  153. const File Project::getLastDocumentOpened()
  154. {
  155. return lastDocumentOpened;
  156. }
  157. void Project::setLastDocumentOpened (const File& file)
  158. {
  159. lastDocumentOpened = file;
  160. }
  161. //==============================================================================
  162. void Project::valueTreePropertyChanged (ValueTree& tree, const var::identifier& property)
  163. {
  164. if (isLibrary())
  165. getJuceLinkageModeValue() = (int) notLinkedToJuce;
  166. changed();
  167. }
  168. void Project::valueTreeChildrenChanged (ValueTree& tree)
  169. {
  170. changed();
  171. }
  172. void Project::valueTreeParentChanged (ValueTree& tree)
  173. {
  174. }
  175. //==============================================================================
  176. const File Project::resolveFilename (const String& filename) const
  177. {
  178. if (filename.isEmpty())
  179. return File::nonexistent;
  180. if (File::isAbsolutePath (filename))
  181. return File (filename);
  182. return getFile().getSiblingFile (filename);
  183. }
  184. const String Project::getRelativePathForFile (const File& file) const
  185. {
  186. String filename (file.getFullPathName());
  187. File relativePathBase (getFile().getParentDirectory());
  188. String p1 (relativePathBase.getFullPathName());
  189. String p2 (file.getFullPathName());
  190. while (p1.startsWithChar (File::separator))
  191. p1 = p1.substring (1);
  192. while (p2.startsWithChar (File::separator))
  193. p2 = p2.substring (1);
  194. if (p1.upToFirstOccurrenceOf (File::separatorString, true, false)
  195. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::separatorString, true, false)))
  196. {
  197. filename = file.getRelativePathFrom (relativePathBase);
  198. }
  199. return filename;
  200. }
  201. //==============================================================================
  202. bool Project::shouldBeAddedToBinaryResourcesByDefault (const File& file)
  203. {
  204. return ! file.hasFileExtension (sourceFileExtensions);
  205. }
  206. Value Project::getProjectType() const
  207. {
  208. static const char* mappings[] = { "guiapp", "1", "consoleapp", "2", "audioplug", "3", "library", "4", "browserplug", "5", 0 };
  209. return Value (new ValueRemapperSource (projectRoot.getPropertyAsValue ("projectType", getUndoManagerFor (projectRoot)), mappings));
  210. }
  211. const StringArray Project::getProjectTypes() const
  212. {
  213. const char* types[] = { "Application (GUI)",
  214. "Application (Non-GUI)",
  215. "Audio Plug-in",
  216. //"Browser Plug-in",
  217. "Static Library",
  218. 0 };
  219. return StringArray (types);
  220. }
  221. Value Project::getJuceLinkageModeValue() const
  222. {
  223. static const char* mappings[] = { "none", "1", "static", "2", "amalg_big", "3", "amalg_template", "4", "amalg_multi", "5", 0 };
  224. return Value (new ValueRemapperSource (projectRoot.getPropertyAsValue ("juceLinkage", getUndoManagerFor (projectRoot)), mappings));
  225. }
  226. const StringArray Project::getJuceLinkageModes() const
  227. {
  228. const char* types[] = { "Not linked to Juce",
  229. "Linked to Juce Static Library",
  230. "Include Juce Amalgamated Files",
  231. "Include Juce Source Code Directly (In a single file)",
  232. "Include Juce Source Code Directly (Split across several files)",
  233. 0 };
  234. return StringArray (types);
  235. }
  236. const File Project::getLocalJuceFolder()
  237. {
  238. ScopedPointer <ProjectExporter> exp (ProjectExporter::createPlatformDefaultExporter (*this));
  239. if (exp != 0)
  240. {
  241. File f (resolveFilename (exp->getJuceFolder().toString()));
  242. if (isJuceFolder (f))
  243. return f;
  244. }
  245. return StoredSettings::getInstance()->getLastKnownJuceFolder();
  246. }
  247. //==============================================================================
  248. void Project::createPropertyEditors (Array <PropertyComponent*>& props)
  249. {
  250. props.add (new TextPropertyComponent (getProjectName(), "Project Name", 256, false));
  251. props.getLast()->setTooltip ("The name of the project.");
  252. props.add (new TextPropertyComponent (getVersion(), "Project Version", 16, false));
  253. props.getLast()->setTooltip ("The project's version number, This should be in the format major.minor.point");
  254. props.add (new ChoicePropertyComponent (getProjectType(), "Project Type", getProjectTypes()));
  255. props.add (new ChoicePropertyComponent (getJuceLinkageModeValue(), "Juce Linkage Method", getJuceLinkageModes()));
  256. props.getLast()->setTooltip ("The method by which your project will be linked to Juce.");
  257. props.add (new TextPropertyComponent (getBundleIdentifier(), "Bundle Identifier", 256, false));
  258. props.getLast()->setTooltip ("A unique identifier for this product, mainly for use in Mac builds. It should be something like 'com.yourcompanyname.yourproductname'");
  259. if (isAudioPlugin())
  260. {
  261. props.add (new BooleanPropertyComponent (shouldBuildVST(), "Build VST", "Enabled"));
  262. props.getLast()->setTooltip ("Whether the project should produce a VST plugin.");
  263. props.add (new BooleanPropertyComponent (shouldBuildAU(), "Build AudioUnit", "Enabled"));
  264. props.getLast()->setTooltip ("Whether the project should produce an AudioUnit plugin.");
  265. props.add (new BooleanPropertyComponent (shouldBuildRTAS(), "Build RTAS", "Enabled"));
  266. props.getLast()->setTooltip ("Whether the project should produce an RTAS plugin.");
  267. }
  268. if (isAudioPlugin())
  269. {
  270. props.add (new TextPropertyComponent (getPluginName(), "Plugin Name", 128, false));
  271. props.getLast()->setTooltip ("The name of your plugin (keep it short!)");
  272. props.add (new TextPropertyComponent (getPluginDesc(), "Plugin Description", 256, false));
  273. props.getLast()->setTooltip ("A short description of your plugin.");
  274. props.add (new TextPropertyComponent (getPluginManufacturer(), "Plugin Manufacturer", 256, false));
  275. props.getLast()->setTooltip ("The name of your company (cannot be blank).");
  276. props.add (new TextPropertyComponent (getPluginManufacturerCode(), "Plugin Manufacturer Code", 4, false));
  277. props.getLast()->setTooltip ("A four-character unique ID for your company.");
  278. props.add (new TextPropertyComponent (getPluginCode(), "Plugin Code", 4, false));
  279. props.getLast()->setTooltip ("A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  280. props.add (new TextPropertyComponent (getPluginChannelConfigs(), "Plugin Channel Configurations", 256, false));
  281. props.getLast()->setTooltip ("This is the set of input/output channel configurations that your plugin can handle. The list is a comma-separated set of pairs of values in the form { numInputs, numOutputs }, and each "
  282. "pair indicates a valid configuration that the plugin can handle. So for example, {1, 1}, {2, 2} means that the plugin can be used in just two configurations: either with 1 input "
  283. "and 1 output, or with 2 inputs and 2 outputs.");
  284. props.add (new BooleanPropertyComponent (getPluginIsSynth(), "Plugin is a Synth", "Is a Synth"));
  285. props.getLast()->setTooltip ("Enable this if you want your plugin to be treated as a synth or generator. It doesn't make much difference to the plugin itself, but some hosts treat synths differently to other plugins.");
  286. props.add (new BooleanPropertyComponent (getPluginWantsMidiInput(), "Plugin Midi Input", "Plugin wants midi input"));
  287. props.getLast()->setTooltip ("Enable this if you want your plugin to accept midi messages.");
  288. props.add (new BooleanPropertyComponent (getPluginProducesMidiOut(), "Plugin Midi Output", "Plugin produces midi output"));
  289. props.getLast()->setTooltip ("Enable this if your plugin is going to produce midi messages.");
  290. props.add (new BooleanPropertyComponent (getPluginSilenceInProducesSilenceOut(), "Silence", "Silence in produces silence out"));
  291. props.getLast()->setTooltip ("Enable this if your plugin has no tail - i.e. if passing a silent buffer to it will always result in a silent buffer being produced.");
  292. props.add (new TextPropertyComponent (getPluginTailLengthSeconds(), "Tail Length (in seconds)", 12, false));
  293. props.getLast()->setTooltip ("This indicates the length, in seconds, of the plugin's tail. This information may or may not be used by the host.");
  294. props.add (new BooleanPropertyComponent (getPluginEditorNeedsKeyFocus(), "Key Focus", "Plugin editor requires keyboard focus"));
  295. props.getLast()->setTooltip ("Enable this if your plugin needs keyboard input - some hosts can be a bit funny about keyboard focus..");
  296. props.add (new TextPropertyComponent (getPluginAUExportPrefix(), "Plugin AU Export Prefix", 64, false));
  297. props.getLast()->setTooltip ("A prefix for the names of exported entry-point functions that the component exposes - typically this will be a version of your plugin's name that can be used as part of a C++ token.");
  298. props.add (new TextPropertyComponent (getPluginAUCocoaViewClassName(), "Plugin AU Cocoa View Name", 64, false));
  299. props.getLast()->setTooltip ("In an AU, this is the name of Cocoa class that creates the UI. Some hosts bizarrely display the class-name, so you might want to make it reflect your plugin. But the name must be "
  300. "UNIQUE to this exact version of your plugin, to avoid objective-C linkage mix-ups that happen when different plugins containing the same class-name are loaded simultaneously.");
  301. props.add (new TextPropertyComponent (getPluginRTASCategory(), "Plugin RTAS Category", 64, false));
  302. props.getLast()->setTooltip ("(Leave this blank if your plugin is a synth). This is one of the RTAS categories from FicPluginEnums.h, such as: ePlugInCategory_None, ePlugInCategory_EQ, ePlugInCategory_Dynamics, "
  303. "ePlugInCategory_PitchShift, ePlugInCategory_Reverb, ePlugInCategory_Delay, "
  304. "ePlugInCategory_Modulation, ePlugInCategory_Harmonic, ePlugInCategory_NoiseReduction, "
  305. "ePlugInCategory_Dither, ePlugInCategory_SoundField");
  306. }
  307. for (int i = props.size(); --i >= 0;)
  308. props.getUnchecked(i)->setPreferredHeight (22);
  309. }
  310. //==============================================================================
  311. Project::Item Project::getMainGroup()
  312. {
  313. return Item (*this, projectRoot.getChildWithName (Tags::projectMainGroup));
  314. }
  315. Project::Item Project::createNewGroup()
  316. {
  317. Item item (*this, ValueTree (Tags::group));
  318. item.createUIDIfMissing();
  319. item.getName() = "New Group";
  320. return item;
  321. }
  322. Project::Item Project::createNewItem (const File& file)
  323. {
  324. Item item (*this, ValueTree (Tags::file));
  325. item.createUIDIfMissing();
  326. item.getName() = file.getFileName();
  327. item.getShouldCompileValue() = file.hasFileExtension ("cpp;mm;c;m");
  328. item.getShouldAddToResourceValue() = shouldBeAddedToBinaryResourcesByDefault (file);
  329. return item;
  330. }
  331. //==============================================================================
  332. Project::Item::Item (Project& project_, const ValueTree& node_)
  333. : project (project_), node (node_)
  334. {
  335. }
  336. Project::Item::Item (const Item& other)
  337. : project (other.project), node (other.node)
  338. {
  339. }
  340. Project::Item::~Item()
  341. {
  342. }
  343. const String Project::Item::getID() const { return node ["id"]; }
  344. bool Project::Item::isFile() const { return node.hasType (Tags::file); }
  345. bool Project::Item::isGroup() const { return node.hasType (Tags::group) || isMainGroup(); }
  346. bool Project::Item::isMainGroup() const { return node.hasType (Tags::projectMainGroup); }
  347. bool Project::Item::canContain (const Item& child) const
  348. {
  349. if (isFile())
  350. return false;
  351. if (isGroup())
  352. return child.isFile() || child.isGroup();
  353. jassertfalse
  354. return false;
  355. }
  356. bool Project::Item::shouldBeAddedToTargetProject() const
  357. {
  358. return isFile();
  359. }
  360. bool Project::Item::shouldBeCompiled() const
  361. {
  362. return getShouldCompileValue().getValue();
  363. }
  364. Value Project::Item::getShouldCompileValue() const
  365. {
  366. return node.getPropertyAsValue ("compile", getUndoManager());
  367. }
  368. bool Project::Item::shouldBeAddedToBinaryResources() const
  369. {
  370. return getShouldAddToResourceValue().getValue();
  371. }
  372. Value Project::Item::getShouldAddToResourceValue() const
  373. {
  374. return node.getPropertyAsValue ("resource", getUndoManager());
  375. }
  376. const File Project::Item::getFile() const
  377. {
  378. if (isFile())
  379. return project.resolveFilename (node ["file"].toString());
  380. else
  381. return File::nonexistent;
  382. }
  383. void Project::Item::setFile (const File& file)
  384. {
  385. node.setProperty ("file", project.getRelativePathForFile (file), getUndoManager());
  386. jassert (getFile() == file);
  387. }
  388. const File Project::Item::determineGroupFolder() const
  389. {
  390. jassert (isGroup());
  391. File f;
  392. for (int i = 0; i < getNumChildren(); ++i)
  393. {
  394. f = getChild(i).getFile();
  395. if (f.exists())
  396. return f.getParentDirectory();
  397. }
  398. Item parent (getParent());
  399. if (parent != *this)
  400. {
  401. f = parent.determineGroupFolder();
  402. if (f.getChildFile (getName().toString()).isDirectory())
  403. f = f.getChildFile (getName().toString());
  404. }
  405. else
  406. {
  407. f = project.getFile().getParentDirectory();
  408. if (f.getChildFile ("Source").isDirectory())
  409. f = f.getChildFile ("Source");
  410. }
  411. return f;
  412. }
  413. void Project::Item::createUIDIfMissing()
  414. {
  415. if (! node.hasProperty ("id"))
  416. node.setProperty ("id", createAlphaNumericUID(), getUndoManager());
  417. }
  418. Value Project::Item::getName() const
  419. {
  420. return node.getPropertyAsValue ("name", getUndoManager());
  421. }
  422. void Project::Item::addChild (const Item& newChild, int insertIndex)
  423. {
  424. node.addChild (newChild.getNode(), insertIndex, getUndoManager());
  425. }
  426. void Project::Item::removeItemFromProject()
  427. {
  428. node.getParent().removeChild (node, getUndoManager());
  429. }
  430. Project::Item Project::Item::getParent() const
  431. {
  432. if (isMainGroup() || ! isGroup())
  433. return *this;
  434. return Item (project, node.getParent());
  435. }
  436. struct ItemSorter
  437. {
  438. static int compareElements (const ValueTree& first, const ValueTree& second)
  439. {
  440. return first["name"].toString().compareIgnoreCase (second["name"].toString());
  441. }
  442. };
  443. void Project::Item::sortAlphabetically()
  444. {
  445. ItemSorter sorter;
  446. node.sort (sorter);
  447. }
  448. bool Project::Item::addFile (const File& file, int insertIndex)
  449. {
  450. if (file == File::nonexistent || file.isHidden() || file.getFileName().startsWithChar ('.'))
  451. return false;
  452. if (file.isDirectory())
  453. {
  454. Item group (project.createNewGroup());
  455. group.getName() = file.getFileNameWithoutExtension();
  456. jassert (canContain (group));
  457. addChild (group, insertIndex);
  458. //group.setFile (file);
  459. DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories);
  460. while (iter.next())
  461. group.addFile (iter.getFile(), -1);
  462. group.sortAlphabetically();
  463. }
  464. else if (file.existsAsFile())
  465. {
  466. Item item (project.createNewItem (file));
  467. if (canContain (item))
  468. {
  469. item.setFile (file);
  470. addChild (item, insertIndex);
  471. }
  472. }
  473. else
  474. {
  475. jassertfalse;
  476. }
  477. return true;
  478. }
  479. Image* Project::Item::getIcon() const
  480. {
  481. if (isFile())
  482. return LookAndFeel::getDefaultLookAndFeel().getDefaultDocumentFileImage();
  483. else if (isMainGroup())
  484. return ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize);
  485. else
  486. return LookAndFeel::getDefaultLookAndFeel().getDefaultFolderImage();
  487. }
  488. //==============================================================================
  489. ValueTree Project::getJuceConfigNode()
  490. {
  491. ValueTree configNode = projectRoot.getChildWithName ("JUCEOPTIONS");
  492. if (! configNode.isValid())
  493. {
  494. configNode = ValueTree ("JUCEOPTIONS");
  495. projectRoot.addChild (configNode, -1, 0);
  496. }
  497. return configNode;
  498. }
  499. void Project::getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags)
  500. {
  501. ValueTree configNode (getJuceConfigNode());
  502. File juceConfigH (getLocalJuceFolder().getChildFile ("juce_Config.h"));
  503. StringArray lines;
  504. lines.addLines (juceConfigH.loadFileAsString());
  505. for (int i = 0; i < lines.size(); ++i)
  506. {
  507. String line (lines[i].trim());
  508. if (line.startsWith ("/** ") && line.containsChar (':'))
  509. {
  510. ScopedPointer <JuceConfigFlag> config (new JuceConfigFlag());
  511. config->symbol = line.substring (4).upToFirstOccurrenceOf (":", false, false).trim();
  512. if (config->symbol.length() > 4)
  513. {
  514. config->description = line.fromFirstOccurrenceOf (":", false, false).trimStart();
  515. ++i;
  516. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  517. {
  518. if (lines[i].trim().isNotEmpty())
  519. config->description = config->description.trim() + " " + lines[i].trim();
  520. ++i;
  521. }
  522. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  523. config->value.referTo (getJuceConfigFlag (config->symbol));
  524. flags.add (config.release());
  525. }
  526. }
  527. }
  528. }
  529. Value Project::getJuceConfigFlag (const String& name)
  530. {
  531. static const char* valueRemappings[] = { "enabled", "1", "disabled", "2", "default", "3", 0 };
  532. ValueTree configNode (getJuceConfigNode());
  533. Value v (new ValueRemapperSource (configNode.getPropertyAsValue (name, getUndoManagerFor (configNode)),
  534. valueRemappings));
  535. if ((int) v.getValue() == 0)
  536. v = 3;
  537. return v;
  538. }
  539. //==============================================================================
  540. ValueTree Project::getConfigurations() const
  541. {
  542. return projectRoot.getChildWithName (Tags::configurations);
  543. }
  544. int Project::getNumConfigurations() const
  545. {
  546. return getConfigurations().getNumChildren();
  547. }
  548. Project::BuildConfiguration Project::getConfiguration (int index)
  549. {
  550. jassert (index < getConfigurations().getNumChildren());
  551. return BuildConfiguration (this, getConfigurations().getChild (index));
  552. }
  553. bool Project::hasConfigurationNamed (const String& name) const
  554. {
  555. const ValueTree configs (getConfigurations());
  556. for (int i = configs.getNumChildren(); --i >= 0;)
  557. if (configs.getChild(i) ["name"].toString() == name)
  558. return true;
  559. return false;
  560. }
  561. const String Project::getUniqueConfigName (String name) const
  562. {
  563. String nameRoot (name);
  564. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  565. nameRoot = nameRoot.dropLastCharacters (1);
  566. nameRoot = nameRoot.trim();
  567. int suffix = 2;
  568. while (hasConfigurationNamed (name))
  569. name = nameRoot + " " + String (suffix++);
  570. return name;
  571. }
  572. void Project::addNewConfiguration (BuildConfiguration* configToCopy)
  573. {
  574. const String configName (getUniqueConfigName (configToCopy != 0 ? configToCopy->config ["name"].toString()
  575. : "New Build Configuration"));
  576. ValueTree configs (getConfigurations());
  577. if (! configs.isValid())
  578. {
  579. projectRoot.addChild (ValueTree (Tags::configurations), 0, getUndoManagerFor (projectRoot));
  580. configs = getConfigurations();
  581. }
  582. ValueTree newConfig (Tags::configuration);
  583. if (configToCopy != 0)
  584. newConfig = configToCopy->config.createCopy();
  585. newConfig.setProperty ("name", configName, 0);
  586. configs.addChild (newConfig, -1, getUndoManagerFor (configs));
  587. }
  588. void Project::deleteConfiguration (int index)
  589. {
  590. ValueTree configs (getConfigurations());
  591. configs.removeChild (index, getUndoManagerFor (getConfigurations()));
  592. }
  593. void Project::createDefaultConfigs()
  594. {
  595. for (int i = 0; i < 2; ++i)
  596. {
  597. addNewConfiguration (0);
  598. BuildConfiguration config = getConfiguration (i);
  599. const bool debugConfig = i == 0;
  600. config.getName() = debugConfig ? "Debug" : "Release";
  601. config.isDebug() = debugConfig;
  602. config.getOptimisationLevel() = debugConfig ? 1 : 2;
  603. config.getTargetBinaryName() = getProjectFilenameRoot();
  604. }
  605. }
  606. //==============================================================================
  607. Project::BuildConfiguration::BuildConfiguration (Project* project_, const ValueTree& configNode)
  608. : project (project_),
  609. config (configNode)
  610. {
  611. }
  612. Project::BuildConfiguration::BuildConfiguration (const BuildConfiguration& other)
  613. : project (other.project),
  614. config (other.config)
  615. {
  616. }
  617. const Project::BuildConfiguration& Project::BuildConfiguration::operator= (const BuildConfiguration& other)
  618. {
  619. project = other.project;
  620. config = other.config;
  621. return *this;
  622. }
  623. Project::BuildConfiguration::~BuildConfiguration()
  624. {
  625. }
  626. const String Project::BuildConfiguration::getGCCOptimisationFlag() const
  627. {
  628. const int level = (int) getOptimisationLevel().getValue();
  629. return String (level <= 1 ? "0" : (level == 2 ? "s" : "3"));
  630. }
  631. static const char* osxSDKs[] = { "Use default", "10.4 SDK", "10.5 SDK", "10.6 SDK", 0 };
  632. static const char* osxSDKMappings[] = { "default", "1", "10.4 SDK", "2", "10.5 SDK", "3", "10.6 SDK", "4", "10.7 SDK", "5", 0 };
  633. void Project::BuildConfiguration::createPropertyEditors (Array <PropertyComponent*>& props)
  634. {
  635. props.add (new TextPropertyComponent (getName(), "Name", 96, false));
  636. props.getLast()->setTooltip ("The name of this configuration.");
  637. props.add (new BooleanPropertyComponent (isDebug(), "Debug mode", "Debugging enabled"));
  638. props.getLast()->setTooltip ("If enabled, this means that the configuration should be built with debug synbols.");
  639. const char* optimisationLevels[] = { "No optimisation", "Optimise for size and speed", "Optimise for maximum speed", 0 };
  640. props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation", StringArray (optimisationLevels)));
  641. props.getLast()->setTooltip ("The optimisation level for this configuration");
  642. props.add (new TextPropertyComponent (getTargetBinaryName(), "Binary name", 256, false));
  643. props.getLast()->setTooltip ("The filename to use for the destination binary executable file. Don't add a suffix to this, because platform-specific suffixes will be added for each target platform.");
  644. props.add (new TextPropertyComponent (getTargetBinaryRelativePath(), "Binary location", 1024, false));
  645. props.getLast()->setTooltip ("The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed in its default location in the build folder.");
  646. props.add (new TextPropertyComponent (getHeaderSearchPath(), "Header search path", 16384, false));
  647. props.getLast()->setTooltip ("Extra header search paths. Use semi-colons to separate multiple paths.");
  648. props.add (new TextPropertyComponent (getPreprocessorDefs(), "Preprocessor definitions", 32768, false));
  649. props.getLast()->setTooltip ("Extra preprocessor definitions. Use whitespace or commas as a delimiter.");
  650. if ((int) getMacSDKVersion().getValue() == 0)
  651. getMacSDKVersion() = 1;
  652. props.add (new ChoicePropertyComponent (getMacSDKVersion(), "OSX Base SDK Version", StringArray (osxSDKs)));
  653. props.getLast()->setTooltip ("The version of OSX to link against in the XCode build.");
  654. if ((int) getMacCompatibilityVersion().getValue() == 0)
  655. getMacCompatibilityVersion() = 1;
  656. props.add (new ChoicePropertyComponent (getMacCompatibilityVersion(), "OSX Compatibility Version", StringArray (osxSDKs)));
  657. props.getLast()->setTooltip ("The minimum version of OSX that the target binary will be compatible with.");
  658. for (int i = props.size(); --i >= 0;)
  659. props.getUnchecked(i)->setPreferredHeight (22);
  660. }
  661. const StringArray Project::BuildConfiguration::parsePreprocessorDefs() const
  662. {
  663. StringArray defines;
  664. defines.addTokens (getPreprocessorDefs().toString(), " ,;", String::empty);
  665. defines.removeEmptyStrings (true);
  666. return defines;
  667. }
  668. const StringArray Project::BuildConfiguration::getHeaderSearchPaths() const
  669. {
  670. StringArray s;
  671. s.addTokens (getHeaderSearchPath().toString(), ";", String::empty);
  672. return s;
  673. }
  674. Value Project::BuildConfiguration::getMacSDKVersion() const
  675. {
  676. return Value (new ValueRemapperSource (config.getPropertyAsValue ("osxSDK", getUndoManager()), osxSDKMappings));
  677. }
  678. Value Project::BuildConfiguration::getMacCompatibilityVersion() const
  679. {
  680. return Value (new ValueRemapperSource (config.getPropertyAsValue ("osxCompatibility", getUndoManager()), osxSDKMappings));
  681. }
  682. //==============================================================================
  683. ValueTree Project::getExporters()
  684. {
  685. ValueTree exporters (projectRoot.getChildWithName (Tags::exporters));
  686. if (! exporters.isValid())
  687. {
  688. projectRoot.addChild (ValueTree (Tags::exporters), 0, getUndoManagerFor (projectRoot));
  689. exporters = getExporters();
  690. }
  691. return exporters;
  692. }
  693. int Project::getNumExporters()
  694. {
  695. return getExporters().getNumChildren();
  696. }
  697. ProjectExporter* Project::createExporter (int index)
  698. {
  699. jassert (index >= 0 && index < getNumExporters());
  700. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  701. }
  702. void Project::addNewExporter (int exporterIndex)
  703. {
  704. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterIndex));
  705. ValueTree exporters (getExporters());
  706. exporters.addChild (exp->getSettings(), -1, getUndoManagerFor (exporters));
  707. }
  708. void Project::deleteExporter (int index)
  709. {
  710. ValueTree exporters (getExporters());
  711. exporters.removeChild (index, getUndoManagerFor (exporters));
  712. }
  713. void Project::createDefaultExporters()
  714. {
  715. ValueTree exporters (getExporters());
  716. exporters.removeAllChildren (getUndoManagerFor (exporters));
  717. for (int i = 0; i < ProjectExporter::getNumExporters(); ++i)
  718. addNewExporter (i);
  719. }
  720. //==============================================================================
  721. const String Project::getFileTemplate (const String& templateName)
  722. {
  723. int dataSize;
  724. const char* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize);
  725. if (data == 0)
  726. {
  727. jassertfalse;
  728. return String::empty;
  729. }
  730. return String::fromUTF8 (data, dataSize);
  731. }