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.

482 lines
21KB

  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_ValueTreePropertyWithDefaultWrapper.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. virtual Identifier getExporterIdentifier() const = 0;
  45. //==============================================================================
  46. // capabilities of exporter
  47. virtual bool usesMMFiles() const = 0;
  48. virtual void createExporterProperties (PropertyListBuilder&) = 0;
  49. virtual bool canLaunchProject() = 0;
  50. virtual bool launchProject() = 0;
  51. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  52. virtual bool shouldFileBeCompiledByDefault (const File& path) const;
  53. virtual bool canCopeWithDuplicateFiles() = 0;
  54. virtual bool supportsUserDefinedConfigurations() const = 0; // false if exporter only supports two configs Debug and Release
  55. virtual void updateDeprecatedSettings() {}
  56. virtual void updateDeprecatedSettingsInteractively() {}
  57. virtual void initialiseDependencyPathValues() {}
  58. // IDE targeted by exporter
  59. virtual bool isXcode() const = 0;
  60. virtual bool isVisualStudio() const = 0;
  61. virtual bool isCodeBlocks() const = 0;
  62. virtual bool isMakefile() const = 0;
  63. virtual bool isAndroidStudio() const = 0;
  64. virtual bool isCLion() const = 0;
  65. // operating system targeted by exporter
  66. virtual bool isAndroid() const = 0;
  67. virtual bool isWindows() const = 0;
  68. virtual bool isLinux() const = 0;
  69. virtual bool isOSX() const = 0;
  70. virtual bool isiOS() const = 0;
  71. virtual File getIDEProjectFile() const { return {}; }
  72. virtual String getNewLineString() const = 0;
  73. virtual String getDescription() { return {}; }
  74. virtual bool supportsPrecompiledHeaders() const { return false; }
  75. //==============================================================================
  76. // cross-platform audio plug-ins supported by exporter
  77. virtual bool supportsTargetType (build_tools::ProjectType::Target::Type type) const = 0;
  78. inline bool shouldBuildTargetType (build_tools::ProjectType::Target::Type type) const
  79. {
  80. return project.shouldBuildTargetType (type) && supportsTargetType (type);
  81. }
  82. inline void callForAllSupportedTargets (std::function<void (build_tools::ProjectType::Target::Type)> callback)
  83. {
  84. for (int i = 0; i < build_tools::ProjectType::Target::unspecified; ++i)
  85. if (shouldBuildTargetType (static_cast<build_tools::ProjectType::Target::Type> (i)))
  86. callback (static_cast<build_tools::ProjectType::Target::Type> (i));
  87. }
  88. //==============================================================================
  89. bool mayCompileOnCurrentOS() const
  90. {
  91. #if JUCE_MAC
  92. return isOSX() || isAndroid() || isiOS();
  93. #elif JUCE_WINDOWS
  94. return isWindows() || isAndroid();
  95. #elif JUCE_LINUX
  96. return isLinux() || isAndroid();
  97. #elif JUCE_BSD
  98. return isLinux();
  99. #else
  100. #error
  101. #endif
  102. }
  103. //==============================================================================
  104. String getUniqueName() const;
  105. File getTargetFolder() const;
  106. Project& getProject() noexcept { return project; }
  107. const Project& getProject() const noexcept { return project; }
  108. UndoManager* getUndoManager() const { return project.getUndoManagerFor (settings); }
  109. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  110. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  111. Value getTargetLocationValue() { return targetLocationValue.getPropertyAsValue(); }
  112. String getTargetLocationString() const { return targetLocationValue.get(); }
  113. String getExtraCompilerFlagsString() const { return extraCompilerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  114. String getExtraLinkerFlagsString() const { return extraLinkerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  115. StringArray getExternalLibrariesStringArray() const { return getSearchPathsFromString (externalLibrariesValue.get().toString()); }
  116. String getExternalLibrariesString() const { return getExternalLibrariesStringArray().joinIntoString (";"); }
  117. bool shouldUseGNUExtensions() const { return gnuExtensionsValue.get(); }
  118. String getVSTLegacyPathString() const { return vstLegacyPathValueWrapper.getCurrentValue(); }
  119. String getAAXPathString() const { return aaxPathValueWrapper.getCurrentValue(); }
  120. String getRTASPathString() const { return rtasPathValueWrapper.getCurrentValue(); }
  121. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  122. // module folder itself.
  123. ValueTreePropertyWithDefault getPathForModuleValue (const String& moduleID);
  124. String getPathForModuleString (const String& moduleID) const;
  125. void removePathForModule (const String& moduleID);
  126. TargetOS::OS getTargetOSForExporter() const;
  127. build_tools::RelativePath getLegacyModulePath (const String& moduleID) const;
  128. String getLegacyModulePath() const;
  129. // Returns a path to the actual module folder itself
  130. build_tools::RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  131. void updateOldModulePaths();
  132. build_tools::RelativePath rebaseFromProjectFolderToBuildTarget (const build_tools::RelativePath& path) const;
  133. void addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index = -1);
  134. void addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder);
  135. void addProjectPathToBuildPathList (StringArray&, const build_tools::RelativePath&, int index = -1) const;
  136. std::unique_ptr<Drawable> getBigIcon() const;
  137. std::unique_ptr<Drawable> getSmallIcon() const;
  138. build_tools::Icons getIcons() const { return { getSmallIcon(), getBigIcon() }; }
  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. void createPropertyEditors (PropertyListBuilder&);
  146. void addSettingsForProjectType (const build_tools::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. enum class PackageDependencyType
  155. {
  156. compile,
  157. link
  158. };
  159. StringArray getLinuxPackages (PackageDependencyType type) const;
  160. //==============================================================================
  161. StringPairArray msvcExtraPreprocessorDefs;
  162. String msvcDelayLoadedDLLs;
  163. StringArray mingwLibs, windowsLibs;
  164. //==============================================================================
  165. StringArray androidLibs;
  166. //==============================================================================
  167. StringArray extraSearchPaths;
  168. StringArray moduleLibSearchPaths;
  169. //==============================================================================
  170. class BuildConfiguration : public ReferenceCountedObject
  171. {
  172. public:
  173. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  174. ~BuildConfiguration();
  175. using Ptr = ReferenceCountedObjectPtr<BuildConfiguration>;
  176. //==============================================================================
  177. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  178. virtual String getModuleLibraryArchName() const = 0;
  179. //==============================================================================
  180. String getName() const { return configNameValue.get(); }
  181. bool isDebug() const { return isDebugValue.get(); }
  182. String getTargetBinaryRelativePathString() const { return targetBinaryPathValue.get(); }
  183. String getTargetBinaryNameString (bool isUnityPlugin = false) const
  184. {
  185. return (isUnityPlugin ? Project::addUnityPluginPrefixIfNecessary (targetNameValue.get().toString())
  186. : targetNameValue.get().toString());
  187. }
  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 getPrecompiledHeaderFilename() const { return "JucePrecompiledHeader_" + getName(); }
  199. static String getSkipPrecompiledHeaderDefine() { return "JUCE_SKIP_PRECOMPILED_HEADER"; }
  200. bool shouldUsePrecompiledHeaderFile() const { return usePrecompiledHeaderFileValue.get(); }
  201. String getPrecompiledHeaderFileContent() const;
  202. //==============================================================================
  203. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  204. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  205. //==============================================================================
  206. void createPropertyEditors (PropertyListBuilder&);
  207. void addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder&);
  208. void addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder&);
  209. struct CompilerNames
  210. {
  211. static constexpr const char* gcc = "GCC";
  212. static constexpr const char* llvm = "LLVM";
  213. };
  214. struct CompilerWarningFlags
  215. {
  216. static CompilerWarningFlags getRecommendedForGCCAndLLVM()
  217. {
  218. CompilerWarningFlags result;
  219. result.common = { "-Wall", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter",
  220. "-Wswitch-enum", "-Wsign-conversion", "-Wsign-compare",
  221. "-Wunreachable-code", "-Wcast-align", "-Wno-ignored-qualifiers" };
  222. result.cpp = { "-Woverloaded-virtual", "-Wreorder", "-Wzero-as-null-pointer-constant" };
  223. return result;
  224. }
  225. StringArray common;
  226. StringArray cpp;
  227. };
  228. CompilerWarningFlags getRecommendedCompilerWarningFlags() const;
  229. void addGCCOptimisationProperty (PropertyListBuilder&);
  230. void removeFromExporter();
  231. //==============================================================================
  232. ValueTree config;
  233. Project& project;
  234. const ProjectExporter& exporter;
  235. protected:
  236. ValueTreePropertyWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, recommendedWarningsValue, optimisationLevelValue,
  237. linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue,
  238. usePrecompiledHeaderFileValue, precompiledHeaderFileValue;
  239. private:
  240. std::map<String, CompilerWarningFlags> recommendedCompilerWarningFlags;
  241. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  242. };
  243. void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy);
  244. void addNewConfiguration (bool isDebugConfig);
  245. bool hasConfigurationNamed (const String& name) const;
  246. String getUniqueConfigName (String name) const;
  247. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  248. //==============================================================================
  249. struct ConfigIterator
  250. {
  251. ConfigIterator (ProjectExporter& exporter);
  252. bool next();
  253. BuildConfiguration& operator*() const { return *config; }
  254. BuildConfiguration* operator->() const { return config.get(); }
  255. BuildConfiguration::Ptr config;
  256. int index;
  257. private:
  258. ProjectExporter& exporter;
  259. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  260. };
  261. struct ConstConfigIterator
  262. {
  263. ConstConfigIterator (const ProjectExporter& exporter);
  264. bool next();
  265. const BuildConfiguration& operator*() const { return *config; }
  266. const BuildConfiguration* operator->() const { return config.get(); }
  267. BuildConfiguration::Ptr config;
  268. int index;
  269. private:
  270. const ProjectExporter& exporter;
  271. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  272. };
  273. int getNumConfigurations() const;
  274. BuildConfiguration::Ptr getConfiguration (int index) const;
  275. ValueTree getConfigurations() const;
  276. virtual void createDefaultConfigs();
  277. void createDefaultModulePaths();
  278. //==============================================================================
  279. Value getExporterPreprocessorDefsValue() { return extraPPDefsValue.getPropertyAsValue(); }
  280. String getExporterPreprocessorDefsString() const { return extraPPDefsValue.get(); }
  281. // includes exporter, project + config defs
  282. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const;
  283. // includes exporter + project defs
  284. StringPairArray getAllPreprocessorDefs() const;
  285. void addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const;
  286. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  287. ValueTree settings;
  288. enum GCCOptimisationLevel
  289. {
  290. gccO0 = 1,
  291. gccO1 = 4,
  292. gccO2 = 5,
  293. gccO3 = 3,
  294. gccOs = 2,
  295. gccOfast = 6
  296. };
  297. bool isPCHEnabledForAnyConfigurations() const
  298. {
  299. if (supportsPrecompiledHeaders())
  300. for (ConstConfigIterator config (*this); config.next();)
  301. if (config->shouldUsePrecompiledHeaderFile())
  302. return true;
  303. return false;
  304. }
  305. protected:
  306. //==============================================================================
  307. String name;
  308. Project& project;
  309. const build_tools::ProjectType& projectType;
  310. const String projectName;
  311. const File projectFolder;
  312. //==============================================================================
  313. ValueTreePropertyWithDefaultWrapper vstLegacyPathValueWrapper, rtasPathValueWrapper, aaxPathValueWrapper;
  314. ValueTreePropertyWithDefault targetLocationValue, extraCompilerFlagsValue, extraLinkerFlagsValue, externalLibrariesValue,
  315. userNotesValue, gnuExtensionsValue, bigIconValue, smallIconValue, extraPPDefsValue;
  316. Value projectCompilerFlagSchemesValue;
  317. HashMap<String, ValueTreePropertyWithDefault> compilerFlagSchemesMap;
  318. mutable Array<Project::Item> itemGroups;
  319. Project::Item* modulesGroup = nullptr;
  320. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  321. void addDefaultPreprocessorDefs (StringPairArray&) const;
  322. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  323. static String getStaticLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".a"); }
  324. static String getDynamicLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".so"); }
  325. virtual void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) = 0;
  326. //==============================================================================
  327. static void createDirectoryOrThrow (const File& dirToCreate)
  328. {
  329. if (! dirToCreate.createDirectory())
  330. throw build_tools::SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  331. }
  332. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding,
  333. int maxCharsPerLine, bool useUnixNewLines = false)
  334. {
  335. XmlElement::TextFormat format;
  336. format.customEncoding = encoding;
  337. format.lineWrapLength = maxCharsPerLine;
  338. format.newLineChars = useUnixNewLines ? "\n" : "\r\n";
  339. MemoryOutputStream mo (8192);
  340. xml.writeTo (mo, format);
  341. build_tools::overwriteFileIfDifferentOrThrow (file, mo);
  342. }
  343. private:
  344. //==============================================================================
  345. void valueChanged (Value&) override { updateCompilerFlagValues(); }
  346. void updateCompilerFlagValues();
  347. //==============================================================================
  348. static String addLibPrefix (const String name)
  349. {
  350. return name.startsWith ("lib") ? name
  351. : "lib" + name;
  352. }
  353. static String addSuffix (const String name, const String suffix)
  354. {
  355. return name.endsWithIgnoreCase (suffix) ? name
  356. : name + suffix;
  357. }
  358. void createDependencyPathProperties (PropertyListBuilder&);
  359. void createIconProperties (PropertyListBuilder&);
  360. void addVSTPathsIfPluginOrHost();
  361. void addCommonAudioPluginSettings();
  362. void addLegacyVSTFolderToPathIfSpecified();
  363. build_tools::RelativePath getInternalVST3SDKPath();
  364. void addAAXFoldersToPath();
  365. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  366. };