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.

352 lines
15KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_PROJECTEXPORTER_JUCEHEADER__
  18. #define __JUCER_PROJECTEXPORTER_JUCEHEADER__
  19. #include "../jucer_Headers.h"
  20. #include "../Project/jucer_Project.h"
  21. #include "../Project/jucer_ProjectType.h"
  22. //==============================================================================
  23. class ProjectExporter
  24. {
  25. public:
  26. ProjectExporter (Project&, const ValueTree& settings);
  27. virtual ~ProjectExporter();
  28. static StringArray getExporterNames();
  29. static ProjectExporter* createNewExporter (Project&, const int index);
  30. static ProjectExporter* createNewExporter (Project&, const String& name);
  31. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  32. static bool canProjectBeLaunched (Project*);
  33. static String getCurrentPlatformExporterName();
  34. //=============================================================================
  35. virtual bool usesMMFiles() const = 0;
  36. virtual void createExporterProperties (PropertyListBuilder&) = 0;
  37. virtual bool canLaunchProject() = 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 bool isWindows() const { return false; }
  45. virtual int getVisualStudioVersion() const { return 0; }
  46. virtual bool isLinux() const { return false; }
  47. virtual bool isOSX() const { return false; }
  48. virtual bool isAndroid() const { return false; }
  49. virtual bool isCodeBlocks() const { return false; }
  50. //==============================================================================
  51. String getName() const { return name; }
  52. File getTargetFolder() const;
  53. Project& getProject() noexcept { return project; }
  54. const Project& getProject() const noexcept { return project; }
  55. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  56. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  57. Value getJuceFolderValue() { return getSetting (Ids::juceFolder); }
  58. String getJuceFolderString() const { return getSettingString (Ids::juceFolder); }
  59. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  60. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  61. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  62. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags).replaceCharacters ("\r\n", " "); }
  63. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  64. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", " "); }
  65. Value getExternalLibraries() { return getSetting (Ids::externalLibraries); }
  66. String getExternalLibrariesString() const { return getSettingString (Ids::externalLibraries).replaceCharacters ("\r\n", " ;"); }
  67. Value getUserNotes() { return getSetting (Ids::userNotes); }
  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. StringArray mingwLibs;
  117. //==============================================================================
  118. StringArray extraSearchPaths;
  119. //==============================================================================
  120. class BuildConfiguration : public ReferenceCountedObject
  121. {
  122. public:
  123. BuildConfiguration (Project& project, const ValueTree& configNode);
  124. ~BuildConfiguration();
  125. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  126. //==============================================================================
  127. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  128. //==============================================================================
  129. Value getNameValue() { return getValue (Ids::name); }
  130. String getName() const { return config [Ids::name]; }
  131. Value isDebugValue() { return getValue (Ids::isDebug); }
  132. bool isDebug() const { return config [Ids::isDebug]; }
  133. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  134. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  135. // the path relative to the build folder in which the binary should go
  136. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  137. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  138. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  139. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  140. String getGCCOptimisationFlag() const;
  141. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  142. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  143. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  144. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  145. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  146. StringArray getHeaderSearchPaths() const;
  147. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  148. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  149. StringArray getLibrarySearchPaths() const;
  150. String getGCCLibraryPathFlags() const;
  151. Value getUserNotes() { return getValue (Ids::userNotes); }
  152. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  153. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  154. void createPropertyEditors (PropertyListBuilder&);
  155. void removeFromExporter();
  156. //==============================================================================
  157. ValueTree config;
  158. Project& project;
  159. protected:
  160. private:
  161. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  162. };
  163. void addNewConfiguration (const BuildConfiguration* configToCopy);
  164. bool hasConfigurationNamed (const String& name) const;
  165. String getUniqueConfigName (String name) const;
  166. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  167. //==============================================================================
  168. struct ConfigIterator
  169. {
  170. ConfigIterator (ProjectExporter& exporter);
  171. bool next();
  172. BuildConfiguration& operator*() const { return *config; }
  173. BuildConfiguration* operator->() const { return config; }
  174. BuildConfiguration::Ptr config;
  175. int index;
  176. private:
  177. ProjectExporter& exporter;
  178. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  179. };
  180. struct ConstConfigIterator
  181. {
  182. ConstConfigIterator (const ProjectExporter& exporter);
  183. bool next();
  184. const BuildConfiguration& operator*() const { return *config; }
  185. const BuildConfiguration* operator->() const { return config; }
  186. BuildConfiguration::Ptr config;
  187. int index;
  188. private:
  189. const ProjectExporter& exporter;
  190. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  191. };
  192. int getNumConfigurations() const;
  193. BuildConfiguration::Ptr getConfiguration (int index) const;
  194. ValueTree getConfigurations() const;
  195. void createDefaultConfigs();
  196. static const Identifier configurations, configuration;
  197. //==============================================================================
  198. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  199. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  200. // includes exporter, project + config defs
  201. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  202. // includes exporter + project defs..
  203. StringPairArray getAllPreprocessorDefs() const;
  204. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  205. ValueTree settings;
  206. //==============================================================================
  207. enum OptimisationLevel
  208. {
  209. optimisationOff = 1,
  210. optimiseMinSize = 2,
  211. optimiseMaxSpeed = 3
  212. };
  213. protected:
  214. //==============================================================================
  215. String name;
  216. Project& project;
  217. const ProjectType& projectType;
  218. const String projectName;
  219. const File projectFolder;
  220. mutable Array<Project::Item> itemGroups;
  221. void initItemGroups() const;
  222. Project::Item* modulesGroup;
  223. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  224. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  225. static String getLibbedFilename (String name)
  226. {
  227. if (! name.startsWith ("lib"))
  228. name = "lib" + name;
  229. if (! name.endsWithIgnoreCase (".a"))
  230. name = name + ".a";
  231. return name;
  232. }
  233. //==============================================================================
  234. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  235. {
  236. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  237. throw SaveError (file);
  238. }
  239. static void createDirectoryOrThrow (const File& dirToCreate)
  240. {
  241. if (! dirToCreate.createDirectory())
  242. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  243. }
  244. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  245. {
  246. MemoryOutputStream mo;
  247. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  248. if (useUnixNewLines)
  249. {
  250. MemoryOutputStream mo2;
  251. mo2 << mo.toString().replace ("\r\n", "\n");
  252. overwriteFileIfDifferentOrThrow (file, mo2);
  253. }
  254. else
  255. {
  256. overwriteFileIfDifferentOrThrow (file, mo);
  257. }
  258. }
  259. static Image rescaleImageForIcon (Image image, int iconSize);
  260. private:
  261. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  262. };
  263. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__