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.

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