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