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.

339 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 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& name) { return settings.getPropertyAsValue (name, project.getUndoManagerFor (settings)); }
  54. String getSettingString (const Identifier& name) const { return settings [name]; }
  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 getUserNotes() { return getSetting (Ids::userNotes); }
  64. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  65. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  66. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  67. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  68. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  69. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  70. Image getBigIcon() const;
  71. Image getSmallIcon() const;
  72. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  73. String getExporterIdentifierMacro() const
  74. {
  75. return "JUCER_" + settings.getType().toString() + "_"
  76. + String::toHexString (getSettingString (Ids::targetFolder).hashCode()).toUpperCase();
  77. }
  78. // An exception that can be thrown by the create() method.
  79. class SaveError
  80. {
  81. public:
  82. SaveError (const String& error) : message (error)
  83. {}
  84. SaveError (const File& fileThatFailedToWrite)
  85. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  86. {}
  87. String message;
  88. };
  89. RelativePath getJucePathFromTargetFolder() const;
  90. RelativePath getJucePathFromProjectFolder() const;
  91. void createPropertyEditors (PropertyListBuilder& props);
  92. //==============================================================================
  93. void copyMainGroupFromProject();
  94. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  95. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  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 createConfigProperties (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 getUserNotes() { return getValue (Ids::userNotes); }
  149. Value getValue (const Identifier& name) { return config.getPropertyAsValue (name, getUndoManager()); }
  150. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  151. void createPropertyEditors (PropertyListBuilder&);
  152. void removeFromExporter();
  153. //==============================================================================
  154. ValueTree config;
  155. Project& project;
  156. protected:
  157. private:
  158. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration);
  159. };
  160. void addNewConfiguration (const BuildConfiguration* configToCopy);
  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. mutable Array<Project::Item> itemGroups;
  210. void initItemGroups() const;
  211. Project::Item* modulesGroup;
  212. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  213. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  214. static String getLibbedFilename (String name)
  215. {
  216. if (! name.startsWith ("lib"))
  217. name = "lib" + name;
  218. if (! name.endsWithIgnoreCase (".a"))
  219. name = name + ".a";
  220. return name;
  221. }
  222. //==============================================================================
  223. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  224. {
  225. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  226. throw SaveError (file);
  227. }
  228. static void createDirectoryOrThrow (const File& dirToCreate)
  229. {
  230. if (! dirToCreate.createDirectory())
  231. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  232. }
  233. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  234. {
  235. MemoryOutputStream mo;
  236. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  237. if (useUnixNewLines)
  238. {
  239. MemoryOutputStream mo2;
  240. mo2 << mo.toString().replace ("\r\n", "\n");
  241. overwriteFileIfDifferentOrThrow (file, mo2);
  242. }
  243. else
  244. {
  245. overwriteFileIfDifferentOrThrow (file, mo);
  246. }
  247. }
  248. static Image rescaleImageForIcon (Image image, int iconSize);
  249. private:
  250. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  251. };
  252. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__