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. // 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. //==============================================================================
  67. // cross-platform audio plug-ins supported by exporter
  68. virtual bool supportsTargetType (ProjectType::Target::Type type) const = 0;
  69. inline bool shouldBuildTargetType (ProjectType::Target::Type type) const
  70. {
  71. return project.shouldBuildTargetType (type) && supportsTargetType (type);
  72. }
  73. inline void callForAllSupportedTargets (std::function<void (ProjectType::Target::Type)> callback)
  74. {
  75. for (int i = 0; i < ProjectType::Target::unspecified; ++i)
  76. if (shouldBuildTargetType (static_cast<ProjectType::Target::Type> (i)))
  77. callback (static_cast<ProjectType::Target::Type> (i));
  78. }
  79. //==============================================================================
  80. bool mayCompileOnCurrentOS() const
  81. {
  82. #if JUCE_MAC
  83. return isOSX() || isAndroid();
  84. #elif JUCE_WINDOWS
  85. return isWindows() || isAndroid();
  86. #elif JUCE_LINUX
  87. return isLinux() || isAndroid();
  88. #else
  89. #error
  90. #endif
  91. }
  92. //==============================================================================
  93. String getName() const { return name; }
  94. File getTargetFolder() const;
  95. Project& getProject() noexcept { return project; }
  96. const Project& getProject() const noexcept { return project; }
  97. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  98. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  99. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  100. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  101. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  102. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags).replaceCharacters ("\r\n", " "); }
  103. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  104. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", " "); }
  105. Value getExternalLibraries() { return getSetting (Ids::externalLibraries); }
  106. String getExternalLibrariesString() const { return getSearchPathsFromString (getSettingString (Ids::externalLibraries)).joinIntoString (";"); }
  107. Value getUserNotes() { return getSetting (Ids::userNotes); }
  108. Value getVST3PathValue() const { return vst3Path; }
  109. Value getRTASPathValue() const { return rtasPath; }
  110. Value getAAXPathValue() const { return aaxPath; }
  111. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  112. // module folder itself.
  113. Value getPathForModuleValue (const String& moduleID);
  114. String getPathForModuleString (const String& moduleID) const;
  115. void removePathForModule (const String& moduleID);
  116. RelativePath getLegacyModulePath (const String& moduleID) const;
  117. String getLegacyModulePath() const;
  118. // Returns a path to the actual module folder itself
  119. RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  120. void updateOldModulePaths();
  121. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  122. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder, int index = -1);
  123. void addToModuleLibPaths (const RelativePath& pathFromProjectFolder);
  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 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