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.

177 lines
7.4KB

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