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.

197 lines
8.2KB

  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 "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* createNewExporter (Project& project, const String& name);
  35. static ProjectExporter* createExporter (Project& project, const ValueTree& settings);
  36. static ProjectExporter* createPlatformDefaultExporter (Project& project);
  37. static StringArray getDefaultExporters();
  38. //=============================================================================
  39. // return 0 if this can't be opened in the current OS, or a higher value, where higher numbers are more preferable.
  40. virtual int getLaunchPreferenceOrderForCurrentOS() = 0;
  41. virtual bool isPossibleForCurrentProject() = 0;
  42. virtual bool usesMMFiles() const = 0;
  43. virtual void createPropertyEditors (Array <PropertyComponent*>& props);
  44. virtual void launchProject() = 0;
  45. virtual void create() = 0; // may throw a SaveError
  46. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  47. virtual bool isXcode() const { return false; }
  48. virtual bool isVisualStudio() const { return false; }
  49. virtual bool isLinux() const { return false; }
  50. //==============================================================================
  51. String getName() const { return name; }
  52. File getTargetFolder() const;
  53. Project& getProject() noexcept { return project; }
  54. const Project& getProject() const noexcept { return project; }
  55. const ValueTree& getSettings() const { return settings; }
  56. Value getSetting (const Identifier& name_) const { return settings.getPropertyAsValue (name_, project.getUndoManagerFor (settings)); }
  57. Value getJuceFolder() const { return getSetting (Ids::juceFolder); }
  58. Value getTargetLocation() const { return getSetting (Ids::targetFolder); }
  59. Value getExtraCompilerFlags() const { return getSetting (Ids::extraCompilerFlags); }
  60. Value getExtraLinkerFlags() const { return getSetting (Ids::extraLinkerFlags); }
  61. Value getExporterPreprocessorDefs() const { return getSetting (Ids::extraDefs); }
  62. // includes exporter, project + config defs
  63. StringPairArray getAllPreprocessorDefs (const Project::BuildConfiguration& config) const;
  64. // includes exporter + project defs..
  65. StringPairArray getAllPreprocessorDefs() const;
  66. String replacePreprocessorTokens (const Project::BuildConfiguration& config,
  67. const String& sourceString) const;
  68. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  69. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  70. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  71. String getExporterIdentifierMacro() const
  72. {
  73. return "JUCER_" + settings.getType().toString() + "_"
  74. + String::toHexString (settings [Ids::targetFolder].toString().hashCode()).toUpperCase();
  75. }
  76. // An exception that can be thrown by the create() method.
  77. class SaveError
  78. {
  79. public:
  80. SaveError (const String& error) : message (error)
  81. {}
  82. SaveError (const File& fileThatFailedToWrite)
  83. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  84. {}
  85. String message;
  86. };
  87. RelativePath getJucePathFromTargetFolder() const;
  88. RelativePath getJucePathFromProjectFolder() const;
  89. //==============================================================================
  90. Array<Project::Item> groups;
  91. Project::Item& getModulesGroup();
  92. //==============================================================================
  93. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  94. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  95. String xcodeShellScript, xcodeShellScriptTitle, xcodeOtherRezFlags;
  96. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  97. StringArray xcodeFrameworks;
  98. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  99. //==============================================================================
  100. String makefileTargetSuffix;
  101. bool makefileIsDLL;
  102. //==============================================================================
  103. String msvcTargetSuffix;
  104. StringPairArray msvcExtraPreprocessorDefs;
  105. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  106. String msvcExtraLinkerOptions, msvcDelayLoadedDLLs, msvcModuleDefinitionFile;
  107. String msvcPostBuildCommand, msvcPostBuildOutputs;
  108. //==============================================================================
  109. StringArray extraSearchPaths;
  110. protected:
  111. //==============================================================================
  112. String name;
  113. Project& project;
  114. const ProjectType& projectType;
  115. const String projectName;
  116. const File projectFolder;
  117. Array<Project::BuildConfiguration> configs;
  118. ValueTree settings;
  119. Project::Item* modulesGroup;
  120. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  121. static String getLibbedFilename (String name)
  122. {
  123. if (! name.startsWith ("lib"))
  124. name = "lib" + name;
  125. if (! name.endsWithIgnoreCase (".a"))
  126. name = name + ".a";
  127. return name;
  128. }
  129. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough);
  130. //==============================================================================
  131. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  132. {
  133. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  134. throw SaveError (file);
  135. }
  136. static void createDirectoryOrThrow (const File& dirToCreate)
  137. {
  138. if (! dirToCreate.createDirectory())
  139. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  140. }
  141. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine)
  142. {
  143. MemoryOutputStream mo;
  144. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  145. overwriteFileIfDifferentOrThrow (file, mo);
  146. }
  147. private:
  148. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  149. };
  150. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__