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.

824 lines
27KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../Application/jucer_Headers.h"
  20. #include "../ProjectSaving/jucer_ProjectSaver.h"
  21. #include "../ProjectSaving/jucer_ProjectExport_Xcode.h"
  22. #include "../Application/jucer_Application.h"
  23. //==============================================================================
  24. ModuleDescription::ModuleDescription (const File& folder)
  25. : moduleFolder (folder),
  26. moduleInfo (parseJUCEHeaderMetadata (getHeader()))
  27. {
  28. }
  29. File ModuleDescription::getHeader() const
  30. {
  31. if (moduleFolder != File())
  32. {
  33. const char* extensions[] = { ".h", ".hpp", ".hxx" };
  34. for (auto e : extensions)
  35. {
  36. auto header = moduleFolder.getChildFile (moduleFolder.getFileName() + e);
  37. if (header.existsAsFile())
  38. return header;
  39. }
  40. }
  41. return {};
  42. }
  43. StringArray ModuleDescription::getDependencies() const
  44. {
  45. auto deps = StringArray::fromTokens (moduleInfo ["dependencies"].toString(), " \t;,", "\"'");
  46. deps.trim();
  47. deps.removeEmptyStrings();
  48. return deps;
  49. }
  50. //==============================================================================
  51. static bool tryToAddModuleFromFolder (const File& path, ModuleIDAndFolderList& list)
  52. {
  53. ModuleDescription m (path);
  54. if (m.isValid())
  55. {
  56. list.push_back ({ m.getID(), path });
  57. return true;
  58. }
  59. return false;
  60. }
  61. static void addAllModulesInSubfoldersRecursively (const File& path, int depth, ModuleIDAndFolderList& list)
  62. {
  63. if (depth > 0)
  64. {
  65. for (DirectoryIterator iter (path, false, "*", File::findDirectories); iter.next();)
  66. {
  67. if (auto* job = ThreadPoolJob::getCurrentThreadPoolJob())
  68. if (job->shouldExit())
  69. return;
  70. auto childPath = iter.getFile();
  71. if (! tryToAddModuleFromFolder (childPath, list))
  72. addAllModulesInSubfoldersRecursively (childPath, depth - 1, list);
  73. }
  74. }
  75. }
  76. static void addAllModulesInFolder (const File& path, ModuleIDAndFolderList& list)
  77. {
  78. if (! tryToAddModuleFromFolder (path, list))
  79. {
  80. int subfolders = 3;
  81. addAllModulesInSubfoldersRecursively (path, subfolders, list);
  82. }
  83. }
  84. static void sort (ModuleIDAndFolderList& listToSort)
  85. {
  86. std::sort (listToSort.begin(), listToSort.end(), [] (const ModuleIDAndFolder& m1, const ModuleIDAndFolder& m2)
  87. {
  88. return m1.first.compareIgnoreCase (m2.first) < 0;
  89. });
  90. }
  91. //==============================================================================
  92. struct ModuleScannerJob : public ThreadPoolJob
  93. {
  94. ModuleScannerJob (const Array<File>& paths, std::function<void (const ModuleIDAndFolderList&)>&& callback)
  95. : ThreadPoolJob ("ModuleScannerJob"),
  96. pathsToScan (paths),
  97. completionCallback (std::move (callback))
  98. {
  99. }
  100. JobStatus runJob() override
  101. {
  102. ModuleIDAndFolderList list;
  103. for (auto& p : pathsToScan)
  104. addAllModulesInFolder (p, list);
  105. if (! shouldExit())
  106. {
  107. sort (list);
  108. completionCallback (list);
  109. }
  110. return jobHasFinished;
  111. }
  112. Array<File> pathsToScan;
  113. std::function<void (const ModuleIDAndFolderList&)> completionCallback;
  114. };
  115. AvailableModuleList::AvailableModuleList()
  116. {
  117. }
  118. ThreadPoolJob* AvailableModuleList::createScannerJob (const Array<File>& paths)
  119. {
  120. return new ModuleScannerJob (paths, [this] (ModuleIDAndFolderList scannedModuleList)
  121. {
  122. {
  123. const ScopedLock swapLock (lock);
  124. moduleList.swap (scannedModuleList);
  125. }
  126. listeners.call ([] (Listener& l) { MessageManager::callAsync ([&] { l.availableModulesChanged(); }); });
  127. });
  128. }
  129. void AvailableModuleList::removePendingAndAddJob (ThreadPoolJob* jobToAdd)
  130. {
  131. scanPool.removeAllJobs (false, 100);
  132. scanPool.addJob (jobToAdd, true);
  133. }
  134. void AvailableModuleList::scanPaths (const Array<File>& paths)
  135. {
  136. auto* job = createScannerJob (paths);
  137. removePendingAndAddJob (job);
  138. scanPool.waitForJobToFinish (job, -1);
  139. }
  140. void AvailableModuleList::scanPathsAsync (const Array<File>& paths)
  141. {
  142. removePendingAndAddJob (createScannerJob (paths));
  143. }
  144. ModuleIDAndFolderList AvailableModuleList::getAllModules() const
  145. {
  146. const ScopedLock readLock (lock);
  147. return moduleList;
  148. }
  149. ModuleIDAndFolder AvailableModuleList::getModuleWithID (const String& id) const
  150. {
  151. const ScopedLock readLock (lock);
  152. for (auto& mod : moduleList)
  153. if (mod.first == id)
  154. return mod;
  155. return {};
  156. }
  157. void AvailableModuleList::removeDuplicates (const ModuleIDAndFolderList& other)
  158. {
  159. const ScopedLock readLock (lock);
  160. for (auto& m : other)
  161. {
  162. auto pos = std::find (moduleList.begin(), moduleList.end(), m);
  163. if (pos != moduleList.end())
  164. moduleList.erase (pos);
  165. }
  166. }
  167. //==============================================================================
  168. LibraryModule::LibraryModule (const ModuleDescription& d)
  169. : moduleInfo (d)
  170. {
  171. }
  172. //==============================================================================
  173. void LibraryModule::writeIncludes (ProjectSaver& projectSaver, OutputStream& out)
  174. {
  175. auto& project = projectSaver.project;
  176. auto& modules = project.getEnabledModules();
  177. auto id = getID();
  178. if (modules.shouldCopyModuleFilesLocally (id).getValue())
  179. {
  180. auto juceModuleFolder = moduleInfo.getFolder();
  181. auto localModuleFolder = project.getLocalModuleFolder (id);
  182. localModuleFolder.createDirectory();
  183. projectSaver.copyFolder (juceModuleFolder, localModuleFolder);
  184. }
  185. out << "#include <" << moduleInfo.moduleFolder.getFileName() << "/"
  186. << moduleInfo.getHeader().getFileName()
  187. << ">" << newLine;
  188. }
  189. //==============================================================================
  190. static void parseAndAddLibs (StringArray& libList, const String& libs)
  191. {
  192. libList.addTokens (libs, ", ", {});
  193. libList.trim();
  194. libList.sort (false);
  195. libList.removeDuplicates (false);
  196. }
  197. void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  198. {
  199. auto& project = exporter.getProject();
  200. auto moduleRelativePath = exporter.getModuleFolderRelativeToProject (getID());
  201. exporter.addToExtraSearchPaths (moduleRelativePath.getParentDirectory());
  202. String libDirPlatform;
  203. if (exporter.isLinux())
  204. libDirPlatform = "Linux";
  205. else if (exporter.isCodeBlocks() && exporter.isWindows())
  206. libDirPlatform = "MinGW";
  207. else
  208. libDirPlatform = exporter.getTargetFolder().getFileName();
  209. auto libSubdirPath = moduleRelativePath.toUnixStyle() + "/libs/" + libDirPlatform;
  210. auto moduleLibDir = File (project.getProjectFolder().getFullPathName() + "/" + libSubdirPath);
  211. if (moduleLibDir.exists())
  212. exporter.addToModuleLibPaths ({ libSubdirPath, moduleRelativePath.getRoot() });
  213. auto extraInternalSearchPaths = moduleInfo.getExtraSearchPaths().trim();
  214. if (extraInternalSearchPaths.isNotEmpty())
  215. {
  216. auto paths = StringArray::fromTokens (extraInternalSearchPaths, true);
  217. for (auto& path : paths)
  218. exporter.addToExtraSearchPaths (moduleRelativePath.getChildFile (path.unquoted()));
  219. }
  220. {
  221. auto extraDefs = moduleInfo.getPreprocessorDefs().trim();
  222. if (extraDefs.isNotEmpty())
  223. exporter.getExporterPreprocessorDefsValue() = exporter.getExporterPreprocessorDefsString() + "\n" + extraDefs;
  224. }
  225. {
  226. Array<File> compiled;
  227. auto& modules = project.getEnabledModules();
  228. auto id = getID();
  229. auto localModuleFolder = modules.shouldCopyModuleFilesLocally (id).getValue() ? project.getLocalModuleFolder (id)
  230. : moduleInfo.getFolder();
  231. findAndAddCompiledUnits (exporter, &projectSaver, compiled);
  232. if (modules.shouldShowAllModuleFilesInProject (id).getValue())
  233. addBrowseableCode (exporter, compiled, localModuleFolder);
  234. }
  235. if (exporter.isXcode())
  236. {
  237. auto& xcodeExporter = dynamic_cast<XcodeProjectExporter&> (exporter);
  238. if (project.isAUPluginHost())
  239. xcodeExporter.xcodeFrameworks.addTokens (xcodeExporter.isOSX() ? "AudioUnit CoreAudioKit" : "CoreAudioKit", false);
  240. auto frameworks = moduleInfo.moduleInfo [xcodeExporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString();
  241. xcodeExporter.xcodeFrameworks.addTokens (frameworks, ", ", {});
  242. parseAndAddLibs (xcodeExporter.xcodeLibs, moduleInfo.moduleInfo [exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString());
  243. }
  244. else if (exporter.isLinux())
  245. {
  246. parseAndAddLibs (exporter.linuxLibs, moduleInfo.moduleInfo ["linuxLibs"].toString());
  247. parseAndAddLibs (exporter.linuxPackages, moduleInfo.moduleInfo ["linuxPackages"].toString());
  248. }
  249. else if (exporter.isWindows())
  250. {
  251. if (exporter.isCodeBlocks())
  252. parseAndAddLibs (exporter.mingwLibs, moduleInfo.moduleInfo ["mingwLibs"].toString());
  253. else
  254. parseAndAddLibs (exporter.windowsLibs, moduleInfo.moduleInfo ["windowsLibs"].toString());
  255. }
  256. else if (exporter.isAndroid())
  257. {
  258. parseAndAddLibs (exporter.androidLibs, moduleInfo.moduleInfo ["androidLibs"].toString());
  259. }
  260. }
  261. void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
  262. {
  263. auto header = moduleInfo.getHeader();
  264. jassert (header.exists());
  265. StringArray lines;
  266. header.readLines (lines);
  267. for (int i = 0; i < lines.size(); ++i)
  268. {
  269. auto line = lines[i].trim();
  270. if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
  271. {
  272. std::unique_ptr<Project::ConfigFlag> config (new Project::ConfigFlag());
  273. config->sourceModuleID = getID();
  274. config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
  275. if (config->symbol.length() > 2)
  276. {
  277. ++i;
  278. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  279. {
  280. if (lines[i].trim().isNotEmpty())
  281. config->description = config->description.trim() + " " + lines[i].trim();
  282. ++i;
  283. }
  284. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  285. config->value = project.getConfigFlag (config->symbol);
  286. i += 2;
  287. if (lines[i].contains ("#define " + config->symbol))
  288. {
  289. auto value = lines[i].fromFirstOccurrenceOf ("#define " + config->symbol, false, true).trim();
  290. config->value.setDefault (value == "0" ? false : true);
  291. }
  292. auto currentValue = config->value.get().toString();
  293. if (currentValue == "enabled") config->value = true;
  294. else if (currentValue == "disabled") config->value = false;
  295. flags.add (config.release());
  296. }
  297. }
  298. }
  299. }
  300. //==============================================================================
  301. struct FileSorter
  302. {
  303. static int compareElements (const File& f1, const File& f2)
  304. {
  305. return f1.getFileName().compareNatural (f2.getFileName());
  306. }
  307. };
  308. bool LibraryModule::CompileUnit::hasSuffix (const File& f, const char* suffix)
  309. {
  310. auto fileWithoutSuffix = f.getFileNameWithoutExtension() + ".";
  311. return fileWithoutSuffix.containsIgnoreCase (suffix + String ("."))
  312. || fileWithoutSuffix.containsIgnoreCase (suffix + String ("_"));
  313. }
  314. void LibraryModule::CompileUnit::writeInclude (MemoryOutputStream&) const
  315. {
  316. }
  317. bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const
  318. {
  319. if ((hasSuffix (file, "_OSX") && ! exporter.isOSX())
  320. || (hasSuffix (file, "_iOS") && ! exporter.isiOS())
  321. || (hasSuffix (file, "_Windows") && ! exporter.isWindows())
  322. || (hasSuffix (file, "_Linux") && ! exporter.isLinux())
  323. || (hasSuffix (file, "_Android") && ! exporter.isAndroid()))
  324. return false;
  325. auto targetType = Project::getTargetTypeFromFilePath (file, false);
  326. if (targetType != ProjectType::Target::unspecified && ! exporter.shouldBuildTargetType (targetType))
  327. return false;
  328. return exporter.usesMMFiles() ? isCompiledForObjC
  329. : isCompiledForNonObjC;
  330. }
  331. String LibraryModule::CompileUnit::getFilenameForProxyFile() const
  332. {
  333. return "include_" + file.getFileName();
  334. }
  335. Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits (ProjectType::Target::Type forTarget) const
  336. {
  337. auto files = getFolder().findChildFiles (File::findFiles, false);
  338. FileSorter sorter;
  339. files.sort (sorter);
  340. Array<LibraryModule::CompileUnit> units;
  341. for (auto& file : files)
  342. {
  343. if (file.getFileName().startsWithIgnoreCase (getID())
  344. && file.hasFileExtension (sourceFileExtensions))
  345. {
  346. if (forTarget == ProjectType::Target::unspecified
  347. || forTarget == Project::getTargetTypeFromFilePath (file, true))
  348. {
  349. CompileUnit cu;
  350. cu.file = file;
  351. units.add (cu);
  352. }
  353. }
  354. }
  355. for (auto& cu : units)
  356. {
  357. cu.isCompiledForObjC = true;
  358. cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m");
  359. if (cu.isCompiledForNonObjC)
  360. if (files.contains (cu.file.withFileExtension ("mm")))
  361. cu.isCompiledForObjC = false;
  362. jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
  363. }
  364. return units;
  365. }
  366. void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter,
  367. ProjectSaver* projectSaver,
  368. Array<File>& result,
  369. ProjectType::Target::Type forTarget) const
  370. {
  371. for (auto& cu : getAllCompileUnits (forTarget))
  372. {
  373. if (cu.isNeededForExporter (exporter))
  374. {
  375. auto localFile = exporter.getProject().getGeneratedCodeFolder()
  376. .getChildFile (cu.getFilenameForProxyFile());
  377. result.add (localFile);
  378. if (projectSaver != nullptr)
  379. projectSaver->addFileToGeneratedGroup (localFile);
  380. }
  381. }
  382. }
  383. static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path)
  384. {
  385. auto slash = path.indexOfChar (File::getSeparatorChar());
  386. if (slash >= 0)
  387. {
  388. auto topLevelGroup = path.substring (0, slash);
  389. auto remainingPath = path.substring (slash + 1);
  390. auto newGroup = group.getOrCreateSubGroup (topLevelGroup);
  391. addFileWithGroups (newGroup, file, remainingPath);
  392. }
  393. else
  394. {
  395. if (! group.containsChildForFile (file))
  396. group.addRelativeFile (file, -1, false);
  397. }
  398. }
  399. void LibraryModule::findBrowseableFiles (const File& folder, Array<File>& filesFound) const
  400. {
  401. Array<File> tempList;
  402. FileSorter sorter;
  403. DirectoryIterator iter (folder, true, "*", File::findFiles);
  404. bool isHiddenFile;
  405. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  406. if (! isHiddenFile && iter.getFile().hasFileExtension (browseableFileExtensions))
  407. tempList.addSorted (sorter, iter.getFile());
  408. filesFound.addArray (tempList);
  409. }
  410. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  411. {
  412. if (sourceFiles.isEmpty())
  413. findBrowseableFiles (localModuleFolder, sourceFiles);
  414. auto sourceGroup = Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false);
  415. auto moduleFromProject = exporter.getModuleFolderRelativeToProject (getID());
  416. auto moduleHeader = moduleInfo.getHeader();
  417. for (auto& sourceFile : sourceFiles)
  418. {
  419. auto pathWithinModule = FileHelpers::getRelativePathFrom (sourceFile, localModuleFolder);
  420. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  421. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  422. if ((exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFile)) && sourceFile != moduleHeader)
  423. addFileWithGroups (sourceGroup,
  424. moduleFromProject.getChildFile (pathWithinModule),
  425. pathWithinModule);
  426. }
  427. sourceGroup.sortAlphabetically (true, true);
  428. sourceGroup.addFileAtIndex (moduleHeader, -1, false);
  429. exporter.getModulesGroup().state.appendChild (sourceGroup.state.createCopy(), nullptr);
  430. }
  431. //==============================================================================
  432. EnabledModuleList::EnabledModuleList (Project& p, const ValueTree& s)
  433. : project (p), state (s)
  434. {
  435. }
  436. ModuleDescription EnabledModuleList::getModuleInfo (const String& moduleID)
  437. {
  438. return ModuleDescription (project.getModuleWithID (moduleID).second);
  439. }
  440. bool EnabledModuleList::isModuleEnabled (const String& moduleID) const
  441. {
  442. return state.getChildWithProperty (Ids::ID, moduleID).isValid();
  443. }
  444. bool EnabledModuleList::isAudioPluginModuleMissing() const
  445. {
  446. return project.getProjectType().isAudioPlugin()
  447. && ! isModuleEnabled ("juce_audio_plugin_client");
  448. }
  449. bool EnabledModuleList::shouldUseGlobalPath (const String& moduleID) const
  450. {
  451. return static_cast<bool> (state.getChildWithProperty (Ids::ID, moduleID)
  452. .getProperty (Ids::useGlobalPath));
  453. }
  454. Value EnabledModuleList::getShouldUseGlobalPathValue (const String& moduleID) const
  455. {
  456. return state.getChildWithProperty (Ids::ID, moduleID)
  457. .getPropertyAsValue (Ids::useGlobalPath, getUndoManager());
  458. }
  459. Value EnabledModuleList::shouldShowAllModuleFilesInProject (const String& moduleID)
  460. {
  461. return state.getChildWithProperty (Ids::ID, moduleID)
  462. .getPropertyAsValue (Ids::showAllCode, getUndoManager());
  463. }
  464. struct ModuleTreeSorter
  465. {
  466. static int compareElements (const ValueTree& m1, const ValueTree& m2)
  467. {
  468. return m1[Ids::ID].toString().compareIgnoreCase (m2[Ids::ID]);
  469. }
  470. };
  471. void EnabledModuleList::sortAlphabetically()
  472. {
  473. ModuleTreeSorter sorter;
  474. state.sort (sorter, getUndoManager(), false);
  475. }
  476. Value EnabledModuleList::shouldCopyModuleFilesLocally (const String& moduleID) const
  477. {
  478. return state.getChildWithProperty (Ids::ID, moduleID)
  479. .getPropertyAsValue (Ids::useLocalCopy, getUndoManager());
  480. }
  481. void EnabledModuleList::addModule (const File& moduleFolder, bool copyLocally, bool useGlobalPath, bool sendAnalyticsEvent)
  482. {
  483. ModuleDescription info (moduleFolder);
  484. if (info.isValid())
  485. {
  486. auto moduleID = info.getID();
  487. if (! isModuleEnabled (moduleID))
  488. {
  489. ValueTree module (Ids::MODULE);
  490. module.setProperty (Ids::ID, moduleID, getUndoManager());
  491. state.appendChild (module, getUndoManager());
  492. sortAlphabetically();
  493. shouldShowAllModuleFilesInProject (moduleID) = true;
  494. shouldCopyModuleFilesLocally (moduleID) = copyLocally;
  495. getShouldUseGlobalPathValue (moduleID) = useGlobalPath;
  496. RelativePath path (moduleFolder.getParentDirectory(),
  497. project.getProjectFolder(), RelativePath::projectFolder);
  498. for (Project::ExporterIterator exporter (project); exporter.next();)
  499. exporter->getPathForModuleValue (moduleID) = path.toUnixStyle();
  500. if (! useGlobalPath)
  501. project.rescanExporterPathModules (false);
  502. if (sendAnalyticsEvent)
  503. {
  504. StringPairArray data;
  505. data.set ("label", moduleID);
  506. Analytics::getInstance()->logEvent ("Module Added", data, ProjucerAnalyticsEvent::projectEvent);
  507. }
  508. }
  509. }
  510. }
  511. void EnabledModuleList::removeModule (String moduleID) // must be pass-by-value, and not a const ref!
  512. {
  513. for (auto i = state.getNumChildren(); --i >= 0;)
  514. if (state.getChild(i) [Ids::ID] == moduleID)
  515. state.removeChild (i, getUndoManager());
  516. for (Project::ExporterIterator exporter (project); exporter.next();)
  517. exporter->removePathForModule (moduleID);
  518. }
  519. void EnabledModuleList::createRequiredModules (OwnedArray<LibraryModule>& modules)
  520. {
  521. for (int i = 0; i < getNumModules(); ++i)
  522. modules.add (new LibraryModule (getModuleInfo (getModuleID (i))));
  523. }
  524. StringArray EnabledModuleList::getAllModules() const
  525. {
  526. StringArray moduleIDs;
  527. for (int i = 0; i < getNumModules(); ++i)
  528. moduleIDs.add (getModuleID (i));
  529. return moduleIDs;
  530. }
  531. static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies)
  532. {
  533. auto info = project.getEnabledModules().getModuleInfo (moduleID);
  534. for (auto uid : info.getDependencies())
  535. {
  536. if (! dependencies.contains (uid, true))
  537. {
  538. dependencies.add (uid);
  539. getDependencies (project, uid, dependencies);
  540. }
  541. }
  542. }
  543. StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const
  544. {
  545. StringArray dependencies, extraDepsNeeded;
  546. getDependencies (project, moduleID, dependencies);
  547. for (auto dep : dependencies)
  548. if (dep != moduleID && ! isModuleEnabled (dep))
  549. extraDepsNeeded.add (dep);
  550. return extraDepsNeeded;
  551. }
  552. bool EnabledModuleList::doesModuleHaveHigherCppStandardThanProject (const String& moduleID)
  553. {
  554. auto projectCppStandard = project.getCppStandardString();
  555. if (projectCppStandard == "latest")
  556. return false;
  557. auto moduleCppStandard = getModuleInfo (moduleID).getMinimumCppStandard();
  558. return (moduleCppStandard.getIntValue() > projectCppStandard.getIntValue());
  559. }
  560. bool EnabledModuleList::areMostModulesUsingGlobalPath() const
  561. {
  562. int numYes = 0, numNo = 0;
  563. for (auto i = getNumModules(); --i >= 0;)
  564. {
  565. if (shouldUseGlobalPath (getModuleID (i)))
  566. ++numYes;
  567. else
  568. ++numNo;
  569. }
  570. return numYes > numNo;
  571. }
  572. bool EnabledModuleList::areMostModulesCopiedLocally() const
  573. {
  574. int numYes = 0, numNo = 0;
  575. for (auto i = getNumModules(); --i >= 0;)
  576. {
  577. if (shouldCopyModuleFilesLocally (getModuleID (i)).getValue())
  578. ++numYes;
  579. else
  580. ++numNo;
  581. }
  582. return numYes > numNo;
  583. }
  584. void EnabledModuleList::setLocalCopyModeForAllModules (bool copyLocally)
  585. {
  586. for (auto i = getNumModules(); --i >= 0;)
  587. shouldCopyModuleFilesLocally (project.getEnabledModules().getModuleID (i)) = copyLocally;
  588. }
  589. File EnabledModuleList::findDefaultModulesFolder (Project& project)
  590. {
  591. File globalPath (getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get().toString());
  592. if (globalPath.exists())
  593. return globalPath;
  594. for (auto& exporterPathModule : project.getExporterPathsModuleList().getAllModules())
  595. {
  596. auto f = exporterPathModule.second;
  597. if (f.isDirectory())
  598. return f.getParentDirectory();
  599. }
  600. return File::getCurrentWorkingDirectory();
  601. }
  602. void EnabledModuleList::addModuleFromUserSelectedFile()
  603. {
  604. static auto lastLocation = findDefaultModulesFolder (project);
  605. FileChooser fc ("Select a module to add...", lastLocation, {});
  606. if (fc.browseForDirectory())
  607. {
  608. lastLocation = fc.getResult();
  609. addModuleOfferingToCopy (lastLocation, true);
  610. }
  611. }
  612. void EnabledModuleList::addModuleInteractive (const String& moduleID)
  613. {
  614. auto f = project.getModuleWithID (moduleID).second;
  615. if (f != File())
  616. {
  617. addModule (f, areMostModulesCopiedLocally(), areMostModulesUsingGlobalPath(), true);
  618. return;
  619. }
  620. addModuleFromUserSelectedFile();
  621. }
  622. void EnabledModuleList::addModuleOfferingToCopy (const File& f, bool isFromUserSpecifiedFolder)
  623. {
  624. ModuleDescription m (f);
  625. if (! m.isValid())
  626. {
  627. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  628. "Add Module", "This wasn't a valid module folder!");
  629. return;
  630. }
  631. if (isModuleEnabled (m.getID()))
  632. {
  633. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  634. "Add Module", "The project already contains this module!");
  635. return;
  636. }
  637. addModule (m.moduleFolder, areMostModulesCopiedLocally(),
  638. isFromUserSpecifiedFolder ? false : areMostModulesUsingGlobalPath(),
  639. true);
  640. }
  641. bool isJUCEFolder (const File& f)
  642. {
  643. return isJUCEModulesFolder (f.getChildFile ("modules"));
  644. }
  645. bool isJUCEModulesFolder (const File& f)
  646. {
  647. return f.isDirectory() && f.getChildFile ("juce_core").isDirectory();
  648. }