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.

331 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 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 ProjectExporter* createPlatformDefaultExporter (Project&);
  34. static String getCurrentPlatformExporterName();
  35. //=============================================================================
  36. // return 0 if this can't be opened in the current OS, or a higher value, where higher numbers are more preferable.
  37. virtual int getLaunchPreferenceOrderForCurrentOS() = 0;
  38. virtual bool isPossibleForCurrentProject() = 0;
  39. virtual bool usesMMFiles() const = 0;
  40. virtual void createPropertyEditors (PropertyListBuilder&);
  41. virtual void launchProject() = 0;
  42. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  43. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  44. virtual bool canCopeWithDuplicateFiles() = 0;
  45. virtual bool isXcode() const { return false; }
  46. virtual bool isVisualStudio() const { return false; }
  47. virtual int getVisualStudioVersion() const { return 0; }
  48. virtual bool isLinux() const { return false; }
  49. virtual bool isOSX() const { return false; }
  50. virtual bool isAndroid() const { return false; }
  51. //==============================================================================
  52. String getName() const { return name; }
  53. File getTargetFolder() const;
  54. Project& getProject() noexcept { return project; }
  55. const Project& getProject() const noexcept { return project; }
  56. Value getSetting (const Identifier& name) { return settings.getPropertyAsValue (name, project.getUndoManagerFor (settings)); }
  57. String getSettingString (const Identifier& name) const { return settings [name]; }
  58. Value getJuceFolderValue() { return getSetting (Ids::juceFolder); }
  59. String getJuceFolderString() const { return getSettingString (Ids::juceFolder); }
  60. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  61. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  62. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  63. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags); }
  64. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  65. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", " "); }
  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. //==============================================================================
  94. Array<Project::Item> groups;
  95. Project::Item& getModulesGroup();
  96. //==============================================================================
  97. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  98. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  99. String xcodeOtherRezFlags, xcodeExcludedFiles64Bit;
  100. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  101. StringArray xcodeFrameworks;
  102. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  103. Array<XmlElement> xcodeExtraPListEntries;
  104. //==============================================================================
  105. String makefileTargetSuffix;
  106. bool makefileIsDLL;
  107. StringArray linuxLibs;
  108. //==============================================================================
  109. String msvcTargetSuffix;
  110. StringPairArray msvcExtraPreprocessorDefs;
  111. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  112. String msvcDelayLoadedDLLs;
  113. //==============================================================================
  114. StringArray extraSearchPaths;
  115. //==============================================================================
  116. class BuildConfiguration : public ReferenceCountedObject
  117. {
  118. public:
  119. BuildConfiguration (Project& project, const ValueTree& configNode);
  120. ~BuildConfiguration();
  121. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  122. //==============================================================================
  123. virtual void createPropertyEditors (PropertyListBuilder&) = 0;
  124. //==============================================================================
  125. Value getNameValue() { return getValue (Ids::name); }
  126. String getName() const { return config [Ids::name]; }
  127. Value isDebugValue() { return getValue (Ids::isDebug); }
  128. bool isDebug() const { return config [Ids::isDebug]; }
  129. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  130. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  131. // the path relative to the build folder in which the binary should go
  132. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  133. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  134. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  135. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  136. String getGCCOptimisationFlag() const;
  137. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  138. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  139. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  140. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  141. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  142. StringArray getHeaderSearchPaths() const;
  143. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  144. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  145. StringArray getLibrarySearchPaths() const;
  146. String getGCCLibraryPathFlags() const;
  147. Value getValue (const Identifier& name) { return config.getPropertyAsValue (name, getUndoManager()); }
  148. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  149. void removeFromExporter();
  150. //==============================================================================
  151. ValueTree config;
  152. Project& project;
  153. protected:
  154. void createBasicPropertyEditors (PropertyListBuilder&);
  155. private:
  156. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration);
  157. };
  158. void addNewConfiguration (const BuildConfiguration* configToCopy);
  159. bool hasConfigurationNamed (const String& name) const;
  160. String getUniqueConfigName (String name) const;
  161. //==============================================================================
  162. struct ConfigIterator
  163. {
  164. ConfigIterator (ProjectExporter& exporter);
  165. bool next();
  166. BuildConfiguration& operator*() const { return *config; }
  167. BuildConfiguration* operator->() const { return config; }
  168. BuildConfiguration::Ptr config;
  169. int index;
  170. private:
  171. ProjectExporter& exporter;
  172. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator);
  173. };
  174. struct ConstConfigIterator
  175. {
  176. ConstConfigIterator (const ProjectExporter& exporter);
  177. bool next();
  178. const BuildConfiguration& operator*() const { return *config; }
  179. const BuildConfiguration* operator->() const { return config; }
  180. BuildConfiguration::Ptr config;
  181. int index;
  182. private:
  183. const ProjectExporter& exporter;
  184. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator);
  185. };
  186. int getNumConfigurations() const;
  187. BuildConfiguration::Ptr getConfiguration (int index) const;
  188. ValueTree getConfigurations() const;
  189. void createDefaultConfigs();
  190. static const Identifier configurations, configuration;
  191. //==============================================================================
  192. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  193. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  194. // includes exporter, project + config defs
  195. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  196. // includes exporter + project defs..
  197. StringPairArray getAllPreprocessorDefs() const;
  198. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  199. ValueTree settings;
  200. protected:
  201. //==============================================================================
  202. String name;
  203. Project& project;
  204. const ProjectType& projectType;
  205. const String projectName;
  206. const File projectFolder;
  207. Project::Item* modulesGroup;
  208. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  209. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  210. static String getLibbedFilename (String name)
  211. {
  212. if (! name.startsWith ("lib"))
  213. name = "lib" + name;
  214. if (! name.endsWithIgnoreCase (".a"))
  215. name = name + ".a";
  216. return name;
  217. }
  218. //==============================================================================
  219. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  220. {
  221. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  222. throw SaveError (file);
  223. }
  224. static void createDirectoryOrThrow (const File& dirToCreate)
  225. {
  226. if (! dirToCreate.createDirectory())
  227. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  228. }
  229. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  230. {
  231. MemoryOutputStream mo;
  232. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  233. if (useUnixNewLines)
  234. {
  235. MemoryOutputStream mo2;
  236. mo2 << mo.toString().replace ("\r\n", "\n");
  237. overwriteFileIfDifferentOrThrow (file, mo2);
  238. }
  239. else
  240. {
  241. overwriteFileIfDifferentOrThrow (file, mo);
  242. }
  243. }
  244. static Image rescaleImageForIcon (Image image, int iconSize);
  245. private:
  246. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  247. };
  248. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__