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.

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