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.

439 lines
18KB

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