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.

452 lines
18KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "../Project/jucer_Project.h"
  21. #include "../Utility/UI/PropertyComponents/jucer_DependencyPathPropertyComponent.h"
  22. #include "../Utility/UI/PropertyComponents/jucer_PropertyComponentsWithEnablement.h"
  23. class ProjectSaver;
  24. //==============================================================================
  25. class ProjectExporter
  26. {
  27. public:
  28. ProjectExporter (Project&, const ValueTree& settings);
  29. virtual ~ProjectExporter();
  30. struct ExporterTypeInfo
  31. {
  32. String name;
  33. const void* iconData;
  34. int iconDataSize;
  35. Image getIcon() const
  36. {
  37. Image image (Image::ARGB, 200, 200, true);
  38. Graphics g (image);
  39. ScopedPointer<Drawable> svgDrawable = Drawable::createFromImageData (iconData, (size_t) iconDataSize);
  40. svgDrawable->drawWithin (g, image.getBounds().toFloat(), RectanglePlacement::fillDestination, 1.0f);
  41. return image;
  42. }
  43. };
  44. static StringArray getExporterNames();
  45. static Array<ExporterTypeInfo> getExporterTypes();
  46. static String getValueTreeNameForExporter (const String& exporterName);
  47. static StringArray getAllDefaultBuildsFolders();
  48. static ProjectExporter* createNewExporter (Project&, const int index);
  49. static ProjectExporter* createNewExporter (Project&, const String& name);
  50. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  51. static bool canProjectBeLaunched (Project*);
  52. static String getCurrentPlatformExporterName();
  53. //==============================================================================
  54. // capabilities of exporter
  55. virtual bool usesMMFiles() const = 0;
  56. virtual void createExporterProperties (PropertyListBuilder&) = 0;
  57. virtual bool canLaunchProject() = 0;
  58. virtual bool launchProject() = 0;
  59. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  60. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  61. virtual bool canCopeWithDuplicateFiles() = 0;
  62. virtual bool supportsUserDefinedConfigurations() const = 0; // false if exporter only supports two configs Debug and Release
  63. virtual void updateDeprecatedProjectSettingsInteractively();
  64. virtual void initialiseDependencyPathValues() {}
  65. // IDE targeted by exporter
  66. virtual bool isXcode() const = 0;
  67. virtual bool isVisualStudio() const = 0;
  68. virtual bool isCodeBlocks() const = 0;
  69. virtual bool isMakefile() const = 0;
  70. virtual bool isAndroidStudio() const = 0;
  71. virtual bool isCLion() const = 0;
  72. // operating system targeted by exporter
  73. virtual bool isAndroid() const = 0;
  74. virtual bool isWindows() const = 0;
  75. virtual bool isLinux() const = 0;
  76. virtual bool isOSX() const = 0;
  77. virtual bool isiOS() const = 0;
  78. virtual String getDescription() { return {}; }
  79. //==============================================================================
  80. // cross-platform audio plug-ins supported by exporter
  81. virtual bool supportsTargetType (ProjectType::Target::Type type) const = 0;
  82. inline bool shouldBuildTargetType (ProjectType::Target::Type type) const
  83. {
  84. return project.shouldBuildTargetType (type) && supportsTargetType (type);
  85. }
  86. inline void callForAllSupportedTargets (std::function<void (ProjectType::Target::Type)> callback)
  87. {
  88. for (int i = 0; i < ProjectType::Target::unspecified; ++i)
  89. if (shouldBuildTargetType (static_cast<ProjectType::Target::Type> (i)))
  90. callback (static_cast<ProjectType::Target::Type> (i));
  91. }
  92. //==============================================================================
  93. bool mayCompileOnCurrentOS() const
  94. {
  95. #if JUCE_MAC
  96. return isOSX() || isAndroid() || isiOS();
  97. #elif JUCE_WINDOWS
  98. return isWindows() || isAndroid();
  99. #elif JUCE_LINUX
  100. return isLinux() || isAndroid();
  101. #else
  102. #error
  103. #endif
  104. }
  105. //==============================================================================
  106. String getName() const;
  107. File getTargetFolder() const;
  108. Project& getProject() noexcept { return project; }
  109. const Project& getProject() const noexcept { return project; }
  110. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  111. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  112. Value getTargetLocationValue() { return targetLocationValue.getPropertyAsValue(); }
  113. String getTargetLocationString() const { return targetLocationValue.get(); }
  114. String getExtraCompilerFlagsString() const { return extraCompilerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  115. String getExtraLinkerFlagsString() const { return extraLinkerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  116. String getExternalLibrariesString() const { return getSearchPathsFromString (externalLibrariesValue.get().toString()).joinIntoString (";"); }
  117. bool shouldUseGNUExtensions() const { return gnuExtensionsValue.get();}
  118. Value getVST3PathValue() const { return vst3Path; }
  119. Value getRTASPathValue() const { return rtasPath; }
  120. Value getAAXPathValue() const { return aaxPath; }
  121. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  122. // module folder itself.
  123. Value getPathForModuleValue (const String& moduleID);
  124. String getPathForModuleString (const String& moduleID) const;
  125. void removePathForModule (const String& moduleID);
  126. TargetOS::OS getTargetOSForExporter() const;
  127. RelativePath getLegacyModulePath (const String& moduleID) const;
  128. String getLegacyModulePath() const;
  129. // Returns a path to the actual module folder itself
  130. RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  131. void updateOldModulePaths();
  132. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  133. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder, int index = -1);
  134. void addToModuleLibPaths (const RelativePath& pathFromProjectFolder);
  135. void addProjectPathToBuildPathList (StringArray&, const RelativePath&, int index = -1) const;
  136. Drawable* getBigIcon() const;
  137. Drawable* getSmallIcon() const;
  138. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  139. String getExporterIdentifierMacro() const
  140. {
  141. return "JUCER_" + settings.getType().toString() + "_"
  142. + String::toHexString (getTargetLocationString().hashCode()).toUpperCase();
  143. }
  144. // An exception that can be thrown by the create() method.
  145. class SaveError
  146. {
  147. public:
  148. SaveError (const String& error) : message (error)
  149. {}
  150. SaveError (const File& fileThatFailedToWrite)
  151. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  152. {}
  153. String message;
  154. };
  155. void createPropertyEditors (PropertyListBuilder&);
  156. void addSettingsForProjectType (const ProjectType&);
  157. //==============================================================================
  158. void copyMainGroupFromProject();
  159. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  160. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  161. Project::Item& getModulesGroup();
  162. //==============================================================================
  163. StringArray linuxLibs, linuxPackages, makefileExtraLinkerFlags;
  164. //==============================================================================
  165. StringPairArray msvcExtraPreprocessorDefs;
  166. String msvcDelayLoadedDLLs;
  167. StringArray mingwLibs, windowsLibs;
  168. //==============================================================================
  169. StringArray androidLibs;
  170. //==============================================================================
  171. StringArray extraSearchPaths;
  172. StringArray moduleLibSearchPaths;
  173. //==============================================================================
  174. class BuildConfiguration : public ReferenceCountedObject
  175. {
  176. public:
  177. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  178. ~BuildConfiguration();
  179. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  180. //==============================================================================
  181. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  182. virtual String getModuleLibraryArchName() const = 0;
  183. //==============================================================================
  184. String getName() const { return configNameValue.get(); }
  185. bool isDebug() const { return isDebugValue.get(); }
  186. String getTargetBinaryNameString() const { return targetNameValue.get(); }
  187. String getTargetBinaryRelativePathString() const { return targetBinaryPathValue.get(); }
  188. int getOptimisationLevelInt() const { return optimisationLevelValue.get(); }
  189. String getGCCOptimisationFlag() const;
  190. bool isLinkTimeOptimisationEnabled() const { return linkTimeOptimisationValue.get(); }
  191. String getBuildConfigPreprocessorDefsString() const { return ppDefinesValue.get(); }
  192. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  193. StringPairArray getUniquePreprocessorDefs() const; // returns pre-processor definitions that are not already in the project pre-processor defs
  194. String getHeaderSearchPathString() const { return headerSearchPathValue.get(); }
  195. StringArray getHeaderSearchPaths() const;
  196. String getLibrarySearchPathString() const { return librarySearchPathValue.get(); }
  197. StringArray getLibrarySearchPaths() const;
  198. String getGCCLibraryPathFlags() const;
  199. //==============================================================================
  200. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  201. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  202. //==============================================================================
  203. void createPropertyEditors (PropertyListBuilder&);
  204. void addGCCOptimisationProperty (PropertyListBuilder&);
  205. void removeFromExporter();
  206. //==============================================================================
  207. ValueTree config;
  208. Project& project;
  209. const ProjectExporter& exporter;
  210. protected:
  211. ValueWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, optimisationLevelValue,
  212. linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue;
  213. private:
  214. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  215. };
  216. void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy);
  217. void addNewConfiguration (bool isDebugConfig);
  218. bool hasConfigurationNamed (const String& name) const;
  219. String getUniqueConfigName (String name) const;
  220. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  221. //==============================================================================
  222. struct ConfigIterator
  223. {
  224. ConfigIterator (ProjectExporter& exporter);
  225. bool next();
  226. BuildConfiguration& operator*() const { return *config; }
  227. BuildConfiguration* operator->() const { return config; }
  228. BuildConfiguration::Ptr config;
  229. int index;
  230. private:
  231. ProjectExporter& exporter;
  232. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  233. };
  234. struct ConstConfigIterator
  235. {
  236. ConstConfigIterator (const ProjectExporter& exporter);
  237. bool next();
  238. const BuildConfiguration& operator*() const { return *config; }
  239. const BuildConfiguration* operator->() const { return config; }
  240. BuildConfiguration::Ptr config;
  241. int index;
  242. private:
  243. const ProjectExporter& exporter;
  244. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  245. };
  246. int getNumConfigurations() const;
  247. BuildConfiguration::Ptr getConfiguration (int index) const;
  248. ValueTree getConfigurations() const;
  249. virtual void createDefaultConfigs();
  250. void createDefaultModulePaths();
  251. //==============================================================================
  252. Value getExporterPreprocessorDefsValue() { return extraPPDefsValue.getPropertyAsValue(); }
  253. String getExporterPreprocessorDefsString() const { return extraPPDefsValue.get(); }
  254. // includes exporter, project + config defs
  255. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config, const ProjectType::Target::Type targetType) const;
  256. // includes exporter + project defs..
  257. StringPairArray getAllPreprocessorDefs() const;
  258. void addTargetSpecificPreprocessorDefs (StringPairArray& defs, const ProjectType::Target::Type targetType) const;
  259. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  260. ValueTree settings;
  261. enum GCCOptimisationLevel
  262. {
  263. gccO0 = 1,
  264. gccO1 = 4,
  265. gccO2 = 5,
  266. gccO3 = 3,
  267. gccOs = 2,
  268. gccOfast = 6
  269. };
  270. protected:
  271. //==============================================================================
  272. String name;
  273. Project& project;
  274. const ProjectType& projectType;
  275. const String projectName;
  276. const File projectFolder;
  277. Value vst3Path, rtasPath, aaxPath; // these must be initialised in the specific exporter c'tors!
  278. ValueWithDefault targetLocationValue, extraCompilerFlagsValue, extraLinkerFlagsValue, externalLibrariesValue,
  279. userNotesValue, gnuExtensionsValue, bigIconValue, smallIconValue, extraPPDefsValue;
  280. mutable Array<Project::Item> itemGroups;
  281. void initItemGroups() const;
  282. Project::Item* modulesGroup = nullptr;
  283. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  284. void addDefaultPreprocessorDefs (StringPairArray&) const;
  285. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  286. static String getStaticLibbedFilename (String name)
  287. {
  288. return addSuffix (addLibPrefix (name), ".a");
  289. }
  290. static String getDynamicLibbedFilename (String name)
  291. {
  292. return addSuffix (addLibPrefix (name), ".so");
  293. }
  294. virtual void addPlatformSpecificSettingsForProjectType (const ProjectType&) = 0;
  295. //==============================================================================
  296. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  297. {
  298. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  299. throw SaveError (file);
  300. }
  301. static void overwriteFileIfDifferentOrThrow (const File& file, const String& newData)
  302. {
  303. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  304. throw SaveError (file);
  305. }
  306. static void createDirectoryOrThrow (const File& dirToCreate)
  307. {
  308. if (! dirToCreate.createDirectory())
  309. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  310. }
  311. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  312. {
  313. MemoryOutputStream mo;
  314. xml.writeToStream (mo, String(), false, true, encoding, maxCharsPerLine);
  315. if (useUnixNewLines)
  316. {
  317. MemoryOutputStream mo2;
  318. mo2 << mo.toString().replace ("\r\n", "\n");
  319. overwriteFileIfDifferentOrThrow (file, mo2);
  320. }
  321. else
  322. {
  323. overwriteFileIfDifferentOrThrow (file, mo);
  324. }
  325. }
  326. static Image rescaleImageForIcon (Drawable&, int iconSize);
  327. private:
  328. //==============================================================================
  329. static String addLibPrefix (const String name)
  330. {
  331. return name.startsWith ("lib") ? name
  332. : "lib" + name;
  333. }
  334. static String addSuffix (const String name, const String suffix)
  335. {
  336. return name.endsWithIgnoreCase (suffix) ? name
  337. : name + suffix;
  338. }
  339. void createDependencyPathProperties (PropertyListBuilder&);
  340. void createIconProperties (PropertyListBuilder&);
  341. void addVSTPathsIfPluginOrHost();
  342. void addCommonAudioPluginSettings();
  343. void addVST3FolderToPath();
  344. void addAAXFoldersToPath();
  345. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  346. };