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.

416 lines
17KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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_H_INCLUDED
  18. #define JUCER_PROJECTEXPORTER_H_INCLUDED
  19. #include "../Project/jucer_Project.h"
  20. #include "../Project/jucer_ProjectType.h"
  21. #include "../Application/jucer_GlobalPreferences.h"
  22. class ProjectSaver;
  23. //==============================================================================
  24. class ProjectExporter
  25. {
  26. public:
  27. ProjectExporter (Project&, const ValueTree& settings);
  28. virtual ~ProjectExporter();
  29. struct ExporterTypeInfo
  30. {
  31. String name;
  32. const void* iconData;
  33. int iconDataSize;
  34. Image getIcon() const { return ImageCache::getFromMemory (iconData, iconDataSize); }
  35. };
  36. static StringArray getExporterNames();
  37. static Array<ExporterTypeInfo> getExporterTypes();
  38. static ProjectExporter* createNewExporter (Project&, const int index);
  39. static ProjectExporter* createNewExporter (Project&, const String& name);
  40. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  41. static bool canProjectBeLaunched (Project*);
  42. static String getCurrentPlatformExporterName();
  43. //==============================================================================
  44. // capabilities of exporter
  45. virtual bool usesMMFiles() const = 0;
  46. virtual void createExporterProperties (PropertyListBuilder&) = 0;
  47. virtual bool canLaunchProject() = 0;
  48. virtual bool launchProject() = 0;
  49. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  50. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  51. virtual bool canCopeWithDuplicateFiles() = 0;
  52. virtual bool supportsUserDefinedConfigurations() const = 0; // false if exporter only supports two configs Debug and Release
  53. // IDE targeted by exporter
  54. virtual bool isXcode() const = 0;
  55. virtual bool isVisualStudio() const = 0;
  56. virtual bool isCodeBlocks() const = 0;
  57. virtual bool isMakefile() const = 0;
  58. virtual bool isAndroidStudio() const = 0;
  59. virtual bool isAndroidAnt() const = 0;
  60. // operating system targeted by exporter
  61. virtual bool isAndroid() const = 0;
  62. virtual bool isWindows() const = 0;
  63. virtual bool isLinux() const = 0;
  64. virtual bool isOSX() const = 0;
  65. virtual bool isiOS() const = 0;
  66. // cross-platform audio plug-ins supported by exporter
  67. virtual bool supportsVST() const = 0;
  68. virtual bool supportsVST3() const = 0;
  69. virtual bool supportsAAX() const = 0;
  70. virtual bool supportsRTAS() const = 0;
  71. virtual bool supportsAU() const = 0;
  72. virtual bool supportsAUv3() const = 0;
  73. virtual bool supportsStandalone() const = 0; // as in Standalong plug-in type, not GUIApp or ConsoleApp
  74. //==============================================================================
  75. bool mayCompileOnCurrentOS() const
  76. {
  77. #if JUCE_MAC
  78. return isOSX() || isAndroid();
  79. #elif JUCE_WINDOWS
  80. return isWindows() || isAndroid();
  81. #elif JUCE_LINUX
  82. return isLinux() || isAndroid();
  83. #else
  84. #error
  85. #endif
  86. }
  87. //==============================================================================
  88. String getName() const { return name; }
  89. File getTargetFolder() const;
  90. Project& getProject() noexcept { return project; }
  91. const Project& getProject() const noexcept { return project; }
  92. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  93. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  94. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  95. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  96. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  97. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags).replaceCharacters ("\r\n", " "); }
  98. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  99. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", " "); }
  100. Value getExternalLibraries() { return getSetting (Ids::externalLibraries); }
  101. String getExternalLibrariesString() const { return getSearchPathsFromString (getSettingString (Ids::externalLibraries)).joinIntoString (";"); }
  102. Value getUserNotes() { return getSetting (Ids::userNotes); }
  103. Value getVSTPathValue (bool isVST3) const { return isVST3 ? vst3Path : vst2Path; }
  104. Value getRTASPathValue() const { return rtasPath; }
  105. Value getAAXPathValue() const { return aaxPath; }
  106. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  107. // module folder itself.
  108. Value getPathForModuleValue (const String& moduleID);
  109. String getPathForModuleString (const String& moduleID) const;
  110. void removePathForModule (const String& moduleID);
  111. RelativePath getLegacyModulePath (const String& moduleID) const;
  112. String getLegacyModulePath() const;
  113. // Returns a path to the actual module folder itself
  114. RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  115. void updateOldModulePaths();
  116. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  117. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder, int index = -1);
  118. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  119. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  120. Drawable* getBigIcon() const;
  121. Drawable* getSmallIcon() const;
  122. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  123. String getExporterIdentifierMacro() const
  124. {
  125. return "JUCER_" + settings.getType().toString() + "_"
  126. + String::toHexString (getSettingString (Ids::targetFolder).hashCode()).toUpperCase();
  127. }
  128. // An exception that can be thrown by the create() method.
  129. class SaveError
  130. {
  131. public:
  132. SaveError (const String& error) : message (error)
  133. {}
  134. SaveError (const File& fileThatFailedToWrite)
  135. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  136. {}
  137. String message;
  138. };
  139. void createPropertyEditors (PropertyListBuilder&);
  140. void addSettingsForProjectType (const ProjectType&);
  141. //==============================================================================
  142. void copyMainGroupFromProject();
  143. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  144. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  145. Project::Item& getModulesGroup();
  146. //==============================================================================
  147. String makefileTargetSuffix;
  148. bool makefileIsDLL;
  149. StringArray linuxLibs, makefileExtraLinkerFlags;
  150. //==============================================================================
  151. String msvcTargetSuffix;
  152. StringPairArray msvcExtraPreprocessorDefs;
  153. bool msvcIsDLL, msvcIsWindowsSubsystem;
  154. String msvcDelayLoadedDLLs;
  155. StringArray mingwLibs;
  156. //==============================================================================
  157. StringArray extraSearchPaths;
  158. //==============================================================================
  159. class BuildConfiguration : public ReferenceCountedObject
  160. {
  161. public:
  162. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  163. ~BuildConfiguration();
  164. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  165. //==============================================================================
  166. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  167. virtual var getDefaultOptimisationLevel() const = 0;
  168. //==============================================================================
  169. Value getNameValue() { return getValue (Ids::name); }
  170. String getName() const { return config [Ids::name]; }
  171. Value isDebugValue() { return getValue (Ids::isDebug); }
  172. bool isDebug() const { return config [Ids::isDebug]; }
  173. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  174. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  175. // the path relative to the build folder in which the binary should go
  176. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  177. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  178. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  179. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  180. String getGCCOptimisationFlag() const;
  181. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  182. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  183. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  184. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  185. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  186. StringArray getHeaderSearchPaths() const;
  187. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  188. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  189. StringArray getLibrarySearchPaths() const;
  190. String getGCCLibraryPathFlags() const;
  191. Value getUserNotes() { return getValue (Ids::userNotes); }
  192. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  193. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  194. void createPropertyEditors (PropertyListBuilder&);
  195. void addGCCOptimisationProperty (PropertyListBuilder&);
  196. void removeFromExporter();
  197. //==============================================================================
  198. ValueTree config;
  199. Project& project;
  200. const ProjectExporter& exporter;
  201. private:
  202. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  203. };
  204. void addNewConfiguration (const BuildConfiguration* configToCopy);
  205. bool hasConfigurationNamed (const String& name) const;
  206. String getUniqueConfigName (String name) const;
  207. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  208. //==============================================================================
  209. struct ConfigIterator
  210. {
  211. ConfigIterator (ProjectExporter& exporter);
  212. bool next();
  213. BuildConfiguration& operator*() const { return *config; }
  214. BuildConfiguration* operator->() const { return config; }
  215. BuildConfiguration::Ptr config;
  216. int index;
  217. private:
  218. ProjectExporter& exporter;
  219. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  220. };
  221. struct ConstConfigIterator
  222. {
  223. ConstConfigIterator (const ProjectExporter& exporter);
  224. bool next();
  225. const BuildConfiguration& operator*() const { return *config; }
  226. const BuildConfiguration* operator->() const { return config; }
  227. BuildConfiguration::Ptr config;
  228. int index;
  229. private:
  230. const ProjectExporter& exporter;
  231. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  232. };
  233. int getNumConfigurations() const;
  234. BuildConfiguration::Ptr getConfiguration (int index) const;
  235. ValueTree getConfigurations() const;
  236. void createDefaultConfigs();
  237. void createDefaultModulePaths();
  238. //==============================================================================
  239. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  240. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  241. // includes exporter, project + config defs
  242. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  243. // includes exporter + project defs..
  244. StringPairArray getAllPreprocessorDefs() const;
  245. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  246. ValueTree settings;
  247. enum GCCOptimisationLevel
  248. {
  249. gccO0 = 1,
  250. gccO1 = 4,
  251. gccO2 = 5,
  252. gccO3 = 3,
  253. gccOs = 2,
  254. gccOfast = 6
  255. };
  256. protected:
  257. //==============================================================================
  258. String name;
  259. Project& project;
  260. const ProjectType& projectType;
  261. const String projectName;
  262. const File projectFolder;
  263. Value vst2Path, vst3Path, rtasPath, aaxPath; // these must be initialised in the specific exporter c'tors!
  264. mutable Array<Project::Item> itemGroups;
  265. void initItemGroups() const;
  266. Project::Item* modulesGroup;
  267. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  268. void addDefaultPreprocessorDefs (StringPairArray&) const;
  269. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  270. static String getLibbedFilename (String name)
  271. {
  272. if (! name.startsWith ("lib")) name = "lib" + name;
  273. if (! name.endsWithIgnoreCase (".a")) name += ".a";
  274. return name;
  275. }
  276. virtual void addPlatformSpecificSettingsForProjectType (const ProjectType&) = 0;
  277. //==============================================================================
  278. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  279. {
  280. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  281. throw SaveError (file);
  282. }
  283. static void overwriteFileIfDifferentOrThrow (const File& file, const String& newData)
  284. {
  285. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  286. throw SaveError (file);
  287. }
  288. static void createDirectoryOrThrow (const File& dirToCreate)
  289. {
  290. if (! dirToCreate.createDirectory())
  291. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  292. }
  293. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  294. {
  295. MemoryOutputStream mo;
  296. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  297. if (useUnixNewLines)
  298. {
  299. MemoryOutputStream mo2;
  300. mo2 << mo.toString().replace ("\r\n", "\n");
  301. overwriteFileIfDifferentOrThrow (file, mo2);
  302. }
  303. else
  304. {
  305. overwriteFileIfDifferentOrThrow (file, mo);
  306. }
  307. }
  308. static Image rescaleImageForIcon (Drawable&, int iconSize);
  309. private:
  310. //==============================================================================
  311. void createDependencyPathProperties (PropertyListBuilder&);
  312. void createIconProperties (PropertyListBuilder&);
  313. void addVSTPathsIfPluginOrHost();
  314. void addCommonAudioPluginSettings();
  315. void addVSTFolderToPath (bool isVST3);
  316. void addAAXFoldersToPath();
  317. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  318. };
  319. #endif // JUCER_PROJECTEXPORTER_H_INCLUDED