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.

203 lines
8.0KB

  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. #pragma once
  20. #include "jucer_Project.h"
  21. class ProjectExporter;
  22. class ProjectSaver;
  23. //==============================================================================
  24. struct ModuleDescription
  25. {
  26. ModuleDescription() = default;
  27. ModuleDescription (const File& folder);
  28. bool isValid() const { return getID().isNotEmpty(); }
  29. String getID() const { return moduleInfo [Ids::ID_uppercase].toString(); }
  30. String getVendor() const { return moduleInfo [Ids::vendor].toString(); }
  31. String getVersion() const { return moduleInfo [Ids::version].toString(); }
  32. String getName() const { return moduleInfo [Ids::name].toString(); }
  33. String getDescription() const { return moduleInfo [Ids::description].toString(); }
  34. String getLicense() const { return moduleInfo [Ids::license].toString(); }
  35. String getMinimumCppStandard() const { return moduleInfo [Ids::minimumCppStandard].toString(); }
  36. String getPreprocessorDefs() const { return moduleInfo [Ids::defines].toString(); }
  37. String getExtraSearchPaths() const { return moduleInfo [Ids::searchpaths].toString(); }
  38. StringArray getDependencies() const;
  39. File getFolder() const { jassert (moduleFolder != File()); return moduleFolder; }
  40. File getHeader() const;
  41. File moduleFolder;
  42. var moduleInfo;
  43. URL url;
  44. };
  45. //==============================================================================
  46. class LibraryModule
  47. {
  48. public:
  49. LibraryModule (const ModuleDescription&);
  50. bool isValid() const { return moduleInfo.isValid(); }
  51. String getID() const { return moduleInfo.getID(); }
  52. String getVendor() const { return moduleInfo.getVendor(); }
  53. String getVersion() const { return moduleInfo.getVersion(); }
  54. String getName() const { return moduleInfo.getName(); }
  55. String getDescription() const { return moduleInfo.getDescription(); }
  56. String getLicense() const { return moduleInfo.getLicense(); }
  57. String getMinimumCppStandard() const { return moduleInfo.getMinimumCppStandard(); }
  58. File getFolder() const { return moduleInfo.getFolder(); }
  59. void writeIncludes (ProjectSaver&, OutputStream&);
  60. void addSettingsForModuleToExporter (ProjectExporter&, ProjectSaver&) const;
  61. void getConfigFlags (Project&, OwnedArray<Project::ConfigFlag>& flags) const;
  62. void findBrowseableFiles (const File& localModuleFolder, Array<File>& files) const;
  63. struct CompileUnit
  64. {
  65. File file;
  66. bool isCompiledForObjC, isCompiledForNonObjC;
  67. bool isNeededForExporter (ProjectExporter&) const;
  68. String getFilenameForProxyFile() const;
  69. static bool hasSuffix (const File&, const char*);
  70. };
  71. Array<CompileUnit> getAllCompileUnits (ProjectType::Target::Type forTarget = ProjectType::Target::unspecified) const;
  72. void findAndAddCompiledUnits (ProjectExporter&, ProjectSaver*, Array<File>& result,
  73. ProjectType::Target::Type forTarget = ProjectType::Target::unspecified) const;
  74. ModuleDescription moduleInfo;
  75. private:
  76. void addSearchPathsToExporter (ProjectExporter&) const;
  77. void addDefinesToExporter (ProjectExporter&) const;
  78. void addCompileUnitsToExporter (ProjectExporter&, ProjectSaver&) const;
  79. void addLibsToExporter (ProjectExporter&) const;
  80. void addBrowseableCode (ProjectExporter&, const Array<File>& compiled, const File& localModuleFolder) const;
  81. mutable Array<File> sourceFiles;
  82. OwnedArray<Project::ConfigFlag> configFlags;
  83. };
  84. //==============================================================================
  85. class AvailableModuleList
  86. {
  87. public:
  88. using ModuleIDAndFolder = std::pair<String, File>;
  89. using ModuleIDAndFolderList = std::vector<ModuleIDAndFolder>;
  90. AvailableModuleList() = default;
  91. void scanPaths (const Array<File>&);
  92. void scanPathsAsync (const Array<File>&);
  93. ModuleIDAndFolderList getAllModules() const;
  94. ModuleIDAndFolder getModuleWithID (const String&) const;
  95. void removeDuplicates (const ModuleIDAndFolderList& other);
  96. //==============================================================================
  97. struct Listener
  98. {
  99. virtual ~Listener() {}
  100. virtual void availableModulesChanged() = 0;
  101. };
  102. void addListener (Listener* listenerToAdd) { listeners.add (listenerToAdd); }
  103. void removeListener (Listener* listenerToRemove) { listeners.remove (listenerToRemove); }
  104. private:
  105. ThreadPoolJob* createScannerJob (const Array<File>&);
  106. void removePendingAndAddJob (ThreadPoolJob*);
  107. ThreadPool scanPool { 1 };
  108. ModuleIDAndFolderList moduleList;
  109. ListenerList<Listener> listeners;
  110. CriticalSection lock;
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AvailableModuleList)
  112. };
  113. //==============================================================================
  114. class EnabledModuleList
  115. {
  116. public:
  117. EnabledModuleList (Project&, const ValueTree&);
  118. //==============================================================================
  119. ValueTree getState() const { return state; }
  120. StringArray getAllModules() const;
  121. void createRequiredModules (OwnedArray<LibraryModule>& modules);
  122. void sortAlphabetically();
  123. File getDefaultModulesFolder() const;
  124. int getNumModules() const { return state.getNumChildren(); }
  125. String getModuleID (int index) const { return state.getChild (index) [Ids::ID].toString(); }
  126. ModuleDescription getModuleInfo (const String& moduleID);
  127. bool isModuleEnabled (const String& moduleID) const;
  128. StringArray getExtraDependenciesNeeded (const String& moduleID) const;
  129. bool doesModuleHaveHigherCppStandardThanProject (const String& moduleID);
  130. bool shouldUseGlobalPath (const String& moduleID) const;
  131. Value shouldUseGlobalPathValue (const String& moduleID) const;
  132. bool shouldShowAllModuleFilesInProject (const String& moduleID) const;
  133. Value shouldShowAllModuleFilesInProjectValue (const String& moduleID) const;
  134. bool shouldCopyModuleFilesLocally (const String& moduleID) const;
  135. Value shouldCopyModuleFilesLocallyValue (const String& moduleID) const;
  136. bool areMostModulesUsingGlobalPath() const;
  137. bool areMostModulesCopiedLocally() const;
  138. //==============================================================================
  139. void addModule (const File& moduleManifestFile, bool copyLocally, bool useGlobalPath, bool sendAnalyticsEvent);
  140. void addModuleInteractive (const String& moduleID);
  141. void addModuleFromUserSelectedFile();
  142. void addModuleOfferingToCopy (const File&, bool isFromUserSpecifiedFolder);
  143. void removeModule (String moduleID);
  144. private:
  145. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  146. Project& project;
  147. ValueTree state;
  148. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EnabledModuleList)
  149. };