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.

351 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 launchProject() = 0;
  38. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  39. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  40. virtual bool canCopeWithDuplicateFiles() = 0;
  41. virtual bool isXcode() const { return false; }
  42. virtual bool isVisualStudio() const { return false; }
  43. virtual bool isWindows() 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. virtual bool isCodeBlocks() const { return false; }
  49. //==============================================================================
  50. String getName() const { return name; }
  51. File getTargetFolder() const;
  52. Project& getProject() noexcept { return project; }
  53. const Project& getProject() const noexcept { return project; }
  54. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  55. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  56. Value getJuceFolderValue() { return getSetting (Ids::juceFolder); }
  57. String getJuceFolderString() const { return getSettingString (Ids::juceFolder); }
  58. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  59. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  60. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  61. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags).replaceCharacters ("\r\n", " "); }
  62. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  63. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", " "); }
  64. Value getExternalLibraries() { return getSetting (Ids::externalLibraries); }
  65. String getExternalLibrariesString() const { return getSettingString (Ids::externalLibraries).replaceCharacters ("\r\n", " ;"); }
  66. Value getUserNotes() { return getSetting (Ids::userNotes); }
  67. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  68. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  69. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  70. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  71. Image getBigIcon() const;
  72. Image getSmallIcon() const;
  73. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  74. String getExporterIdentifierMacro() const
  75. {
  76. return "JUCER_" + settings.getType().toString() + "_"
  77. + String::toHexString (getSettingString (Ids::targetFolder).hashCode()).toUpperCase();
  78. }
  79. // An exception that can be thrown by the create() method.
  80. class SaveError
  81. {
  82. public:
  83. SaveError (const String& error) : message (error)
  84. {}
  85. SaveError (const File& fileThatFailedToWrite)
  86. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  87. {}
  88. String message;
  89. };
  90. RelativePath getJucePathFromTargetFolder() const;
  91. RelativePath getJucePathFromProjectFolder() const;
  92. void createPropertyEditors (PropertyListBuilder& props);
  93. //==============================================================================
  94. void copyMainGroupFromProject();
  95. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  96. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  97. Project::Item& getModulesGroup();
  98. //==============================================================================
  99. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  100. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  101. String xcodeOtherRezFlags, xcodeExcludedFiles64Bit;
  102. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  103. StringArray xcodeFrameworks;
  104. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  105. Array<XmlElement> xcodeExtraPListEntries;
  106. //==============================================================================
  107. String makefileTargetSuffix;
  108. bool makefileIsDLL;
  109. StringArray linuxLibs;
  110. //==============================================================================
  111. String msvcTargetSuffix;
  112. StringPairArray msvcExtraPreprocessorDefs;
  113. bool msvcIsDLL, msvcIsWindowsSubsystem;
  114. String msvcDelayLoadedDLLs;
  115. StringArray mingwLibs;
  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. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  166. //==============================================================================
  167. struct ConfigIterator
  168. {
  169. ConfigIterator (ProjectExporter& exporter);
  170. bool next();
  171. BuildConfiguration& operator*() const { return *config; }
  172. BuildConfiguration* operator->() const { return config; }
  173. BuildConfiguration::Ptr config;
  174. int index;
  175. private:
  176. ProjectExporter& exporter;
  177. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  178. };
  179. struct ConstConfigIterator
  180. {
  181. ConstConfigIterator (const ProjectExporter& exporter);
  182. bool next();
  183. const BuildConfiguration& operator*() const { return *config; }
  184. const BuildConfiguration* operator->() const { return config; }
  185. BuildConfiguration::Ptr config;
  186. int index;
  187. private:
  188. const ProjectExporter& exporter;
  189. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  190. };
  191. int getNumConfigurations() const;
  192. BuildConfiguration::Ptr getConfiguration (int index) const;
  193. ValueTree getConfigurations() const;
  194. void createDefaultConfigs();
  195. static const Identifier configurations, configuration;
  196. //==============================================================================
  197. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  198. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  199. // includes exporter, project + config defs
  200. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  201. // includes exporter + project defs..
  202. StringPairArray getAllPreprocessorDefs() const;
  203. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  204. ValueTree settings;
  205. //==============================================================================
  206. enum OptimisationLevel
  207. {
  208. optimisationOff = 1,
  209. optimiseMinSize = 2,
  210. optimiseMaxSpeed = 3
  211. };
  212. protected:
  213. //==============================================================================
  214. String name;
  215. Project& project;
  216. const ProjectType& projectType;
  217. const String projectName;
  218. const File projectFolder;
  219. mutable Array<Project::Item> itemGroups;
  220. void initItemGroups() const;
  221. Project::Item* modulesGroup;
  222. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  223. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  224. static String getLibbedFilename (String name)
  225. {
  226. if (! name.startsWith ("lib"))
  227. name = "lib" + name;
  228. if (! name.endsWithIgnoreCase (".a"))
  229. name = name + ".a";
  230. return name;
  231. }
  232. //==============================================================================
  233. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  234. {
  235. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  236. throw SaveError (file);
  237. }
  238. static void createDirectoryOrThrow (const File& dirToCreate)
  239. {
  240. if (! dirToCreate.createDirectory())
  241. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  242. }
  243. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  244. {
  245. MemoryOutputStream mo;
  246. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  247. if (useUnixNewLines)
  248. {
  249. MemoryOutputStream mo2;
  250. mo2 << mo.toString().replace ("\r\n", "\n");
  251. overwriteFileIfDifferentOrThrow (file, mo2);
  252. }
  253. else
  254. {
  255. overwriteFileIfDifferentOrThrow (file, mo);
  256. }
  257. }
  258. static Image rescaleImageForIcon (Image image, int iconSize);
  259. private:
  260. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  261. };
  262. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__