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.

337 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 bool canProjectBeLaunched (Project*);
  35. static String getCurrentPlatformExporterName();
  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. 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, msvcNeedsDLLRuntimeLib;
  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 createPropertyEditors (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 getValue (const Identifier& name) { return config.getPropertyAsValue (name, getUndoManager()); }
  151. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  152. void removeFromExporter();
  153. //==============================================================================
  154. ValueTree config;
  155. Project& project;
  156. protected:
  157. void createBasicPropertyEditors (PropertyListBuilder&);
  158. private:
  159. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration);
  160. };
  161. void addNewConfiguration (const BuildConfiguration* configToCopy);
  162. bool hasConfigurationNamed (const String& name) const;
  163. String getUniqueConfigName (String name) const;
  164. //==============================================================================
  165. struct ConfigIterator
  166. {
  167. ConfigIterator (ProjectExporter& exporter);
  168. bool next();
  169. BuildConfiguration& operator*() const { return *config; }
  170. BuildConfiguration* operator->() const { return config; }
  171. BuildConfiguration::Ptr config;
  172. int index;
  173. private:
  174. ProjectExporter& exporter;
  175. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator);
  176. };
  177. struct ConstConfigIterator
  178. {
  179. ConstConfigIterator (const ProjectExporter& exporter);
  180. bool next();
  181. const BuildConfiguration& operator*() const { return *config; }
  182. const BuildConfiguration* operator->() const { return config; }
  183. BuildConfiguration::Ptr config;
  184. int index;
  185. private:
  186. const ProjectExporter& exporter;
  187. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator);
  188. };
  189. int getNumConfigurations() const;
  190. BuildConfiguration::Ptr getConfiguration (int index) const;
  191. ValueTree getConfigurations() const;
  192. void createDefaultConfigs();
  193. static const Identifier configurations, configuration;
  194. //==============================================================================
  195. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  196. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  197. // includes exporter, project + config defs
  198. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  199. // includes exporter + project defs..
  200. StringPairArray getAllPreprocessorDefs() const;
  201. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  202. ValueTree settings;
  203. protected:
  204. //==============================================================================
  205. String name;
  206. Project& project;
  207. const ProjectType& projectType;
  208. const String projectName;
  209. const File projectFolder;
  210. mutable Array<Project::Item> itemGroups;
  211. void initItemGroups() const;
  212. Project::Item* modulesGroup;
  213. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  214. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  215. static String getLibbedFilename (String name)
  216. {
  217. if (! name.startsWith ("lib"))
  218. name = "lib" + name;
  219. if (! name.endsWithIgnoreCase (".a"))
  220. name = name + ".a";
  221. return name;
  222. }
  223. //==============================================================================
  224. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  225. {
  226. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  227. throw SaveError (file);
  228. }
  229. static void createDirectoryOrThrow (const File& dirToCreate)
  230. {
  231. if (! dirToCreate.createDirectory())
  232. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  233. }
  234. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  235. {
  236. MemoryOutputStream mo;
  237. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  238. if (useUnixNewLines)
  239. {
  240. MemoryOutputStream mo2;
  241. mo2 << mo.toString().replace ("\r\n", "\n");
  242. overwriteFileIfDifferentOrThrow (file, mo2);
  243. }
  244. else
  245. {
  246. overwriteFileIfDifferentOrThrow (file, mo);
  247. }
  248. }
  249. static Image rescaleImageForIcon (Image image, int iconSize);
  250. private:
  251. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  252. };
  253. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__