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.

427 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. #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. //==============================================================================
  68. // cross-platform audio plug-ins supported by exporter
  69. virtual bool supportsTargetType (ProjectType::Target::Type type) const = 0;
  70. inline bool shouldBuildTargetType (ProjectType::Target::Type type) const
  71. {
  72. return project.shouldBuildTargetType (type) && supportsTargetType (type);
  73. }
  74. inline void callForAllSupportedTargets (std::function<void (ProjectType::Target::Type)> callback)
  75. {
  76. for (int i = 0; i < ProjectType::Target::unspecified; ++i)
  77. if (shouldBuildTargetType (static_cast<ProjectType::Target::Type> (i)))
  78. callback (static_cast<ProjectType::Target::Type> (i));
  79. }
  80. //==============================================================================
  81. bool mayCompileOnCurrentOS() const
  82. {
  83. #if JUCE_MAC
  84. return isOSX() || isAndroid();
  85. #elif JUCE_WINDOWS
  86. return isWindows() || isAndroid();
  87. #elif JUCE_LINUX
  88. return isLinux() || isAndroid();
  89. #else
  90. #error
  91. #endif
  92. }
  93. //==============================================================================
  94. String getName() const { return name; }
  95. File getTargetFolder() const;
  96. Project& getProject() noexcept { return project; }
  97. const Project& getProject() const noexcept { return project; }
  98. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  99. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  100. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  101. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  102. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  103. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags).replaceCharacters ("\r\n", " "); }
  104. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  105. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", " "); }
  106. Value getExternalLibraries() { return getSetting (Ids::externalLibraries); }
  107. String getExternalLibrariesString() const { return getSearchPathsFromString (getSettingString (Ids::externalLibraries)).joinIntoString (";"); }
  108. Value getUserNotes() { return getSetting (Ids::userNotes); }
  109. Value getVST3PathValue() const { return vst3Path; }
  110. Value getRTASPathValue() const { return rtasPath; }
  111. Value getAAXPathValue() const { return aaxPath; }
  112. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  113. // module folder itself.
  114. Value getPathForModuleValue (const String& moduleID);
  115. String getPathForModuleString (const String& moduleID) const;
  116. void removePathForModule (const String& moduleID);
  117. RelativePath getLegacyModulePath (const String& moduleID) const;
  118. String getLegacyModulePath() const;
  119. // Returns a path to the actual module folder itself
  120. RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  121. void updateOldModulePaths();
  122. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  123. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder, int index = -1);
  124. void addToModuleLibPaths (const RelativePath& pathFromProjectFolder);
  125. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  126. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  127. Drawable* getBigIcon() const;
  128. Drawable* getSmallIcon() const;
  129. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  130. String getExporterIdentifierMacro() const
  131. {
  132. return "JUCER_" + settings.getType().toString() + "_"
  133. + String::toHexString (getSettingString (Ids::targetFolder).hashCode()).toUpperCase();
  134. }
  135. // An exception that can be thrown by the create() method.
  136. class SaveError
  137. {
  138. public:
  139. SaveError (const String& error) : message (error)
  140. {}
  141. SaveError (const File& fileThatFailedToWrite)
  142. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  143. {}
  144. String message;
  145. };
  146. void createPropertyEditors (PropertyListBuilder&);
  147. void addSettingsForProjectType (const ProjectType&);
  148. //==============================================================================
  149. void copyMainGroupFromProject();
  150. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  151. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  152. Project::Item& getModulesGroup();
  153. //==============================================================================
  154. StringArray linuxLibs, linuxPackages, makefileExtraLinkerFlags;
  155. //==============================================================================
  156. StringPairArray msvcExtraPreprocessorDefs;
  157. String msvcDelayLoadedDLLs;
  158. StringArray mingwLibs, windowsLibs;
  159. //==============================================================================
  160. StringArray extraSearchPaths;
  161. StringArray moduleLibSearchPaths;
  162. //==============================================================================
  163. class BuildConfiguration : public ReferenceCountedObject
  164. {
  165. public:
  166. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  167. ~BuildConfiguration();
  168. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  169. //==============================================================================
  170. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  171. virtual var getDefaultOptimisationLevel() const = 0;
  172. virtual String getLibrarySubdirPath() const { return String(); }
  173. //==============================================================================
  174. Value getNameValue() { return getValue (Ids::name); }
  175. String getName() const { return config [Ids::name]; }
  176. Value isDebugValue() { return getValue (Ids::isDebug); }
  177. bool isDebug() const { return config [Ids::isDebug]; }
  178. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  179. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  180. // the path relative to the build folder in which the binary should go
  181. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  182. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  183. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  184. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  185. String getGCCOptimisationFlag() const;
  186. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  187. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  188. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  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 getLibbedFilename (String name)
  277. {
  278. if (! name.startsWith ("lib")) name = "lib" + name;
  279. if (! name.endsWithIgnoreCase (".a")) name += ".a";
  280. return name;
  281. }
  282. virtual void addPlatformSpecificSettingsForProjectType (const ProjectType&) = 0;
  283. //==============================================================================
  284. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  285. {
  286. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  287. throw SaveError (file);
  288. }
  289. static void overwriteFileIfDifferentOrThrow (const File& file, const String& newData)
  290. {
  291. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  292. throw SaveError (file);
  293. }
  294. static void createDirectoryOrThrow (const File& dirToCreate)
  295. {
  296. if (! dirToCreate.createDirectory())
  297. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  298. }
  299. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  300. {
  301. MemoryOutputStream mo;
  302. xml.writeToStream (mo, String(), false, true, encoding, maxCharsPerLine);
  303. if (useUnixNewLines)
  304. {
  305. MemoryOutputStream mo2;
  306. mo2 << mo.toString().replace ("\r\n", "\n");
  307. overwriteFileIfDifferentOrThrow (file, mo2);
  308. }
  309. else
  310. {
  311. overwriteFileIfDifferentOrThrow (file, mo);
  312. }
  313. }
  314. static Image rescaleImageForIcon (Drawable&, int iconSize);
  315. private:
  316. //==============================================================================
  317. void createDependencyPathProperties (PropertyListBuilder&);
  318. void createIconProperties (PropertyListBuilder&);
  319. void addVSTPathsIfPluginOrHost();
  320. void addCommonAudioPluginSettings();
  321. void addVST3FolderToPath();
  322. void addAAXFoldersToPath();
  323. void addProjectPathToBuildPathList (StringArray&, const RelativePath&, int index = -1);
  324. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  325. };
  326. #endif // JUCER_PROJECTEXPORTER_H_INCLUDED