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.

814 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_Module.h"
  19. #include "jucer_ProjectType.h"
  20. #include "../Project Saving/jucer_ProjectExporter.h"
  21. #include "../Project Saving/jucer_ProjectSaver.h"
  22. #include "../Project Saving/jucer_ProjectExport_XCode.h"
  23. static String trimCommentCharsFromStartOfLine (const String& line)
  24. {
  25. return line.trimStart().trimCharactersAtStart ("*/").trimStart();
  26. }
  27. static var parseModuleDesc (const StringArray& lines)
  28. {
  29. DynamicObject* o = new DynamicObject();
  30. var result (o);
  31. for (int i = 0; i < lines.size(); ++i)
  32. {
  33. String line = trimCommentCharsFromStartOfLine (lines[i]);
  34. int colon = line.indexOfChar (':');
  35. if (colon >= 0)
  36. {
  37. String key = line.substring (0, colon).trim();
  38. String value = line.substring (colon + 1).trim();
  39. o->setProperty (key, value);
  40. }
  41. }
  42. return result;
  43. }
  44. static var parseModuleDesc (const File& header)
  45. {
  46. StringArray lines;
  47. header.readLines (lines);
  48. for (int i = 0; i < lines.size(); ++i)
  49. {
  50. if (trimCommentCharsFromStartOfLine (lines[i]).startsWith ("BEGIN_JUCE_MODULE_DECLARATION"))
  51. {
  52. StringArray desc;
  53. for (int j = i + 1; j < lines.size(); ++j)
  54. {
  55. if (trimCommentCharsFromStartOfLine (lines[j]).startsWith ("END_JUCE_MODULE_DECLARATION"))
  56. return parseModuleDesc (desc);
  57. desc.add (lines[j]);
  58. }
  59. break;
  60. }
  61. }
  62. return var();
  63. }
  64. ModuleDescription::ModuleDescription (const File& folder)
  65. : moduleFolder (folder),
  66. moduleInfo (parseModuleDesc (getHeader()))
  67. {
  68. }
  69. File ModuleDescription::getHeader() const
  70. {
  71. const char* extensions[] = { ".h", ".hpp", ".hxx" };
  72. for (int i = 0; i < numElementsInArray (extensions); ++i)
  73. {
  74. File header (moduleFolder.getChildFile (moduleFolder.getFileName() + extensions[i]));
  75. if (header.existsAsFile())
  76. return header;
  77. }
  78. return File();
  79. }
  80. StringArray ModuleDescription::getDependencies() const
  81. {
  82. StringArray deps = StringArray::fromTokens (moduleInfo ["dependencies"].toString(), " \t;,", "\"'");
  83. deps.trim();
  84. deps.removeEmptyStrings();
  85. return deps;
  86. }
  87. //==============================================================================
  88. ModuleList::ModuleList()
  89. {
  90. }
  91. ModuleList::ModuleList (const ModuleList& other)
  92. {
  93. operator= (other);
  94. }
  95. ModuleList& ModuleList::operator= (const ModuleList& other)
  96. {
  97. modules.clear();
  98. modules.addCopiesOf (other.modules);
  99. return *this;
  100. }
  101. const ModuleDescription* ModuleList::getModuleWithID (const String& moduleID) const
  102. {
  103. for (int i = 0; i < modules.size(); ++i)
  104. {
  105. ModuleDescription* m = modules.getUnchecked(i);
  106. if (m->getID() == moduleID)
  107. return m;
  108. }
  109. return nullptr;
  110. }
  111. struct ModuleSorter
  112. {
  113. static int compareElements (const ModuleDescription* m1, const ModuleDescription* m2)
  114. {
  115. return m1->getID().compareIgnoreCase (m2->getID());
  116. }
  117. };
  118. void ModuleList::sort()
  119. {
  120. ModuleSorter sorter;
  121. modules.sort (sorter);
  122. }
  123. StringArray ModuleList::getIDs() const
  124. {
  125. StringArray results;
  126. for (int i = 0; i < modules.size(); ++i)
  127. results.add (modules.getUnchecked(i)->getID());
  128. results.sort (true);
  129. return results;
  130. }
  131. Result ModuleList::addAllModulesInFolder (const File& path)
  132. {
  133. ModuleDescription m (path);
  134. if (m.isValid())
  135. {
  136. modules.add (new ModuleDescription (m));
  137. }
  138. else
  139. {
  140. for (DirectoryIterator iter (path, false, "*", File::findDirectories); iter.next();)
  141. {
  142. Result r = addAllModulesInFolder (iter.getFile().getLinkedTarget());
  143. if (r.failed())
  144. return r;
  145. }
  146. }
  147. return Result::ok();
  148. }
  149. static Array<File> getAllPossibleModulePaths (Project& project)
  150. {
  151. StringArray paths;
  152. for (Project::ExporterIterator exporter (project); exporter.next();)
  153. {
  154. for (int i = 0; i < project.getModules().getNumModules(); ++i)
  155. {
  156. const String path (exporter->getPathForModuleString (project.getModules().getModuleID (i)));
  157. if (path.isNotEmpty())
  158. paths.addIfNotAlreadyThere (path);
  159. }
  160. String oldPath (exporter->getLegacyModulePath());
  161. if (oldPath.isNotEmpty())
  162. paths.addIfNotAlreadyThere (oldPath);
  163. }
  164. Array<File> files;
  165. for (int i = 0; i < paths.size(); ++i)
  166. {
  167. const File f (project.resolveFilename (paths[i]));
  168. if (f.isDirectory())
  169. {
  170. files.add (f);
  171. if (f.getChildFile ("modules").isDirectory())
  172. files.addIfNotAlreadyThere (f.getChildFile ("modules"));
  173. }
  174. }
  175. return files;
  176. }
  177. Result ModuleList::scanAllKnownFolders (Project& project)
  178. {
  179. modules.clear();
  180. Result result (Result::ok());
  181. const Array<File> modulePaths (getAllPossibleModulePaths (project));
  182. for (int i = 0; i < modulePaths.size(); ++i)
  183. {
  184. result = addAllModulesInFolder (modulePaths.getReference(i));
  185. if (result.failed())
  186. break;
  187. }
  188. sort();
  189. return result;
  190. }
  191. //==============================================================================
  192. LibraryModule::LibraryModule (const ModuleDescription& d)
  193. : moduleInfo (d)
  194. {
  195. }
  196. //==============================================================================
  197. void LibraryModule::writeIncludes (ProjectSaver& projectSaver, OutputStream& out)
  198. {
  199. Project& project = projectSaver.project;
  200. EnabledModuleList& modules = project.getModules();
  201. const String id (getID());
  202. if (modules.shouldCopyModuleFilesLocally (id).getValue())
  203. {
  204. const File juceModuleFolder (moduleInfo.getFolder());
  205. const File localModuleFolder (project.getLocalModuleFolder (id));
  206. localModuleFolder.createDirectory();
  207. projectSaver.copyFolder (juceModuleFolder, localModuleFolder);
  208. }
  209. out << "#include <" << moduleInfo.moduleFolder.getFileName() << "/"
  210. << moduleInfo.getHeader().getFileName()
  211. << ">" << newLine;
  212. }
  213. //==============================================================================
  214. static void parseAndAddLibs (StringArray& libList, const String& libs)
  215. {
  216. libList.addTokens (libs, ", ", StringRef());
  217. libList.trim();
  218. libList.sort (false);
  219. libList.removeDuplicates (false);
  220. }
  221. void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  222. {
  223. Project& project = exporter.getProject();
  224. RelativePath modulePath = exporter.getModuleFolderRelativeToProject (getID());
  225. exporter.addToExtraSearchPaths (modulePath.getParentDirectory());
  226. const String extraInternalSearchPaths (moduleInfo.getExtraSearchPaths().trim());
  227. if (extraInternalSearchPaths.isNotEmpty())
  228. {
  229. StringArray paths;
  230. paths.addTokens (extraInternalSearchPaths, true);
  231. for (int i = 0; i < paths.size(); ++i)
  232. exporter.addToExtraSearchPaths (modulePath.getChildFile (paths.getReference(i)));
  233. }
  234. {
  235. const String extraDefs (moduleInfo.getPreprocessorDefs().trim());
  236. if (extraDefs.isNotEmpty())
  237. exporter.getExporterPreprocessorDefs() = exporter.getExporterPreprocessorDefsString() + "\n" + extraDefs;
  238. }
  239. {
  240. Array<File> compiled;
  241. const File localModuleFolder = project.getModules().shouldCopyModuleFilesLocally (getID()).getValue()
  242. ? project.getLocalModuleFolder (getID())
  243. : moduleInfo.getFolder();
  244. findAndAddCompiledUnits (exporter, &projectSaver, compiled);
  245. if (project.getModules().shouldShowAllModuleFilesInProject (getID()).getValue())
  246. addBrowseableCode (exporter, compiled, localModuleFolder);
  247. }
  248. if (exporter.isXcode())
  249. {
  250. XCodeProjectExporter& xcodeExporter = dynamic_cast<XCodeProjectExporter&> (exporter);
  251. if (project.isAUPluginHost())
  252. xcodeExporter.xcodeFrameworks.addTokens (xcodeExporter.isOSX() ? "AudioUnit CoreAudioKit" : "CoreAudioKit", false);
  253. const String frameworks (moduleInfo.moduleInfo [xcodeExporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString());
  254. xcodeExporter.xcodeFrameworks.addTokens (frameworks, ", ", StringRef());
  255. parseAndAddLibs (xcodeExporter.xcodeLibs, moduleInfo.moduleInfo [exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString());
  256. }
  257. else if (exporter.isLinux())
  258. {
  259. parseAndAddLibs (exporter.linuxLibs, moduleInfo.moduleInfo ["linuxLibs"].toString());
  260. parseAndAddLibs (exporter.linuxPackages, moduleInfo.moduleInfo ["linuxPackages"].toString());
  261. }
  262. else if (exporter.isCodeBlocks() && exporter.isWindows())
  263. {
  264. parseAndAddLibs (exporter.mingwLibs, moduleInfo.moduleInfo ["mingwLibs"].toString());
  265. }
  266. }
  267. void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
  268. {
  269. const File header (moduleInfo.getHeader());
  270. jassert (header.exists());
  271. StringArray lines;
  272. header.readLines (lines);
  273. for (int i = 0; i < lines.size(); ++i)
  274. {
  275. String line (lines[i].trim());
  276. if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
  277. {
  278. ScopedPointer<Project::ConfigFlag> config (new Project::ConfigFlag());
  279. config->sourceModuleID = getID();
  280. config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
  281. if (config->symbol.length() > 2)
  282. {
  283. ++i;
  284. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  285. {
  286. if (lines[i].trim().isNotEmpty())
  287. config->description = config->description.trim() + " " + lines[i].trim();
  288. ++i;
  289. }
  290. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  291. config->value.referTo (project.getConfigFlag (config->symbol));
  292. flags.add (config.release());
  293. }
  294. }
  295. }
  296. }
  297. //==============================================================================
  298. struct FileSorter
  299. {
  300. static int compareElements (const File& f1, const File& f2)
  301. {
  302. return f1.getFileName().compareNatural (f2.getFileName());
  303. }
  304. };
  305. bool LibraryModule::CompileUnit::hasSuffix (const File& f, const char* suffix)
  306. {
  307. String fileWithoutSuffix = f.getFileNameWithoutExtension() + String (".");
  308. return fileWithoutSuffix.containsIgnoreCase (suffix + String ("."))
  309. || fileWithoutSuffix.containsIgnoreCase (suffix + String ("_"));
  310. }
  311. void LibraryModule::CompileUnit::writeInclude (MemoryOutputStream&) const
  312. {
  313. }
  314. bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const
  315. {
  316. Project& project = exporter.getProject();
  317. if ((hasSuffix (file, "_OSX") && ! exporter.isOSX())
  318. || (hasSuffix (file, "_iOS") && ! exporter.isiOS())
  319. || (hasSuffix (file, "_Windows") && ! exporter.isWindows())
  320. || (hasSuffix (file, "_Linux") && ! exporter.isLinux())
  321. || (hasSuffix (file, "_Android") && ! exporter.isAndroid())
  322. || (hasSuffix (file, "_AU") && ! (project.shouldBuildAU() .getValue() && exporter.supportsAU()))
  323. || (hasSuffix (file, "_AUv3") && ! (project.shouldBuildAUv3().getValue() && exporter.supportsAUv3()))
  324. || (hasSuffix (file, "_AAX") && ! (project.shouldBuildAAX() .getValue() && exporter.supportsAAX()))
  325. || (hasSuffix (file, "_RTAS") && ! (project.shouldBuildRTAS().getValue() && exporter.supportsRTAS()))
  326. || (hasSuffix (file, "_VST2") && ! (project.shouldBuildVST() .getValue() && exporter.supportsVST()))
  327. || (hasSuffix (file, "_VST3") && ! (project.shouldBuildVST3().getValue() && exporter.supportsVST3()))
  328. || (hasSuffix (file, "_Standalone") && ! (project.shouldBuildStandalone().getValue() && exporter.supportsStandalone())))
  329. return false;
  330. return exporter.usesMMFiles() ? isCompiledForObjC
  331. : isCompiledForNonObjC;
  332. }
  333. Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits() const
  334. {
  335. Array<File> files;
  336. getFolder().findChildFiles (files, File::findFiles, false);
  337. FileSorter sorter;
  338. files.sort (sorter);
  339. Array<LibraryModule::CompileUnit> units;
  340. for (int i = 0; i < files.size(); ++i)
  341. {
  342. CompileUnit cu;
  343. cu.file = files.getReference(i);
  344. if (cu.file.getFileName().startsWithIgnoreCase (getID())
  345. && cu.file.hasFileExtension (sourceFileExtensions))
  346. {
  347. units.add (cu);
  348. }
  349. }
  350. for (int i = 0; i < units.size(); ++i)
  351. {
  352. CompileUnit& cu = units.getReference(i);
  353. cu.isCompiledForObjC = true;
  354. cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m");
  355. if (cu.isCompiledForNonObjC)
  356. if (files.contains (cu.file.withFileExtension ("mm")))
  357. cu.isCompiledForObjC = false;
  358. jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
  359. }
  360. return units;
  361. }
  362. void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter,
  363. ProjectSaver* projectSaver,
  364. Array<File>& result) const
  365. {
  366. Array<CompileUnit> units = getAllCompileUnits();
  367. for (int i = 0; i < units.size(); ++i)
  368. {
  369. const CompileUnit& cu = units.getReference(i);
  370. if (cu.isNeededForExporter (exporter))
  371. {
  372. File localFile = exporter.getProject().getGeneratedCodeFolder().getChildFile (cu.file.getFileName());
  373. result.add (localFile);
  374. if (projectSaver != nullptr)
  375. projectSaver->addFileToGeneratedGroup (localFile);
  376. }
  377. }
  378. }
  379. static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path)
  380. {
  381. const int slash = path.indexOfChar (File::separator);
  382. if (slash >= 0)
  383. {
  384. const String topLevelGroup (path.substring (0, slash));
  385. const String remainingPath (path.substring (slash + 1));
  386. Project::Item newGroup (group.getOrCreateSubGroup (topLevelGroup));
  387. addFileWithGroups (newGroup, file, remainingPath);
  388. }
  389. else
  390. {
  391. if (! group.containsChildForFile (file))
  392. group.addRelativeFile (file, -1, false);
  393. }
  394. }
  395. void LibraryModule::findBrowseableFiles (const File& folder, Array<File>& filesFound) const
  396. {
  397. Array<File> tempList;
  398. FileSorter sorter;
  399. DirectoryIterator iter (folder, true, "*", File::findFiles);
  400. bool isHiddenFile;
  401. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  402. if (! isHiddenFile && iter.getFile().hasFileExtension (browseableFileExtensions))
  403. tempList.addSorted (sorter, iter.getFile());
  404. filesFound.addArray (tempList);
  405. }
  406. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  407. {
  408. if (sourceFiles.size() == 0)
  409. findBrowseableFiles (localModuleFolder, sourceFiles);
  410. Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false));
  411. const RelativePath moduleFromProject (exporter.getModuleFolderRelativeToProject (getID()));
  412. for (int i = 0; i < sourceFiles.size(); ++i)
  413. {
  414. const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder));
  415. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  416. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  417. if (exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFiles.getReference(i)))
  418. addFileWithGroups (sourceGroup,
  419. moduleFromProject.getChildFile (pathWithinModule),
  420. pathWithinModule);
  421. }
  422. sourceGroup.sortAlphabetically (true, true);
  423. sourceGroup.addFileAtIndex (moduleInfo.getHeader(), -1, false);
  424. exporter.getModulesGroup().state.addChild (sourceGroup.state.createCopy(), -1, nullptr);
  425. }
  426. //==============================================================================
  427. EnabledModuleList::EnabledModuleList (Project& p, const ValueTree& s)
  428. : project (p), state (s)
  429. {
  430. }
  431. ModuleDescription EnabledModuleList::getModuleInfo (const String& moduleID)
  432. {
  433. return ModuleDescription (getModuleFolder (moduleID));
  434. }
  435. bool EnabledModuleList::isModuleEnabled (const String& moduleID) const
  436. {
  437. for (int i = 0; i < state.getNumChildren(); ++i)
  438. if (state.getChild(i) [Ids::ID] == moduleID)
  439. return true;
  440. return false;
  441. }
  442. bool EnabledModuleList::isAudioPluginModuleMissing() const
  443. {
  444. return project.getProjectType().isAudioPlugin()
  445. && ! isModuleEnabled ("juce_audio_plugin_client");
  446. }
  447. Value EnabledModuleList::shouldShowAllModuleFilesInProject (const String& moduleID)
  448. {
  449. return state.getChildWithProperty (Ids::ID, moduleID)
  450. .getPropertyAsValue (Ids::showAllCode, getUndoManager());
  451. }
  452. File EnabledModuleList::findLocalModuleFolder (const String& moduleID, bool useExportersForOtherOSes)
  453. {
  454. for (Project::ExporterIterator exporter (project); exporter.next();)
  455. {
  456. if (useExportersForOtherOSes || exporter->mayCompileOnCurrentOS())
  457. {
  458. const String path (exporter->getPathForModuleString (moduleID));
  459. if (path.isNotEmpty())
  460. {
  461. const File moduleFolder (project.resolveFilename (path));
  462. if (moduleFolder.exists())
  463. {
  464. if (ModuleDescription (moduleFolder).isValid())
  465. return moduleFolder;
  466. File f = moduleFolder.getChildFile (moduleID);
  467. if (ModuleDescription (f).isValid())
  468. return f;
  469. }
  470. }
  471. }
  472. }
  473. return File();
  474. }
  475. File EnabledModuleList::getModuleFolder (const String& moduleID)
  476. {
  477. File f = findLocalModuleFolder (moduleID, false);
  478. if (f == File())
  479. f = findLocalModuleFolder (moduleID, true);
  480. return f;
  481. }
  482. struct ModuleTreeSorter
  483. {
  484. static int compareElements (const ValueTree& m1, const ValueTree& m2)
  485. {
  486. return m1[Ids::ID].toString().compareIgnoreCase (m2[Ids::ID]);
  487. }
  488. };
  489. void EnabledModuleList::sortAlphabetically()
  490. {
  491. ModuleTreeSorter sorter;
  492. state.sort (sorter, getUndoManager(), false);
  493. }
  494. Value EnabledModuleList::shouldCopyModuleFilesLocally (const String& moduleID) const
  495. {
  496. return state.getChildWithProperty (Ids::ID, moduleID)
  497. .getPropertyAsValue (Ids::useLocalCopy, getUndoManager());
  498. }
  499. void EnabledModuleList::addModule (const File& moduleFolder, bool copyLocally)
  500. {
  501. ModuleDescription info (moduleFolder);
  502. if (info.isValid())
  503. {
  504. const String moduleID (info.getID());
  505. if (! isModuleEnabled (moduleID))
  506. {
  507. ValueTree module (Ids::MODULE);
  508. module.setProperty (Ids::ID, moduleID, nullptr);
  509. state.addChild (module, -1, getUndoManager());
  510. sortAlphabetically();
  511. shouldShowAllModuleFilesInProject (moduleID) = true;
  512. shouldCopyModuleFilesLocally (moduleID) = copyLocally;
  513. RelativePath path (moduleFolder.getParentDirectory(),
  514. project.getProjectFolder(), RelativePath::projectFolder);
  515. for (Project::ExporterIterator exporter (project); exporter.next();)
  516. exporter->getPathForModuleValue (moduleID) = path.toUnixStyle();
  517. }
  518. }
  519. }
  520. void EnabledModuleList::removeModule (String moduleID) // must be pass-by-value, and not a const ref!
  521. {
  522. for (int i = state.getNumChildren(); --i >= 0;)
  523. if (state.getChild(i) [Ids::ID] == moduleID)
  524. state.removeChild (i, getUndoManager());
  525. for (Project::ExporterIterator exporter (project); exporter.next();)
  526. exporter->removePathForModule (moduleID);
  527. }
  528. void EnabledModuleList::createRequiredModules (OwnedArray<LibraryModule>& modules)
  529. {
  530. for (int i = 0; i < getNumModules(); ++i)
  531. modules.add (new LibraryModule (getModuleInfo (getModuleID (i))));
  532. }
  533. StringArray EnabledModuleList::getAllModules() const
  534. {
  535. StringArray moduleIDs;
  536. for (int i = 0; i < getNumModules(); ++i)
  537. moduleIDs.add (getModuleID(i));
  538. return moduleIDs;
  539. }
  540. static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies)
  541. {
  542. ModuleDescription info (project.getModules().getModuleInfo (moduleID));
  543. for (auto uid : info.getDependencies())
  544. {
  545. if (! dependencies.contains (uid, true))
  546. {
  547. dependencies.add (uid);
  548. getDependencies (project, uid, dependencies);
  549. }
  550. }
  551. }
  552. StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const
  553. {
  554. StringArray dependencies, extraDepsNeeded;
  555. getDependencies (project, moduleID, dependencies);
  556. for (auto dep : dependencies)
  557. if (dep != moduleID && ! isModuleEnabled (dep))
  558. extraDepsNeeded.add (dep);
  559. return extraDepsNeeded;
  560. }
  561. bool EnabledModuleList::areMostModulesCopiedLocally() const
  562. {
  563. int numYes = 0, numNo = 0;
  564. for (int i = getNumModules(); --i >= 0;)
  565. {
  566. if (shouldCopyModuleFilesLocally (getModuleID (i)).getValue())
  567. ++numYes;
  568. else
  569. ++numNo;
  570. }
  571. return numYes > numNo;
  572. }
  573. void EnabledModuleList::setLocalCopyModeForAllModules (bool copyLocally)
  574. {
  575. for (int i = getNumModules(); --i >= 0;)
  576. shouldCopyModuleFilesLocally (project.getModules().getModuleID (i)) = copyLocally;
  577. }
  578. File EnabledModuleList::findDefaultModulesFolder (Project& project)
  579. {
  580. ModuleList available;
  581. available.scanAllKnownFolders (project);
  582. for (int i = available.modules.size(); --i >= 0;)
  583. {
  584. File f (available.modules.getUnchecked(i)->getFolder());
  585. if (f.isDirectory())
  586. return f.getParentDirectory();
  587. }
  588. return File::getCurrentWorkingDirectory();
  589. }
  590. void EnabledModuleList::addModuleFromUserSelectedFile()
  591. {
  592. static File lastLocation (findDefaultModulesFolder (project));
  593. FileChooser fc ("Select a module to add...", lastLocation, String(), false);
  594. if (fc.browseForDirectory())
  595. {
  596. lastLocation = fc.getResult();
  597. addModuleOfferingToCopy (lastLocation);
  598. }
  599. }
  600. void EnabledModuleList::addModuleInteractive (const String& moduleID)
  601. {
  602. ModuleList list;
  603. list.scanAllKnownFolders (project);
  604. if (const ModuleDescription* info = list.getModuleWithID (moduleID))
  605. addModule (info->moduleFolder, areMostModulesCopiedLocally());
  606. else
  607. addModuleFromUserSelectedFile();
  608. }
  609. void EnabledModuleList::addModuleOfferingToCopy (const File& f)
  610. {
  611. ModuleDescription m (f);
  612. if (! m.isValid())
  613. {
  614. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  615. "Add Module", "This wasn't a valid module folder!");
  616. return;
  617. }
  618. if (isModuleEnabled (m.getID()))
  619. {
  620. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  621. "Add Module", "The project already contains this module!");
  622. return;
  623. }
  624. addModule (m.moduleFolder, areMostModulesCopiedLocally());
  625. }
  626. bool isJuceFolder (const File& f)
  627. {
  628. return isJuceModulesFolder (f.getChildFile ("modules"));
  629. }
  630. bool isJuceModulesFolder (const File& f)
  631. {
  632. return f.isDirectory() && f.getChildFile ("juce_core").isDirectory();
  633. }