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.

267 lines
11KB

  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. public:
  27. ProjectExporter (Project&, const ValueTree& settings);
  28. virtual ~ProjectExporter();
  29. static int getNumExporters();
  30. static StringArray getExporterNames();
  31. static ProjectExporter* createNewExporter (Project&, const int index);
  32. static ProjectExporter* createNewExporter (Project&, const String& name);
  33. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  34. static ProjectExporter* createPlatformDefaultExporter (Project&);
  35. static StringArray getDefaultExporters();
  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 (PropertyListBuilder&);
  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 canCopeWithDuplicateFiles() = 0;
  46. virtual bool isXcode() const { return false; }
  47. virtual bool isVisualStudio() const { return false; }
  48. virtual bool isLinux() const { return false; }
  49. virtual bool isOSX() 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. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  62. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  63. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  64. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  65. String getExporterIdentifierMacro() const
  66. {
  67. return "JUCER_" + settings.getType().toString() + "_"
  68. + String::toHexString (settings [Ids::targetFolder].toString().hashCode()).toUpperCase();
  69. }
  70. // An exception that can be thrown by the create() method.
  71. class SaveError
  72. {
  73. public:
  74. SaveError (const String& error) : message (error)
  75. {}
  76. SaveError (const File& fileThatFailedToWrite)
  77. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  78. {}
  79. String message;
  80. };
  81. RelativePath getJucePathFromTargetFolder() const;
  82. RelativePath getJucePathFromProjectFolder() const;
  83. //==============================================================================
  84. Array<Project::Item> groups;
  85. Project::Item& getModulesGroup();
  86. //==============================================================================
  87. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  88. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  89. String xcodeShellScript, xcodeShellScriptTitle, xcodeOtherRezFlags;
  90. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  91. StringArray xcodeFrameworks;
  92. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  93. Array<XmlElement> xcodeExtraPListEntries;
  94. //==============================================================================
  95. String makefileTargetSuffix;
  96. bool makefileIsDLL;
  97. //==============================================================================
  98. String msvcTargetSuffix;
  99. StringPairArray msvcExtraPreprocessorDefs;
  100. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  101. String msvcExtraLinkerOptions, msvcDelayLoadedDLLs, msvcModuleDefinitionFile;
  102. String msvcPostBuildCommand, msvcPostBuildOutputs;
  103. String msvcPreBuildCommand;
  104. //==============================================================================
  105. StringArray androidDynamicLibs;
  106. //==============================================================================
  107. StringArray extraSearchPaths;
  108. //==============================================================================
  109. class BuildConfiguration : public ReferenceCountedObject
  110. {
  111. public:
  112. BuildConfiguration (Project& project, const ValueTree& configNode);
  113. ~BuildConfiguration();
  114. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  115. //==============================================================================
  116. virtual void createPropertyEditors (PropertyListBuilder&) = 0;
  117. //==============================================================================
  118. Value getName() const { return getValue (Ids::name); }
  119. Value isDebug() const { return getValue (Ids::isDebug); }
  120. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  121. // the path relative to the build folder in which the binary should go
  122. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  123. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  124. String getGCCOptimisationFlag() const;
  125. Value getBuildConfigPreprocessorDefs() const { return getValue (Ids::defines); }
  126. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  127. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  128. StringArray getHeaderSearchPaths() const;
  129. //==============================================================================
  130. ValueTree config;
  131. protected:
  132. Project& project;
  133. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  134. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  135. void createBasicPropertyEditors (PropertyListBuilder&);
  136. private:
  137. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration);
  138. };
  139. int getNumConfigurations() const;
  140. BuildConfiguration::Ptr getConfiguration (int index) const;
  141. void addNewConfiguration (const BuildConfiguration* configToCopy);
  142. void deleteConfiguration (int index);
  143. bool hasConfigurationNamed (const String& name) const;
  144. String getUniqueConfigName (String name) const;
  145. ValueTree getConfigurations() const;
  146. void createDefaultConfigs();
  147. static const Identifier configurations, configuration;
  148. //==============================================================================
  149. Value getExporterPreprocessorDefs() const { return getSetting (Ids::extraDefs); }
  150. // includes exporter, project + config defs
  151. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  152. // includes exporter + project defs..
  153. StringPairArray getAllPreprocessorDefs() const;
  154. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  155. ValueTree settings;
  156. protected:
  157. //==============================================================================
  158. String name;
  159. Project& project;
  160. const ProjectType& projectType;
  161. const String projectName;
  162. const File projectFolder;
  163. Project::Item* modulesGroup;
  164. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  165. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  166. static String getLibbedFilename (String name)
  167. {
  168. if (! name.startsWith ("lib"))
  169. name = "lib" + name;
  170. if (! name.endsWithIgnoreCase (".a"))
  171. name = name + ".a";
  172. return name;
  173. }
  174. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough);
  175. //==============================================================================
  176. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  177. {
  178. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  179. throw SaveError (file);
  180. }
  181. static void createDirectoryOrThrow (const File& dirToCreate)
  182. {
  183. if (! dirToCreate.createDirectory())
  184. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  185. }
  186. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  187. {
  188. MemoryOutputStream mo;
  189. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  190. if (useUnixNewLines)
  191. {
  192. MemoryOutputStream mo2;
  193. mo2 << mo.toString().replace ("\r\n", "\n");
  194. overwriteFileIfDifferentOrThrow (file, mo2);
  195. }
  196. else
  197. {
  198. overwriteFileIfDifferentOrThrow (file, mo);
  199. }
  200. }
  201. private:
  202. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  203. };
  204. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__