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.

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