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.

350 lines
15KB

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