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.

166 lines
7.0KB

  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_PROJECTEXPORTER_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORTER_JUCEHEADER__
  20. #include "../jucer_Headers.h"
  21. #include "jucer_Project.h"
  22. //==============================================================================
  23. class ProjectExporter
  24. {
  25. protected:
  26. //==============================================================================
  27. ProjectExporter (Project& project, const ValueTree& settings);
  28. public:
  29. virtual ~ProjectExporter();
  30. static int getNumExporters();
  31. static const StringArray getExporterNames();
  32. static ProjectExporter* createNewExporter (Project& project, const int index);
  33. static ProjectExporter* createExporter (Project& project, const ValueTree& settings);
  34. static ProjectExporter* createPlatformDefaultExporter (Project& project);
  35. //=============================================================================
  36. // return 0 if this can't be opened in the current OS, or a higher value, where higher numbers are more preferable.
  37. virtual int getLaunchPreferenceOrderForCurrentOS() = 0;
  38. virtual bool isPossibleForCurrentProject() = 0;
  39. virtual bool usesMMFiles() const = 0;
  40. virtual void createPropertyEditors (Array <PropertyComponent*>& props);
  41. virtual void launchProject() = 0;
  42. virtual void create() = 0; // may throw a SaveError
  43. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  44. //==============================================================================
  45. const String getName() const { return name; }
  46. const File getTargetFolder() const;
  47. const ValueTree& getSettings() const { return settings; }
  48. Value getSetting (const Identifier& name_) const { return settings.getPropertyAsValue (name_, project.getUndoManagerFor (settings)); }
  49. Value getJuceFolder() const { return getSetting (Ids::juceFolder); }
  50. Value getTargetLocation() const { return getSetting (Ids::targetFolder); }
  51. Value getVSTFolder() const { return getSetting (Ids::vstFolder); }
  52. Value getRTASFolder() const { return getSetting (Ids::rtasFolder); }
  53. Value getAUFolder() const { return getSetting (Ids::auFolder); }
  54. bool isVST() const { return (bool) project.isAudioPlugin() && (bool) project.shouldBuildVST().getValue(); }
  55. bool isRTAS() const { return (bool) project.isAudioPlugin() && (bool) project.shouldBuildRTAS().getValue(); }
  56. bool isAU() const { return (bool) project.isAudioPlugin() && (bool) project.shouldBuildAU().getValue(); }
  57. Value getExtraCompilerFlags() const { return getSetting (Ids::extraCompilerFlags); }
  58. Value getExtraLinkerFlags() const { return getSetting (Ids::extraLinkerFlags); }
  59. Value getExporterPreprocessorDefs() const { return getSetting (Ids::extraDefs); }
  60. // includes exporter, project + config defs
  61. const StringPairArray getAllPreprocessorDefs (const Project::BuildConfiguration& config) const;
  62. // includes exporter + project defs..
  63. const StringPairArray getAllPreprocessorDefs() const;
  64. const String replacePreprocessorTokens (const Project::BuildConfiguration& config,
  65. const String& sourceString) const;
  66. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  67. const String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  68. const String getExporterIdentifierMacro() const
  69. {
  70. return "JUCER_" + settings.getType().toString() + "_"
  71. + String::toHexString (settings [Ids::targetFolder].toString().hashCode()).toUpperCase();
  72. }
  73. Array<RelativePath> juceWrapperFiles;
  74. RelativePath juceWrapperFolder;
  75. // An exception that can be thrown by the create() method.
  76. class SaveError
  77. {
  78. public:
  79. SaveError (const String& error) : message (error)
  80. {}
  81. SaveError (const File& fileThatFailedToWrite)
  82. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  83. {}
  84. String message;
  85. };
  86. protected:
  87. //==============================================================================
  88. Project& project;
  89. ValueTree settings;
  90. String name;
  91. const RelativePath getJucePathFromTargetFolder() const;
  92. static const String getDefaultBuildsRootFolder() { return "Builds/"; }
  93. const Array<RelativePath> getVSTFilesRequired() const;
  94. static const String getLibbedFilename (String name)
  95. {
  96. if (! name.startsWith ("lib"))
  97. name = "lib" + name;
  98. if (! name.endsWithIgnoreCase (".a"))
  99. name = name + ".a";
  100. return name;
  101. }
  102. const RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  103. //==============================================================================
  104. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  105. {
  106. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  107. throw SaveError (file);
  108. }
  109. static void createDirectoryOrThrow (const File& dirToCreate)
  110. {
  111. if (! dirToCreate.createDirectory())
  112. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  113. }
  114. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine)
  115. {
  116. MemoryOutputStream mo;
  117. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  118. overwriteFileIfDifferentOrThrow (file, mo);
  119. }
  120. private:
  121. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  122. };
  123. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__