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.

323 lines
16KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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 ("bundleIdentifier"); }
  62. void setBundleIdentifierToDefault() { getBundleIdentifier() = "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false); }
  63. //==============================================================================
  64. // linkage modes..
  65. static const char* const notLinkedToJuce;
  66. static const char* const useLinkedJuce;
  67. static const char* const useAmalgamatedJuce;
  68. static const char* const useAmalgamatedJuceViaSingleTemplate;
  69. static const char* const useAmalgamatedJuceViaMultipleTemplates;
  70. Value getJuceLinkageModeValue() const { return getProjectValue ("juceLinkage"); }
  71. String getJuceLinkageMode() const { return getJuceLinkageModeValue().toString(); }
  72. bool isUsingWrapperFiles() const { return isUsingFullyAmalgamatedFile() || isUsingSingleTemplateFile() || isUsingMultipleTemplateFiles(); }
  73. bool isUsingFullyAmalgamatedFile() const { return getJuceLinkageMode() == useAmalgamatedJuce; }
  74. bool isUsingSingleTemplateFile() const { return getJuceLinkageMode() == useAmalgamatedJuceViaSingleTemplate; }
  75. bool isUsingMultipleTemplateFiles() const { return getJuceLinkageMode() == useAmalgamatedJuceViaMultipleTemplates; }
  76. //==============================================================================
  77. Value getProjectValue (const Identifier& name) const { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  78. Value getProjectPreprocessorDefs() const { return getProjectValue (Ids::defines); }
  79. StringPairArray getPreprocessorDefs() const;
  80. Value getBigIconImageItemID() const { return getProjectValue ("bigIcon"); }
  81. Value getSmallIconImageItemID() const { return getProjectValue ("smallIcon"); }
  82. Image getBigIcon();
  83. Image getSmallIcon();
  84. //==============================================================================
  85. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  86. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  87. File getPluginCharacteristicsFile() const { return getGeneratedCodeFolder().getChildFile (getPluginCharacteristicsFilename()); }
  88. File getLocalJuceFolder();
  89. //==============================================================================
  90. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  91. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  92. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  93. String getAppConfigFilename() const { return "AppConfig.h"; }
  94. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  95. int getNumSeparateAmalgamatedFiles() const { return 4; }
  96. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  97. String getJuceCodeGroupName() const { return "Juce Library Code"; }
  98. String getPluginCharacteristicsFilename() const { return "JucePluginCharacteristics.h"; }
  99. //==============================================================================
  100. class Item
  101. {
  102. public:
  103. //==============================================================================
  104. Item (Project& project, const ValueTree& itemNode);
  105. Item (const Item& other);
  106. Item& operator= (const Item& other);
  107. ~Item();
  108. static Item createGroup (Project& project, const String& name);
  109. void initialiseNodeValues();
  110. //==============================================================================
  111. bool isValid() const { return node.isValid(); }
  112. const ValueTree& getNode() const noexcept { return node; }
  113. ValueTree& getNode() noexcept { return node; }
  114. Project& getProject() const noexcept { return *project; }
  115. bool operator== (const Item& other) const { return node == other.node && project == other.project; }
  116. bool operator!= (const Item& other) const { return ! operator== (other); }
  117. //==============================================================================
  118. bool isFile() const;
  119. bool isGroup() const;
  120. bool isMainGroup() const;
  121. bool isImageFile() const;
  122. String getID() const;
  123. Item findItemWithID (const String& targetId) const; // (recursive search)
  124. String getImageFileID() const;
  125. void setID (const String& newID);
  126. //==============================================================================
  127. Value getName() const;
  128. File getFile() const;
  129. String getFilePath() const;
  130. void setFile (const File& file);
  131. void setFile (const RelativePath& file);
  132. File determineGroupFolder() const;
  133. bool renameFile (const File& newFile);
  134. bool shouldBeAddedToTargetProject() const;
  135. bool shouldBeCompiled() const;
  136. Value getShouldCompileValue() const;
  137. bool shouldBeAddedToBinaryResources() const;
  138. Value getShouldAddToResourceValue() const;
  139. Value getShouldInhibitWarningsValue() const;
  140. Value getShouldUseStdCallValue() const;
  141. //==============================================================================
  142. bool canContain (const Item& child) const;
  143. int getNumChildren() const { return node.getNumChildren(); }
  144. Item getChild (int index) const { return Item (getProject(), node.getChild (index)); }
  145. Item addNewSubGroup (const String& name, int insertIndex);
  146. void addChild (const Item& newChild, int insertIndex);
  147. bool addFile (const File& file, int insertIndex);
  148. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  149. void removeItemFromProject();
  150. void sortAlphabetically();
  151. Item findItemForFile (const File& file) const;
  152. Item getParent() const;
  153. Item createCopy();
  154. const Drawable* getIcon() const;
  155. private:
  156. //==============================================================================
  157. Project* project;
  158. ValueTree node;
  159. UndoManager* getUndoManager() const { return getProject().getUndoManagerFor (node); }
  160. };
  161. Item getMainGroup();
  162. void findAllImageItems (OwnedArray<Item>& items);
  163. //==============================================================================
  164. class BuildConfiguration
  165. {
  166. public:
  167. BuildConfiguration (const BuildConfiguration&);
  168. const BuildConfiguration& operator= (const BuildConfiguration&);
  169. ~BuildConfiguration();
  170. //==============================================================================
  171. Project& getProject() const { return *project; }
  172. void createPropertyEditors (Array <PropertyComponent*>& properties);
  173. //==============================================================================
  174. Value getName() const { return getValue (Ids::name); }
  175. Value isDebug() const { return getValue (Ids::isDebug); }
  176. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  177. // the path relative to the build folder in which the binary should go
  178. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  179. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  180. String getGCCOptimisationFlag() const;
  181. Value getBuildConfigPreprocessorDefs() const { return getValue (Ids::defines); }
  182. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  183. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  184. StringArray getHeaderSearchPaths() const;
  185. static const char* const osxVersionDefault;
  186. static const char* const osxVersion10_4;
  187. static const char* const osxVersion10_5;
  188. static const char* const osxVersion10_6;
  189. Value getMacSDKVersion() const { return getValue (Ids::osxSDK); }
  190. Value getMacCompatibilityVersion() const { return getValue (Ids::osxCompatibility); }
  191. static const char* const osxArch_Default;
  192. static const char* const osxArch_Native;
  193. static const char* const osxArch_32BitUniversal;
  194. static const char* const osxArch_64BitUniversal;
  195. static const char* const osxArch_64Bit;
  196. Value getMacArchitecture() const { return getValue (Ids::osxArchitecture); }
  197. //==============================================================================
  198. private:
  199. friend class Project;
  200. Project* project;
  201. ValueTree config;
  202. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  203. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  204. BuildConfiguration (Project* project, const ValueTree& configNode);
  205. };
  206. int getNumConfigurations() const;
  207. BuildConfiguration getConfiguration (int index);
  208. void addNewConfiguration (BuildConfiguration* configToCopy);
  209. void deleteConfiguration (int index);
  210. bool hasConfigurationNamed (const String& name) const;
  211. String getUniqueConfigName (String name) const;
  212. //==============================================================================
  213. ValueTree getExporters();
  214. int getNumExporters();
  215. ProjectExporter* createExporter (int index);
  216. void addNewExporter (int exporterIndex);
  217. void deleteExporter (int index);
  218. void createDefaultExporters();
  219. //==============================================================================
  220. struct ConfigFlag
  221. {
  222. String symbol, description;
  223. Value value; // 1 = true, 2 = false, anything else = use default
  224. };
  225. void getAllConfigFlags (OwnedArray <ConfigFlag>& flags);
  226. static const char* const configFlagDefault;
  227. static const char* const configFlagEnabled;
  228. static const char* const configFlagDisabled;
  229. Value getConfigFlag (const String& name);
  230. bool isConfigFlagEnabled (const String& name) const;
  231. //==============================================================================
  232. String getFileTemplate (const String& templateName);
  233. //==============================================================================
  234. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  235. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  236. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  237. void valueTreeChildOrderChanged (ValueTree& parentTree);
  238. void valueTreeParentChanged (ValueTree& tree);
  239. //==============================================================================
  240. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  241. //==============================================================================
  242. static const char* projectFileExtension;
  243. static void resaveJucerFile (const File& file);
  244. private:
  245. friend class Item;
  246. ValueTree projectRoot;
  247. static File lastDocumentOpened;
  248. DrawableImage mainProjectIcon;
  249. void updateProjectSettings();
  250. void setMissingDefaultValues();
  251. ValueTree getConfigurations() const;
  252. void createDefaultConfigs();
  253. ValueTree getConfigNode();
  254. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  255. };
  256. #endif // __JUCER_PROJECT_JUCEHEADER__