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.

450 lines
20KB

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