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.

194 lines
8.0KB

  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 getExtraCompilerFlags() const { return getSetting (Ids::extraCompilerFlags); }
  58. Value getExtraLinkerFlags() const { return getSetting (Ids::extraLinkerFlags); }
  59. Value getExporterPreprocessorDefs() const { return getSetting (Ids::extraDefs); }
  60. // includes exporter, project + config defs
  61. StringPairArray getAllPreprocessorDefs (const Project::BuildConfiguration& config) const;
  62. // includes exporter + project defs..
  63. StringPairArray getAllPreprocessorDefs() const;
  64. String replacePreprocessorTokens (const Project::BuildConfiguration& config,
  65. const String& sourceString) const;
  66. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  67. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  68. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  69. String getExporterIdentifierMacro() const
  70. {
  71. return "JUCER_" + settings.getType().toString() + "_"
  72. + String::toHexString (settings [Ids::targetFolder].toString().hashCode()).toUpperCase();
  73. }
  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. RelativePath getJucePathFromTargetFolder() const;
  86. RelativePath getJucePathFromProjectFolder() const;
  87. //==============================================================================
  88. Array<Project::Item> groups;
  89. OwnedArray<LibraryModule> libraryModules;
  90. //==============================================================================
  91. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  92. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  93. String xcodeShellScript, xcodeShellScriptTitle, xcodeOtherRezFlags;
  94. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  95. StringArray xcodeFrameworks;
  96. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  97. //==============================================================================
  98. String makefileTargetSuffix;
  99. bool makefileIsDLL;
  100. //==============================================================================
  101. String msvcTargetSuffix;
  102. StringPairArray msvcExtraPreprocessorDefs;
  103. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  104. String msvcExtraLinkerOptions, msvcDelayLoadedDLLs, msvcModuleDefinitionFile;
  105. String msvcPostBuildCommand, msvcPostBuildOutputs;
  106. //==============================================================================
  107. void createLibraryModules();
  108. protected:
  109. //==============================================================================
  110. String name;
  111. Project& project;
  112. const ProjectType& projectType;
  113. const String projectName;
  114. const File projectFolder;
  115. Array<Project::BuildConfiguration> configs;
  116. ValueTree settings;
  117. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  118. static String getLibbedFilename (String name)
  119. {
  120. if (! name.startsWith ("lib"))
  121. name = "lib" + name;
  122. if (! name.endsWithIgnoreCase (".a"))
  123. name = name + ".a";
  124. return name;
  125. }
  126. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough);
  127. //==============================================================================
  128. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  129. {
  130. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  131. throw SaveError (file);
  132. }
  133. static void createDirectoryOrThrow (const File& dirToCreate)
  134. {
  135. if (! dirToCreate.createDirectory())
  136. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  137. }
  138. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine)
  139. {
  140. MemoryOutputStream mo;
  141. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  142. overwriteFileIfDifferentOrThrow (file, mo);
  143. }
  144. private:
  145. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  146. };
  147. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__