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.

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