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.

329 lines
14KB

  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_PROJECTEXPORTER_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORTER_JUCEHEADER__
  20. #include "../jucer_Headers.h"
  21. #include "../Project/jucer_Project.h"
  22. #include "../Project/jucer_ProjectType.h"
  23. //==============================================================================
  24. class ProjectExporter
  25. {
  26. public:
  27. ProjectExporter (Project&, const ValueTree& settings);
  28. virtual ~ProjectExporter();
  29. static int getNumExporters();
  30. static StringArray getExporterNames();
  31. static ProjectExporter* createNewExporter (Project&, const int index);
  32. static ProjectExporter* createNewExporter (Project&, const String& name);
  33. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  34. static ProjectExporter* createPlatformDefaultExporter (Project&);
  35. static StringArray getDefaultExporters();
  36. //=============================================================================
  37. // return 0 if this can't be opened in the current OS, or a higher value, where higher numbers are more preferable.
  38. virtual int getLaunchPreferenceOrderForCurrentOS() = 0;
  39. virtual bool isPossibleForCurrentProject() = 0;
  40. virtual bool usesMMFiles() const = 0;
  41. virtual void createPropertyEditors (PropertyListBuilder&);
  42. virtual void launchProject() = 0;
  43. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  44. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  45. virtual bool canCopeWithDuplicateFiles() = 0;
  46. virtual bool isXcode() const { return false; }
  47. virtual bool isVisualStudio() const { return false; }
  48. virtual int getVisualStudioVersion() const { return 0; }
  49. virtual bool isLinux() const { return false; }
  50. virtual bool isOSX() const { return false; }
  51. //==============================================================================
  52. String getName() const { return name; }
  53. File getTargetFolder() const;
  54. Project& getProject() noexcept { return project; }
  55. const Project& getProject() const noexcept { return project; }
  56. Value getSetting (const Identifier& name_) { return settings.getPropertyAsValue (name_, project.getUndoManagerFor (settings)); }
  57. Value getJuceFolderValue() { return getSetting (Ids::juceFolder); }
  58. String getJuceFolderString() const { return settings [Ids::juceFolder]; }
  59. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  60. String getTargetLocationString() const { return settings [Ids::targetFolder]; }
  61. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  62. String getExtraCompilerFlagsString() const { return settings [Ids::extraCompilerFlags]; }
  63. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  64. String getExtraLinkerFlagsString() const { return settings [Ids::extraLinkerFlags]; }
  65. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  66. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  67. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  68. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  69. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  70. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  71. Image getBigIcon() const;
  72. Image getSmallIcon() const;
  73. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  74. String getExporterIdentifierMacro() const
  75. {
  76. return "JUCER_" + settings.getType().toString() + "_"
  77. + String::toHexString (settings [Ids::targetFolder].toString().hashCode()).toUpperCase();
  78. }
  79. // An exception that can be thrown by the create() method.
  80. class SaveError
  81. {
  82. public:
  83. SaveError (const String& error) : message (error)
  84. {}
  85. SaveError (const File& fileThatFailedToWrite)
  86. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  87. {}
  88. String message;
  89. };
  90. RelativePath getJucePathFromTargetFolder() const;
  91. RelativePath getJucePathFromProjectFolder() const;
  92. //==============================================================================
  93. Array<Project::Item> groups;
  94. Project::Item& getModulesGroup();
  95. //==============================================================================
  96. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  97. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  98. String xcodeShellScript, xcodeShellScriptTitle, xcodeOtherRezFlags;
  99. String xcodeExcludedFiles64Bit;
  100. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  101. StringArray xcodeFrameworks;
  102. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  103. Array<XmlElement> xcodeExtraPListEntries;
  104. //==============================================================================
  105. String makefileTargetSuffix;
  106. bool makefileIsDLL;
  107. //==============================================================================
  108. String msvcTargetSuffix;
  109. StringPairArray msvcExtraPreprocessorDefs;
  110. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  111. String msvcDelayLoadedDLLs;
  112. //==============================================================================
  113. StringArray extraSearchPaths;
  114. //==============================================================================
  115. class BuildConfiguration : public ReferenceCountedObject
  116. {
  117. public:
  118. BuildConfiguration (Project& project, const ValueTree& configNode);
  119. ~BuildConfiguration();
  120. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  121. //==============================================================================
  122. virtual void createPropertyEditors (PropertyListBuilder&) = 0;
  123. //==============================================================================
  124. Value getNameValue() { return getValue (Ids::name); }
  125. String getName() const { return config [Ids::name]; }
  126. Value isDebugValue() { return getValue (Ids::isDebug); }
  127. bool isDebug() const { return config [Ids::isDebug]; }
  128. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  129. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  130. // the path relative to the build folder in which the binary should go
  131. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  132. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  133. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  134. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  135. String getGCCOptimisationFlag() const;
  136. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  137. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  138. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  139. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  140. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  141. StringArray getHeaderSearchPaths() const;
  142. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  143. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  144. StringArray getLibrarySearchPaths() const;
  145. String getGCCLibraryPathFlags() const;
  146. Value getValue (const Identifier& name) { return config.getPropertyAsValue (name, getUndoManager()); }
  147. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  148. //==============================================================================
  149. ValueTree config;
  150. Project& project;
  151. protected:
  152. void createBasicPropertyEditors (PropertyListBuilder&);
  153. private:
  154. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration);
  155. };
  156. void addNewConfiguration (const BuildConfiguration* configToCopy);
  157. void deleteConfiguration (int index);
  158. bool hasConfigurationNamed (const String& name) const;
  159. String getUniqueConfigName (String name) const;
  160. //==============================================================================
  161. struct ConfigIterator
  162. {
  163. ConfigIterator (ProjectExporter& exporter);
  164. bool next();
  165. BuildConfiguration& operator*() const { return *config; }
  166. BuildConfiguration* operator->() const { return config; }
  167. BuildConfiguration::Ptr config;
  168. int index;
  169. private:
  170. ProjectExporter& exporter;
  171. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator);
  172. };
  173. struct ConstConfigIterator
  174. {
  175. ConstConfigIterator (const ProjectExporter& exporter);
  176. bool next();
  177. const BuildConfiguration& operator*() const { return *config; }
  178. const BuildConfiguration* operator->() const { return config; }
  179. BuildConfiguration::Ptr config;
  180. int index;
  181. private:
  182. const ProjectExporter& exporter;
  183. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator);
  184. };
  185. int getNumConfigurations() const;
  186. BuildConfiguration::Ptr getConfiguration (int index) const;
  187. ValueTree getConfigurations() const;
  188. void createDefaultConfigs();
  189. static const Identifier configurations, configuration;
  190. //==============================================================================
  191. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  192. String getExporterPreprocessorDefsString() const { return settings [Ids::extraDefs]; }
  193. // includes exporter, project + config defs
  194. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  195. // includes exporter + project defs..
  196. StringPairArray getAllPreprocessorDefs() const;
  197. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  198. ValueTree settings;
  199. protected:
  200. //==============================================================================
  201. String name;
  202. Project& project;
  203. const ProjectType& projectType;
  204. const String projectName;
  205. const File projectFolder;
  206. Project::Item* modulesGroup;
  207. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  208. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  209. static String getLibbedFilename (String name)
  210. {
  211. if (! name.startsWith ("lib"))
  212. name = "lib" + name;
  213. if (! name.endsWithIgnoreCase (".a"))
  214. name = name + ".a";
  215. return name;
  216. }
  217. //==============================================================================
  218. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  219. {
  220. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  221. throw SaveError (file);
  222. }
  223. static void createDirectoryOrThrow (const File& dirToCreate)
  224. {
  225. if (! dirToCreate.createDirectory())
  226. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  227. }
  228. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  229. {
  230. MemoryOutputStream mo;
  231. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  232. if (useUnixNewLines)
  233. {
  234. MemoryOutputStream mo2;
  235. mo2 << mo.toString().replace ("\r\n", "\n");
  236. overwriteFileIfDifferentOrThrow (file, mo2);
  237. }
  238. else
  239. {
  240. overwriteFileIfDifferentOrThrow (file, mo);
  241. }
  242. }
  243. static Image rescaleImageForIcon (Image image, int iconSize);
  244. private:
  245. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  246. };
  247. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__