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.

842 lines
26KB

  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::tryToAddModuleFromFolder (const File& path)
  132. {
  133. ModuleDescription m (path);
  134. if (m.isValid())
  135. {
  136. modules.add (new ModuleDescription (m));
  137. return Result::ok();
  138. }
  139. return Result::fail (path.getFullPathName() + " is not a valid module");
  140. }
  141. Result ModuleList::addAllModulesInFolder (const File& path)
  142. {
  143. if (! tryToAddModuleFromFolder (path))
  144. {
  145. const int subfolders = 2;
  146. return addAllModulesInSubfoldersRecursively (path, subfolders);
  147. }
  148. return Result::ok();
  149. }
  150. Result ModuleList::addAllModulesInSubfoldersRecursively (const File& path, int depth)
  151. {
  152. if (depth > 0)
  153. {
  154. for (DirectoryIterator iter (path, false, "*", File::findDirectories); iter.next();)
  155. {
  156. const File& childPath = iter.getFile().getLinkedTarget();
  157. if (! tryToAddModuleFromFolder (childPath))
  158. addAllModulesInSubfoldersRecursively (childPath, depth - 1);
  159. }
  160. }
  161. return Result::ok();
  162. }
  163. static Array<File> getAllPossibleModulePaths (Project& project)
  164. {
  165. StringArray paths;
  166. for (Project::ExporterIterator exporter (project); exporter.next();)
  167. {
  168. for (int i = 0; i < project.getModules().getNumModules(); ++i)
  169. {
  170. const String path (exporter->getPathForModuleString (project.getModules().getModuleID (i)));
  171. if (path.isNotEmpty())
  172. paths.addIfNotAlreadyThere (path);
  173. }
  174. String oldPath (exporter->getLegacyModulePath());
  175. if (oldPath.isNotEmpty())
  176. paths.addIfNotAlreadyThere (oldPath);
  177. }
  178. Array<File> files;
  179. for (int i = 0; i < paths.size(); ++i)
  180. {
  181. const File f (project.resolveFilename (paths[i]));
  182. if (f.isDirectory())
  183. {
  184. files.add (f);
  185. if (f.getChildFile ("modules").isDirectory())
  186. files.addIfNotAlreadyThere (f.getChildFile ("modules"));
  187. }
  188. }
  189. return files;
  190. }
  191. Result ModuleList::scanAllKnownFolders (Project& project)
  192. {
  193. modules.clear();
  194. Result result (Result::ok());
  195. const Array<File> modulePaths (getAllPossibleModulePaths (project));
  196. for (int i = 0; i < modulePaths.size(); ++i)
  197. {
  198. result = addAllModulesInFolder (modulePaths.getReference(i));
  199. if (result.failed())
  200. break;
  201. }
  202. sort();
  203. return result;
  204. }
  205. //==============================================================================
  206. LibraryModule::LibraryModule (const ModuleDescription& d)
  207. : moduleInfo (d)
  208. {
  209. }
  210. //==============================================================================
  211. void LibraryModule::writeIncludes (ProjectSaver& projectSaver, OutputStream& out)
  212. {
  213. Project& project = projectSaver.project;
  214. EnabledModuleList& modules = project.getModules();
  215. const String id (getID());
  216. if (modules.shouldCopyModuleFilesLocally (id).getValue())
  217. {
  218. const File juceModuleFolder (moduleInfo.getFolder());
  219. const File localModuleFolder (project.getLocalModuleFolder (id));
  220. localModuleFolder.createDirectory();
  221. projectSaver.copyFolder (juceModuleFolder, localModuleFolder);
  222. }
  223. out << "#include <" << moduleInfo.moduleFolder.getFileName() << "/"
  224. << moduleInfo.getHeader().getFileName()
  225. << ">" << newLine;
  226. }
  227. //==============================================================================
  228. static void parseAndAddLibs (StringArray& libList, const String& libs)
  229. {
  230. libList.addTokens (libs, ", ", StringRef());
  231. libList.trim();
  232. libList.sort (false);
  233. libList.removeDuplicates (false);
  234. }
  235. void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  236. {
  237. auto& project = exporter.getProject();
  238. const auto moduleRelativePath = exporter.getModuleFolderRelativeToProject (getID());
  239. exporter.addToExtraSearchPaths (moduleRelativePath.getParentDirectory());
  240. String libDirPlatform;
  241. if (exporter.isLinux())
  242. libDirPlatform = "Linux";
  243. else if (exporter.isCodeBlocks() && exporter.isWindows())
  244. libDirPlatform = "MinGW";
  245. else
  246. libDirPlatform = exporter.getTargetFolder().getFileName();
  247. const auto libSubdirPath = String (moduleRelativePath.toUnixStyle() + "/libs/") + libDirPlatform;
  248. const auto moduleLibDir = File (project.getProjectFolder().getFullPathName() + "/" + libSubdirPath);
  249. if (moduleLibDir.exists())
  250. exporter.addToModuleLibPaths (RelativePath (libSubdirPath, moduleRelativePath.getRoot()));
  251. const auto extraInternalSearchPaths = moduleInfo.getExtraSearchPaths().trim();
  252. if (extraInternalSearchPaths.isNotEmpty())
  253. {
  254. StringArray paths;
  255. paths.addTokens (extraInternalSearchPaths, true);
  256. for (int i = 0; i < paths.size(); ++i)
  257. exporter.addToExtraSearchPaths (moduleRelativePath.getChildFile (paths.getReference(i)));
  258. }
  259. {
  260. const String extraDefs (moduleInfo.getPreprocessorDefs().trim());
  261. if (extraDefs.isNotEmpty())
  262. exporter.getExporterPreprocessorDefs() = exporter.getExporterPreprocessorDefsString() + "\n" + extraDefs;
  263. }
  264. {
  265. Array<File> compiled;
  266. const File localModuleFolder = project.getModules().shouldCopyModuleFilesLocally (getID()).getValue()
  267. ? project.getLocalModuleFolder (getID())
  268. : moduleInfo.getFolder();
  269. findAndAddCompiledUnits (exporter, &projectSaver, compiled);
  270. if (project.getModules().shouldShowAllModuleFilesInProject (getID()).getValue())
  271. addBrowseableCode (exporter, compiled, localModuleFolder);
  272. }
  273. if (exporter.isXcode())
  274. {
  275. XCodeProjectExporter& xcodeExporter = dynamic_cast<XCodeProjectExporter&> (exporter);
  276. if (project.isAUPluginHost())
  277. xcodeExporter.xcodeFrameworks.addTokens (xcodeExporter.isOSX() ? "AudioUnit CoreAudioKit" : "CoreAudioKit", false);
  278. const String frameworks (moduleInfo.moduleInfo [xcodeExporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString());
  279. xcodeExporter.xcodeFrameworks.addTokens (frameworks, ", ", StringRef());
  280. parseAndAddLibs (xcodeExporter.xcodeLibs, moduleInfo.moduleInfo [exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString());
  281. }
  282. else if (exporter.isLinux())
  283. {
  284. parseAndAddLibs (exporter.linuxLibs, moduleInfo.moduleInfo ["linuxLibs"].toString());
  285. parseAndAddLibs (exporter.linuxPackages, moduleInfo.moduleInfo ["linuxPackages"].toString());
  286. }
  287. else if (exporter.isWindows())
  288. {
  289. if (exporter.isCodeBlocks())
  290. parseAndAddLibs (exporter.mingwLibs, moduleInfo.moduleInfo ["mingwLibs"].toString());
  291. else
  292. parseAndAddLibs (exporter.windowsLibs, moduleInfo.moduleInfo ["windowsLibs"].toString());
  293. }
  294. }
  295. void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
  296. {
  297. const File header (moduleInfo.getHeader());
  298. jassert (header.exists());
  299. StringArray lines;
  300. header.readLines (lines);
  301. for (int i = 0; i < lines.size(); ++i)
  302. {
  303. String line (lines[i].trim());
  304. if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
  305. {
  306. ScopedPointer<Project::ConfigFlag> config (new Project::ConfigFlag());
  307. config->sourceModuleID = getID();
  308. config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
  309. if (config->symbol.length() > 2)
  310. {
  311. ++i;
  312. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  313. {
  314. if (lines[i].trim().isNotEmpty())
  315. config->description = config->description.trim() + " " + lines[i].trim();
  316. ++i;
  317. }
  318. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  319. config->value.referTo (project.getConfigFlag (config->symbol));
  320. flags.add (config.release());
  321. }
  322. }
  323. }
  324. }
  325. //==============================================================================
  326. struct FileSorter
  327. {
  328. static int compareElements (const File& f1, const File& f2)
  329. {
  330. return f1.getFileName().compareNatural (f2.getFileName());
  331. }
  332. };
  333. bool LibraryModule::CompileUnit::hasSuffix (const File& f, const char* suffix)
  334. {
  335. String fileWithoutSuffix = f.getFileNameWithoutExtension() + String (".");
  336. return fileWithoutSuffix.containsIgnoreCase (suffix + String ("."))
  337. || fileWithoutSuffix.containsIgnoreCase (suffix + String ("_"));
  338. }
  339. void LibraryModule::CompileUnit::writeInclude (MemoryOutputStream&) const
  340. {
  341. }
  342. bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const
  343. {
  344. if ((hasSuffix (file, "_OSX") && ! exporter.isOSX())
  345. || (hasSuffix (file, "_iOS") && ! exporter.isiOS())
  346. || (hasSuffix (file, "_Windows") && ! exporter.isWindows())
  347. || (hasSuffix (file, "_Linux") && ! exporter.isLinux())
  348. || (hasSuffix (file, "_Android") && ! exporter.isAndroid()))
  349. return false;
  350. const ProjectType::Target::Type targetType = Project::getTargetTypeFromFilePath (file, false);
  351. if (targetType != ProjectType::Target::unspecified && ! exporter.shouldBuildTargetType (targetType))
  352. return false;
  353. return exporter.usesMMFiles() ? isCompiledForObjC
  354. : isCompiledForNonObjC;
  355. }
  356. Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits() const
  357. {
  358. Array<File> files;
  359. getFolder().findChildFiles (files, File::findFiles, false);
  360. FileSorter sorter;
  361. files.sort (sorter);
  362. Array<LibraryModule::CompileUnit> units;
  363. for (int i = 0; i < files.size(); ++i)
  364. {
  365. CompileUnit cu;
  366. cu.file = files.getReference(i);
  367. if (cu.file.getFileName().startsWithIgnoreCase (getID())
  368. && cu.file.hasFileExtension (sourceFileExtensions))
  369. {
  370. units.add (cu);
  371. }
  372. }
  373. for (int i = 0; i < units.size(); ++i)
  374. {
  375. CompileUnit& cu = units.getReference(i);
  376. cu.isCompiledForObjC = true;
  377. cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m");
  378. if (cu.isCompiledForNonObjC)
  379. if (files.contains (cu.file.withFileExtension ("mm")))
  380. cu.isCompiledForObjC = false;
  381. jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
  382. }
  383. return units;
  384. }
  385. void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter,
  386. ProjectSaver* projectSaver,
  387. Array<File>& result) const
  388. {
  389. Array<CompileUnit> units = getAllCompileUnits();
  390. for (int i = 0; i < units.size(); ++i)
  391. {
  392. const CompileUnit& cu = units.getReference(i);
  393. if (cu.isNeededForExporter (exporter))
  394. {
  395. File localFile = exporter.getProject().getGeneratedCodeFolder().getChildFile (cu.file.getFileName());
  396. result.add (localFile);
  397. if (projectSaver != nullptr)
  398. projectSaver->addFileToGeneratedGroup (localFile);
  399. }
  400. }
  401. }
  402. static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path)
  403. {
  404. const int slash = path.indexOfChar (File::separator);
  405. if (slash >= 0)
  406. {
  407. const String topLevelGroup (path.substring (0, slash));
  408. const String remainingPath (path.substring (slash + 1));
  409. Project::Item newGroup (group.getOrCreateSubGroup (topLevelGroup));
  410. addFileWithGroups (newGroup, file, remainingPath);
  411. }
  412. else
  413. {
  414. if (! group.containsChildForFile (file))
  415. group.addRelativeFile (file, -1, false);
  416. }
  417. }
  418. void LibraryModule::findBrowseableFiles (const File& folder, Array<File>& filesFound) const
  419. {
  420. Array<File> tempList;
  421. FileSorter sorter;
  422. DirectoryIterator iter (folder, true, "*", File::findFiles);
  423. bool isHiddenFile;
  424. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  425. if (! isHiddenFile && iter.getFile().hasFileExtension (browseableFileExtensions))
  426. tempList.addSorted (sorter, iter.getFile());
  427. filesFound.addArray (tempList);
  428. }
  429. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  430. {
  431. if (sourceFiles.size() == 0)
  432. findBrowseableFiles (localModuleFolder, sourceFiles);
  433. Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false));
  434. const RelativePath moduleFromProject (exporter.getModuleFolderRelativeToProject (getID()));
  435. for (int i = 0; i < sourceFiles.size(); ++i)
  436. {
  437. const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder));
  438. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  439. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  440. if (exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFiles.getReference(i)))
  441. addFileWithGroups (sourceGroup,
  442. moduleFromProject.getChildFile (pathWithinModule),
  443. pathWithinModule);
  444. }
  445. sourceGroup.sortAlphabetically (true, true);
  446. sourceGroup.addFileAtIndex (moduleInfo.getHeader(), -1, false);
  447. exporter.getModulesGroup().state.addChild (sourceGroup.state.createCopy(), -1, nullptr);
  448. }
  449. //==============================================================================
  450. EnabledModuleList::EnabledModuleList (Project& p, const ValueTree& s)
  451. : project (p), state (s)
  452. {
  453. }
  454. ModuleDescription EnabledModuleList::getModuleInfo (const String& moduleID)
  455. {
  456. return ModuleDescription (getModuleFolder (moduleID));
  457. }
  458. bool EnabledModuleList::isModuleEnabled (const String& moduleID) const
  459. {
  460. for (int i = 0; i < state.getNumChildren(); ++i)
  461. if (state.getChild(i) [Ids::ID] == moduleID)
  462. return true;
  463. return false;
  464. }
  465. bool EnabledModuleList::isAudioPluginModuleMissing() const
  466. {
  467. return project.getProjectType().isAudioPlugin()
  468. && ! isModuleEnabled ("juce_audio_plugin_client");
  469. }
  470. Value EnabledModuleList::shouldShowAllModuleFilesInProject (const String& moduleID)
  471. {
  472. return state.getChildWithProperty (Ids::ID, moduleID)
  473. .getPropertyAsValue (Ids::showAllCode, getUndoManager());
  474. }
  475. File EnabledModuleList::findLocalModuleFolder (const String& moduleID, bool useExportersForOtherOSes)
  476. {
  477. for (Project::ExporterIterator exporter (project); exporter.next();)
  478. {
  479. if (useExportersForOtherOSes || exporter->mayCompileOnCurrentOS())
  480. {
  481. const String path (exporter->getPathForModuleString (moduleID));
  482. if (path.isNotEmpty())
  483. {
  484. const File moduleFolder (project.resolveFilename (path));
  485. if (moduleFolder.exists())
  486. {
  487. if (ModuleDescription (moduleFolder).isValid())
  488. return moduleFolder;
  489. File f = moduleFolder.getChildFile (moduleID);
  490. if (ModuleDescription (f).isValid())
  491. return f;
  492. }
  493. }
  494. }
  495. }
  496. return File();
  497. }
  498. File EnabledModuleList::getModuleFolder (const String& moduleID)
  499. {
  500. File f = findLocalModuleFolder (moduleID, false);
  501. if (f == File())
  502. f = findLocalModuleFolder (moduleID, true);
  503. return f;
  504. }
  505. struct ModuleTreeSorter
  506. {
  507. static int compareElements (const ValueTree& m1, const ValueTree& m2)
  508. {
  509. return m1[Ids::ID].toString().compareIgnoreCase (m2[Ids::ID]);
  510. }
  511. };
  512. void EnabledModuleList::sortAlphabetically()
  513. {
  514. ModuleTreeSorter sorter;
  515. state.sort (sorter, getUndoManager(), false);
  516. }
  517. Value EnabledModuleList::shouldCopyModuleFilesLocally (const String& moduleID) const
  518. {
  519. return state.getChildWithProperty (Ids::ID, moduleID)
  520. .getPropertyAsValue (Ids::useLocalCopy, getUndoManager());
  521. }
  522. void EnabledModuleList::addModule (const File& moduleFolder, bool copyLocally)
  523. {
  524. ModuleDescription info (moduleFolder);
  525. if (info.isValid())
  526. {
  527. const String moduleID (info.getID());
  528. if (! isModuleEnabled (moduleID))
  529. {
  530. ValueTree module (Ids::MODULE);
  531. module.setProperty (Ids::ID, moduleID, nullptr);
  532. state.addChild (module, -1, getUndoManager());
  533. sortAlphabetically();
  534. shouldShowAllModuleFilesInProject (moduleID) = true;
  535. shouldCopyModuleFilesLocally (moduleID) = copyLocally;
  536. RelativePath path (moduleFolder.getParentDirectory(),
  537. project.getProjectFolder(), RelativePath::projectFolder);
  538. for (Project::ExporterIterator exporter (project); exporter.next();)
  539. exporter->getPathForModuleValue (moduleID) = path.toUnixStyle();
  540. }
  541. }
  542. }
  543. void EnabledModuleList::removeModule (String moduleID) // must be pass-by-value, and not a const ref!
  544. {
  545. for (int i = state.getNumChildren(); --i >= 0;)
  546. if (state.getChild(i) [Ids::ID] == moduleID)
  547. state.removeChild (i, getUndoManager());
  548. for (Project::ExporterIterator exporter (project); exporter.next();)
  549. exporter->removePathForModule (moduleID);
  550. }
  551. void EnabledModuleList::createRequiredModules (OwnedArray<LibraryModule>& modules)
  552. {
  553. for (int i = 0; i < getNumModules(); ++i)
  554. modules.add (new LibraryModule (getModuleInfo (getModuleID (i))));
  555. }
  556. StringArray EnabledModuleList::getAllModules() const
  557. {
  558. StringArray moduleIDs;
  559. for (int i = 0; i < getNumModules(); ++i)
  560. moduleIDs.add (getModuleID(i));
  561. return moduleIDs;
  562. }
  563. static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies)
  564. {
  565. ModuleDescription info (project.getModules().getModuleInfo (moduleID));
  566. for (auto uid : info.getDependencies())
  567. {
  568. if (! dependencies.contains (uid, true))
  569. {
  570. dependencies.add (uid);
  571. getDependencies (project, uid, dependencies);
  572. }
  573. }
  574. }
  575. StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const
  576. {
  577. StringArray dependencies, extraDepsNeeded;
  578. getDependencies (project, moduleID, dependencies);
  579. for (auto dep : dependencies)
  580. if (dep != moduleID && ! isModuleEnabled (dep))
  581. extraDepsNeeded.add (dep);
  582. return extraDepsNeeded;
  583. }
  584. bool EnabledModuleList::areMostModulesCopiedLocally() const
  585. {
  586. int numYes = 0, numNo = 0;
  587. for (int i = getNumModules(); --i >= 0;)
  588. {
  589. if (shouldCopyModuleFilesLocally (getModuleID (i)).getValue())
  590. ++numYes;
  591. else
  592. ++numNo;
  593. }
  594. return numYes > numNo;
  595. }
  596. void EnabledModuleList::setLocalCopyModeForAllModules (bool copyLocally)
  597. {
  598. for (int i = getNumModules(); --i >= 0;)
  599. shouldCopyModuleFilesLocally (project.getModules().getModuleID (i)) = copyLocally;
  600. }
  601. File EnabledModuleList::findDefaultModulesFolder (Project& project)
  602. {
  603. ModuleList available;
  604. available.scanAllKnownFolders (project);
  605. for (int i = available.modules.size(); --i >= 0;)
  606. {
  607. File f (available.modules.getUnchecked(i)->getFolder());
  608. if (f.isDirectory())
  609. return f.getParentDirectory();
  610. }
  611. return File::getCurrentWorkingDirectory();
  612. }
  613. void EnabledModuleList::addModuleFromUserSelectedFile()
  614. {
  615. static File lastLocation (findDefaultModulesFolder (project));
  616. FileChooser fc ("Select a module to add...", lastLocation, String(), false);
  617. if (fc.browseForDirectory())
  618. {
  619. lastLocation = fc.getResult();
  620. addModuleOfferingToCopy (lastLocation);
  621. }
  622. }
  623. void EnabledModuleList::addModuleInteractive (const String& moduleID)
  624. {
  625. ModuleList list;
  626. list.scanAllKnownFolders (project);
  627. if (const ModuleDescription* info = list.getModuleWithID (moduleID))
  628. addModule (info->moduleFolder, areMostModulesCopiedLocally());
  629. else
  630. addModuleFromUserSelectedFile();
  631. }
  632. void EnabledModuleList::addModuleOfferingToCopy (const File& f)
  633. {
  634. ModuleDescription m (f);
  635. if (! m.isValid())
  636. {
  637. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  638. "Add Module", "This wasn't a valid module folder!");
  639. return;
  640. }
  641. if (isModuleEnabled (m.getID()))
  642. {
  643. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  644. "Add Module", "The project already contains this module!");
  645. return;
  646. }
  647. addModule (m.moduleFolder, areMostModulesCopiedLocally());
  648. }
  649. bool isJuceFolder (const File& f)
  650. {
  651. return isJuceModulesFolder (f.getChildFile ("modules"));
  652. }
  653. bool isJuceModulesFolder (const File& f)
  654. {
  655. return f.isDirectory() && f.getChildFile ("juce_core").isDirectory();
  656. }