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.

332 lines
14KB

  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>&) const = 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 int getVisualStudioVersion() const { return 0; }
  49. virtual bool isLinux() const { return false; }
  50. virtual bool isOSX() const { return false; }
  51. virtual bool isAndroid() const { return false; }
  52. //==============================================================================
  53. String getName() const { return name; }
  54. File getTargetFolder() const;
  55. Project& getProject() noexcept { return project; }
  56. const Project& getProject() const noexcept { return project; }
  57. Value getSetting (const Identifier& name) { return settings.getPropertyAsValue (name, project.getUndoManagerFor (settings)); }
  58. String getSettingString (const Identifier& name) const { return settings [name]; }
  59. Value getJuceFolderValue() { return getSetting (Ids::juceFolder); }
  60. String getJuceFolderString() const { return getSettingString (Ids::juceFolder); }
  61. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  62. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  63. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  64. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags); }
  65. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  66. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags); }
  67. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  68. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  69. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  70. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  71. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  72. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  73. Image getBigIcon() const;
  74. Image getSmallIcon() const;
  75. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  76. String getExporterIdentifierMacro() const
  77. {
  78. return "JUCER_" + settings.getType().toString() + "_"
  79. + String::toHexString (getSettingString (Ids::targetFolder).hashCode()).toUpperCase();
  80. }
  81. // An exception that can be thrown by the create() method.
  82. class SaveError
  83. {
  84. public:
  85. SaveError (const String& error) : message (error)
  86. {}
  87. SaveError (const File& fileThatFailedToWrite)
  88. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  89. {}
  90. String message;
  91. };
  92. RelativePath getJucePathFromTargetFolder() const;
  93. RelativePath getJucePathFromProjectFolder() const;
  94. //==============================================================================
  95. Array<Project::Item> groups;
  96. Project::Item& getModulesGroup();
  97. //==============================================================================
  98. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  99. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  100. String xcodeShellScript, xcodeShellScriptTitle, xcodeOtherRezFlags;
  101. String xcodeExcludedFiles64Bit;
  102. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  103. StringArray xcodeFrameworks;
  104. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  105. Array<XmlElement> xcodeExtraPListEntries;
  106. //==============================================================================
  107. String makefileTargetSuffix;
  108. bool makefileIsDLL;
  109. StringArray linuxLibs;
  110. //==============================================================================
  111. String msvcTargetSuffix;
  112. StringPairArray msvcExtraPreprocessorDefs;
  113. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  114. String msvcDelayLoadedDLLs;
  115. //==============================================================================
  116. StringArray extraSearchPaths;
  117. //==============================================================================
  118. class BuildConfiguration : public ReferenceCountedObject
  119. {
  120. public:
  121. BuildConfiguration (Project& project, const ValueTree& configNode);
  122. ~BuildConfiguration();
  123. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  124. //==============================================================================
  125. virtual void createPropertyEditors (PropertyListBuilder&) = 0;
  126. //==============================================================================
  127. Value getNameValue() { return getValue (Ids::name); }
  128. String getName() const { return config [Ids::name]; }
  129. Value isDebugValue() { return getValue (Ids::isDebug); }
  130. bool isDebug() const { return config [Ids::isDebug]; }
  131. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  132. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  133. // the path relative to the build folder in which the binary should go
  134. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  135. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  136. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  137. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  138. String getGCCOptimisationFlag() const;
  139. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  140. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  141. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  142. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  143. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  144. StringArray getHeaderSearchPaths() const;
  145. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  146. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  147. StringArray getLibrarySearchPaths() const;
  148. String getGCCLibraryPathFlags() const;
  149. Value getValue (const Identifier& name) { return config.getPropertyAsValue (name, getUndoManager()); }
  150. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  151. //==============================================================================
  152. ValueTree config;
  153. Project& project;
  154. protected:
  155. void createBasicPropertyEditors (PropertyListBuilder&);
  156. private:
  157. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration);
  158. };
  159. void addNewConfiguration (const BuildConfiguration* configToCopy);
  160. void deleteConfiguration (int index);
  161. bool hasConfigurationNamed (const String& name) const;
  162. String getUniqueConfigName (String name) const;
  163. //==============================================================================
  164. struct ConfigIterator
  165. {
  166. ConfigIterator (ProjectExporter& exporter);
  167. bool next();
  168. BuildConfiguration& operator*() const { return *config; }
  169. BuildConfiguration* operator->() const { return config; }
  170. BuildConfiguration::Ptr config;
  171. int index;
  172. private:
  173. ProjectExporter& exporter;
  174. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator);
  175. };
  176. struct ConstConfigIterator
  177. {
  178. ConstConfigIterator (const ProjectExporter& exporter);
  179. bool next();
  180. const BuildConfiguration& operator*() const { return *config; }
  181. const BuildConfiguration* operator->() const { return config; }
  182. BuildConfiguration::Ptr config;
  183. int index;
  184. private:
  185. const ProjectExporter& exporter;
  186. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator);
  187. };
  188. int getNumConfigurations() const;
  189. BuildConfiguration::Ptr getConfiguration (int index) const;
  190. ValueTree getConfigurations() const;
  191. void createDefaultConfigs();
  192. static const Identifier configurations, configuration;
  193. //==============================================================================
  194. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  195. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  196. // includes exporter, project + config defs
  197. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  198. // includes exporter + project defs..
  199. StringPairArray getAllPreprocessorDefs() const;
  200. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  201. ValueTree settings;
  202. protected:
  203. //==============================================================================
  204. String name;
  205. Project& project;
  206. const ProjectType& projectType;
  207. const String projectName;
  208. const File projectFolder;
  209. Project::Item* modulesGroup;
  210. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  211. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  212. static String getLibbedFilename (String name)
  213. {
  214. if (! name.startsWith ("lib"))
  215. name = "lib" + name;
  216. if (! name.endsWithIgnoreCase (".a"))
  217. name = name + ".a";
  218. return name;
  219. }
  220. //==============================================================================
  221. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  222. {
  223. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  224. throw SaveError (file);
  225. }
  226. static void createDirectoryOrThrow (const File& dirToCreate)
  227. {
  228. if (! dirToCreate.createDirectory())
  229. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  230. }
  231. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  232. {
  233. MemoryOutputStream mo;
  234. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  235. if (useUnixNewLines)
  236. {
  237. MemoryOutputStream mo2;
  238. mo2 << mo.toString().replace ("\r\n", "\n");
  239. overwriteFileIfDifferentOrThrow (file, mo2);
  240. }
  241. else
  242. {
  243. overwriteFileIfDifferentOrThrow (file, mo);
  244. }
  245. }
  246. static Image rescaleImageForIcon (Image image, int iconSize);
  247. private:
  248. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  249. };
  250. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__