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.

286 lines
12KB

  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 msvcDelayLoadedDLLs;
  102. //==============================================================================
  103. StringArray extraSearchPaths;
  104. //==============================================================================
  105. class BuildConfiguration : public ReferenceCountedObject
  106. {
  107. public:
  108. BuildConfiguration (Project& project, const ValueTree& configNode);
  109. ~BuildConfiguration();
  110. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  111. //==============================================================================
  112. virtual void createPropertyEditors (PropertyListBuilder&) = 0;
  113. //==============================================================================
  114. Value getName() const { return getValue (Ids::name); }
  115. Value isDebug() const { return getValue (Ids::isDebug); }
  116. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  117. // the path relative to the build folder in which the binary should go
  118. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  119. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  120. String getGCCOptimisationFlag() const;
  121. Value getBuildConfigPreprocessorDefs() const { return getValue (Ids::defines); }
  122. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  123. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  124. StringArray getHeaderSearchPaths() const;
  125. //==============================================================================
  126. ValueTree config;
  127. //==============================================================================
  128. String msvcExtraLinkerOptions, msvcModuleDefinitionFile;
  129. String msvcPostBuildCommand, msvcPostBuildOutputs;
  130. String msvcPreBuildCommand;
  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. void addNewConfiguration (const BuildConfiguration* configToCopy);
  140. void deleteConfiguration (int index);
  141. bool hasConfigurationNamed (const String& name) const;
  142. String getUniqueConfigName (String name) const;
  143. //==============================================================================
  144. struct ConfigIterator
  145. {
  146. ConfigIterator (ProjectExporter& exporter);
  147. bool next();
  148. BuildConfiguration& operator*() const { return *config; }
  149. BuildConfiguration* operator->() const { return config; }
  150. BuildConfiguration::Ptr config;
  151. int index;
  152. private:
  153. ProjectExporter& exporter;
  154. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator);
  155. };
  156. int getNumConfigurations() const;
  157. BuildConfiguration::Ptr getConfiguration (int index) const;
  158. ValueTree getConfigurations() const;
  159. void createDefaultConfigs();
  160. static const Identifier configurations, configuration;
  161. //==============================================================================
  162. Value getExporterPreprocessorDefs() const { return getSetting (Ids::extraDefs); }
  163. // includes exporter, project + config defs
  164. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  165. // includes exporter + project defs..
  166. StringPairArray getAllPreprocessorDefs() const;
  167. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  168. ValueTree settings;
  169. protected:
  170. //==============================================================================
  171. String name;
  172. Project& project;
  173. const ProjectType& projectType;
  174. const String projectName;
  175. const File projectFolder;
  176. Project::Item* modulesGroup;
  177. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  178. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  179. static String getLibbedFilename (String name)
  180. {
  181. if (! name.startsWith ("lib"))
  182. name = "lib" + name;
  183. if (! name.endsWithIgnoreCase (".a"))
  184. name = name + ".a";
  185. return name;
  186. }
  187. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough);
  188. //==============================================================================
  189. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  190. {
  191. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  192. throw SaveError (file);
  193. }
  194. static void createDirectoryOrThrow (const File& dirToCreate)
  195. {
  196. if (! dirToCreate.createDirectory())
  197. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  198. }
  199. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  200. {
  201. MemoryOutputStream mo;
  202. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  203. if (useUnixNewLines)
  204. {
  205. MemoryOutputStream mo2;
  206. mo2 << mo.toString().replace ("\r\n", "\n");
  207. overwriteFileIfDifferentOrThrow (file, mo2);
  208. }
  209. else
  210. {
  211. overwriteFileIfDifferentOrThrow (file, mo);
  212. }
  213. }
  214. private:
  215. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  216. };
  217. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__