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.

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