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.

205 lines
8.6KB

  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. 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 canCopeWithDuplicateFiles() = 0;
  48. virtual bool isXcode() const { return false; }
  49. virtual bool isVisualStudio() const { return false; }
  50. virtual bool isLinux() const { return false; }
  51. virtual bool isOSX() const { return false; }
  52. //==============================================================================
  53. String getName() const { return name; }
  54. File getTargetFolder() const;
  55. Project& getProject() noexcept { return project; }
  56. const Project& getProject() const noexcept { return project; }
  57. const ValueTree& getSettings() const { return settings; }
  58. Value getSetting (const Identifier& name_) const { return settings.getPropertyAsValue (name_, project.getUndoManagerFor (settings)); }
  59. Value getJuceFolder() const { return getSetting (Ids::juceFolder); }
  60. Value getTargetLocation() const { return getSetting (Ids::targetFolder); }
  61. Value getExtraCompilerFlags() const { return getSetting (Ids::extraCompilerFlags); }
  62. Value getExtraLinkerFlags() const { return getSetting (Ids::extraLinkerFlags); }
  63. Value getExporterPreprocessorDefs() const { return getSetting (Ids::extraDefs); }
  64. // includes exporter, project + config defs
  65. StringPairArray getAllPreprocessorDefs (const Project::BuildConfiguration& config) const;
  66. // includes exporter + project defs..
  67. StringPairArray getAllPreprocessorDefs() const;
  68. String replacePreprocessorTokens (const Project::BuildConfiguration& config,
  69. const String& sourceString) const;
  70. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  71. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  72. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  73. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  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. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  100. StringArray xcodeFrameworks;
  101. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  102. Array<XmlElement> xcodeExtraPListEntries;
  103. //==============================================================================
  104. String makefileTargetSuffix;
  105. bool makefileIsDLL;
  106. //==============================================================================
  107. String msvcTargetSuffix;
  108. StringPairArray msvcExtraPreprocessorDefs;
  109. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  110. String msvcExtraLinkerOptions, msvcDelayLoadedDLLs, msvcModuleDefinitionFile;
  111. String msvcPostBuildCommand, msvcPostBuildOutputs;
  112. String msvcPreBuildCommand;
  113. //==============================================================================
  114. StringArray androidDynamicLibs;
  115. //==============================================================================
  116. StringArray extraSearchPaths;
  117. protected:
  118. //==============================================================================
  119. String name;
  120. Project& project;
  121. const ProjectType& projectType;
  122. const String projectName;
  123. const File projectFolder;
  124. Array<Project::BuildConfiguration> configs;
  125. ValueTree settings;
  126. Project::Item* modulesGroup;
  127. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  128. static String getLibbedFilename (String name)
  129. {
  130. if (! name.startsWith ("lib"))
  131. name = "lib" + name;
  132. if (! name.endsWithIgnoreCase (".a"))
  133. name = name + ".a";
  134. return name;
  135. }
  136. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough);
  137. //==============================================================================
  138. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  139. {
  140. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  141. throw SaveError (file);
  142. }
  143. static void createDirectoryOrThrow (const File& dirToCreate)
  144. {
  145. if (! dirToCreate.createDirectory())
  146. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  147. }
  148. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine)
  149. {
  150. MemoryOutputStream mo;
  151. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  152. overwriteFileIfDifferentOrThrow (file, mo);
  153. }
  154. private:
  155. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  156. };
  157. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__