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.

316 lines
15KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECT_JUCEHEADER__
  19. #define __JUCER_PROJECT_JUCEHEADER__
  20. #include "../jucer_Headers.h"
  21. class ProjectExporter;
  22. class ProjectType;
  23. class ModuleList;
  24. class LibraryModule;
  25. //==============================================================================
  26. class Project : public FileBasedDocument,
  27. public ValueTree::Listener
  28. {
  29. public:
  30. //==============================================================================
  31. Project (const File& file);
  32. ~Project();
  33. //==============================================================================
  34. // FileBasedDocument stuff..
  35. const String getDocumentTitle();
  36. const String loadDocument (const File& file);
  37. const String saveDocument (const File& file);
  38. const File getLastDocumentOpened();
  39. void setLastDocumentOpened (const File& file);
  40. void setTitle (const String& newTitle);
  41. //==============================================================================
  42. ValueTree getProjectRoot() const { return projectRoot; }
  43. Value getProjectName() { return getMainGroup().getName(); }
  44. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  45. String getProjectUID() const { return projectRoot [Ids::id_]; }
  46. //==============================================================================
  47. template <class FileType>
  48. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  49. {
  50. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  51. }
  52. File resolveFilename (String filename) const;
  53. String getRelativePathForFile (const File& file) const;
  54. //==============================================================================
  55. // Creates editors for the project settings
  56. void createPropertyEditors (Array <PropertyComponent*>& properties);
  57. //==============================================================================
  58. // project types
  59. const ProjectType& getProjectType() const;
  60. Value getProjectTypeValue() const { return getProjectValue ("projectType"); }
  61. Value getVersion() const { return getProjectValue ("version"); }
  62. String getVersionAsHex() const;
  63. Value getBundleIdentifier() const { return getProjectValue (Ids::bundleIdentifier); }
  64. void setBundleIdentifierToDefault() { getBundleIdentifier() = "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false); }
  65. //==============================================================================
  66. Value getProjectValue (const Identifier& name) const { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  67. Value getProjectPreprocessorDefs() const { return getProjectValue (Ids::defines); }
  68. StringPairArray getPreprocessorDefs() const;
  69. Value getBigIconImageItemID() const { return getProjectValue ("bigIcon"); }
  70. Value getSmallIconImageItemID() const { return getProjectValue ("smallIcon"); }
  71. Image getBigIcon();
  72. Image getSmallIcon();
  73. //==============================================================================
  74. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  75. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  76. //==============================================================================
  77. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  78. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  79. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  80. String getAppConfigFilename() const { return "AppConfig.h"; }
  81. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  82. int getNumSeparateAmalgamatedFiles() const { return 4; }
  83. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  84. //==============================================================================
  85. class Item
  86. {
  87. public:
  88. //==============================================================================
  89. Item (Project& project, const ValueTree& itemNode);
  90. Item (const Item& other);
  91. Item& operator= (const Item& other);
  92. ~Item();
  93. static Item createGroup (Project& project, const String& name, const String& uid);
  94. void initialiseNodeValues();
  95. //==============================================================================
  96. bool isValid() const { return node.isValid(); }
  97. const ValueTree& getNode() const noexcept { return node; }
  98. ValueTree& getNode() noexcept { return node; }
  99. Project& getProject() const noexcept { return *project; }
  100. bool operator== (const Item& other) const { return node == other.node && project == other.project; }
  101. bool operator!= (const Item& other) const { return ! operator== (other); }
  102. //==============================================================================
  103. bool isFile() const;
  104. bool isGroup() const;
  105. bool isMainGroup() const;
  106. bool isImageFile() const;
  107. String getID() const;
  108. Item findItemWithID (const String& targetId) const; // (recursive search)
  109. String getImageFileID() const;
  110. void setID (const String& newID);
  111. //==============================================================================
  112. Value getName() const;
  113. File getFile() const;
  114. String getFilePath() const;
  115. void setFile (const File& file);
  116. void setFile (const RelativePath& file);
  117. File determineGroupFolder() const;
  118. bool renameFile (const File& newFile);
  119. bool shouldBeAddedToTargetProject() const;
  120. bool shouldBeCompiled() const;
  121. Value getShouldCompileValue() const;
  122. bool shouldBeAddedToBinaryResources() const;
  123. Value getShouldAddToResourceValue() const;
  124. Value getShouldInhibitWarningsValue() const;
  125. Value getShouldUseStdCallValue() const;
  126. //==============================================================================
  127. bool canContain (const Item& child) const;
  128. int getNumChildren() const { return node.getNumChildren(); }
  129. Item getChild (int index) const { return Item (getProject(), node.getChild (index)); }
  130. Item addNewSubGroup (const String& name, int insertIndex);
  131. Item getOrCreateSubGroup (const String& name);
  132. void addChild (const Item& newChild, int insertIndex);
  133. bool addFile (const File& file, int insertIndex, bool shouldCompile);
  134. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  135. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  136. void removeItemFromProject();
  137. void sortAlphabetically (bool keepGroupsAtStart);
  138. Item findItemForFile (const File& file) const;
  139. bool containsChildForFile (const RelativePath& file) const;
  140. Item getParent() const;
  141. Item createCopy();
  142. const Drawable* getIcon() const;
  143. private:
  144. //==============================================================================
  145. Project* project;
  146. ValueTree node;
  147. UndoManager* getUndoManager() const { return getProject().getUndoManagerFor (node); }
  148. };
  149. Item getMainGroup();
  150. void findAllImageItems (OwnedArray<Item>& items);
  151. //==============================================================================
  152. class BuildConfiguration
  153. {
  154. public:
  155. BuildConfiguration (const BuildConfiguration&);
  156. const BuildConfiguration& operator= (const BuildConfiguration&);
  157. ~BuildConfiguration();
  158. //==============================================================================
  159. Project& getProject() const { return *project; }
  160. void createPropertyEditors (Array <PropertyComponent*>& properties);
  161. //==============================================================================
  162. Value getName() const { return getValue (Ids::name); }
  163. Value isDebug() const { return getValue (Ids::isDebug); }
  164. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  165. // the path relative to the build folder in which the binary should go
  166. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  167. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  168. String getGCCOptimisationFlag() const;
  169. Value getBuildConfigPreprocessorDefs() const { return getValue (Ids::defines); }
  170. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  171. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  172. StringArray getHeaderSearchPaths() const;
  173. static const char* const osxVersionDefault;
  174. static const char* const osxVersion10_4;
  175. static const char* const osxVersion10_5;
  176. static const char* const osxVersion10_6;
  177. Value getMacSDKVersion() const { return getValue (Ids::osxSDK); }
  178. Value getMacCompatibilityVersion() const { return getValue (Ids::osxCompatibility); }
  179. static const char* const osxArch_Default;
  180. static const char* const osxArch_Native;
  181. static const char* const osxArch_32BitUniversal;
  182. static const char* const osxArch_64BitUniversal;
  183. static const char* const osxArch_64Bit;
  184. Value getMacArchitecture() const { return getValue (Ids::osxArchitecture); }
  185. //==============================================================================
  186. private:
  187. friend class Project;
  188. Project* project;
  189. ValueTree config;
  190. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  191. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  192. BuildConfiguration (Project* project, const ValueTree& configNode);
  193. };
  194. int getNumConfigurations() const;
  195. BuildConfiguration getConfiguration (int index);
  196. void addNewConfiguration (BuildConfiguration* configToCopy);
  197. void deleteConfiguration (int index);
  198. bool hasConfigurationNamed (const String& name) const;
  199. String getUniqueConfigName (String name) const;
  200. //==============================================================================
  201. ValueTree getExporters();
  202. int getNumExporters();
  203. ProjectExporter* createExporter (int index);
  204. void addNewExporter (const String& exporterName);
  205. void deleteExporter (int index);
  206. void createDefaultExporters();
  207. //==============================================================================
  208. struct ConfigFlag
  209. {
  210. String symbol, description, sourceModuleID;
  211. Value value; // 1 = true, 2 = false, anything else = use default
  212. };
  213. static const char* const configFlagDefault;
  214. static const char* const configFlagEnabled;
  215. static const char* const configFlagDisabled;
  216. Value getConfigFlag (const String& name);
  217. bool isConfigFlagEnabled (const String& name) const;
  218. //==============================================================================
  219. bool isModuleEnabled (const String& moduleID) const;
  220. Value shouldShowAllModuleFilesInProject (const String& moduleID);
  221. Value shouldCopyModuleFilesLocally (const String& moduleID);
  222. void addModule (const String& moduleID);
  223. void removeModule (const String& moduleID);
  224. void createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const;
  225. //==============================================================================
  226. String getFileTemplate (const String& templateName);
  227. //==============================================================================
  228. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  229. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  230. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  231. void valueTreeChildOrderChanged (ValueTree& parentTree);
  232. void valueTreeParentChanged (ValueTree& tree);
  233. //==============================================================================
  234. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  235. //==============================================================================
  236. static const char* projectFileExtension;
  237. private:
  238. friend class Item;
  239. ValueTree projectRoot;
  240. static File lastDocumentOpened;
  241. DrawableImage mainProjectIcon;
  242. void updateProjectSettings();
  243. void sanitiseConfigFlags();
  244. void setMissingDefaultValues();
  245. ValueTree getConfigurations() const;
  246. void createDefaultConfigs();
  247. ValueTree getConfigNode();
  248. ValueTree getModulesNode();
  249. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  250. };
  251. #endif // __JUCER_PROJECT_JUCEHEADER__