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).replaceCharacters ("\r\n", " "); }
  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 xcodeOtherRezFlags, xcodeExcludedFiles64Bit;
  101. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  102. StringArray xcodeFrameworks;
  103. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  104. Array<XmlElement> xcodeExtraPListEntries;
  105. //==============================================================================
  106. String makefileTargetSuffix;
  107. bool makefileIsDLL;
  108. StringArray linuxLibs;
  109. //==============================================================================
  110. String msvcTargetSuffix;
  111. StringPairArray msvcExtraPreprocessorDefs;
  112. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  113. String msvcDelayLoadedDLLs;
  114. //==============================================================================
  115. StringArray extraSearchPaths;
  116. //==============================================================================
  117. class BuildConfiguration : public ReferenceCountedObject
  118. {
  119. public:
  120. BuildConfiguration (Project& project, const ValueTree& configNode);
  121. ~BuildConfiguration();
  122. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  123. //==============================================================================
  124. virtual void createPropertyEditors (PropertyListBuilder&) = 0;
  125. //==============================================================================
  126. Value getNameValue() { return getValue (Ids::name); }
  127. String getName() const { return config [Ids::name]; }
  128. Value isDebugValue() { return getValue (Ids::isDebug); }
  129. bool isDebug() const { return config [Ids::isDebug]; }
  130. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  131. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  132. // the path relative to the build folder in which the binary should go
  133. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  134. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  135. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  136. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  137. String getGCCOptimisationFlag() const;
  138. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  139. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  140. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  141. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  142. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  143. StringArray getHeaderSearchPaths() const;
  144. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  145. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  146. StringArray getLibrarySearchPaths() const;
  147. String getGCCLibraryPathFlags() const;
  148. Value getValue (const Identifier& name) { return config.getPropertyAsValue (name, getUndoManager()); }
  149. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  150. void removeFromExporter();
  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. bool hasConfigurationNamed (const String& name) const;
  161. String getUniqueConfigName (String name) const;
  162. //==============================================================================
  163. struct ConfigIterator
  164. {
  165. ConfigIterator (ProjectExporter& exporter);
  166. bool next();
  167. BuildConfiguration& operator*() const { return *config; }
  168. BuildConfiguration* operator->() const { return config; }
  169. BuildConfiguration::Ptr config;
  170. int index;
  171. private:
  172. ProjectExporter& exporter;
  173. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator);
  174. };
  175. struct ConstConfigIterator
  176. {
  177. ConstConfigIterator (const ProjectExporter& exporter);
  178. bool next();
  179. const BuildConfiguration& operator*() const { return *config; }
  180. const BuildConfiguration* operator->() const { return config; }
  181. BuildConfiguration::Ptr config;
  182. int index;
  183. private:
  184. const ProjectExporter& exporter;
  185. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator);
  186. };
  187. int getNumConfigurations() const;
  188. BuildConfiguration::Ptr getConfiguration (int index) const;
  189. ValueTree getConfigurations() const;
  190. void createDefaultConfigs();
  191. static const Identifier configurations, configuration;
  192. //==============================================================================
  193. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  194. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  195. // includes exporter, project + config defs
  196. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  197. // includes exporter + project defs..
  198. StringPairArray getAllPreprocessorDefs() const;
  199. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  200. ValueTree settings;
  201. protected:
  202. //==============================================================================
  203. String name;
  204. Project& project;
  205. const ProjectType& projectType;
  206. const String projectName;
  207. const File projectFolder;
  208. Project::Item* modulesGroup;
  209. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  210. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  211. static String getLibbedFilename (String name)
  212. {
  213. if (! name.startsWith ("lib"))
  214. name = "lib" + name;
  215. if (! name.endsWithIgnoreCase (".a"))
  216. name = name + ".a";
  217. return name;
  218. }
  219. //==============================================================================
  220. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  221. {
  222. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  223. throw SaveError (file);
  224. }
  225. static void createDirectoryOrThrow (const File& dirToCreate)
  226. {
  227. if (! dirToCreate.createDirectory())
  228. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  229. }
  230. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  231. {
  232. MemoryOutputStream mo;
  233. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  234. if (useUnixNewLines)
  235. {
  236. MemoryOutputStream mo2;
  237. mo2 << mo.toString().replace ("\r\n", "\n");
  238. overwriteFileIfDifferentOrThrow (file, mo2);
  239. }
  240. else
  241. {
  242. overwriteFileIfDifferentOrThrow (file, mo);
  243. }
  244. }
  245. static Image rescaleImageForIcon (Image image, int iconSize);
  246. private:
  247. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  248. };
  249. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__