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.

199 lines
8.4KB

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