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.

165 lines
6.9KB

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