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.

487 lines
21KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. //==============================================================================
  30. struct ExporterTypeInfo
  31. {
  32. Identifier identifier;
  33. String displayName;
  34. String targetFolder;
  35. Image icon;
  36. };
  37. static std::vector<ExporterTypeInfo> getExporterTypeInfos();
  38. static ExporterTypeInfo getTypeInfoForExporter (const Identifier& exporterIdentifier);
  39. static ExporterTypeInfo getCurrentPlatformExporterTypeInfo();
  40. static std::unique_ptr<ProjectExporter> createNewExporter (Project&, const Identifier& exporterIdentifier);
  41. static std::unique_ptr<ProjectExporter> createExporterFromSettings (Project&, const ValueTree& settings);
  42. static bool canProjectBeLaunched (Project*);
  43. virtual Identifier getExporterIdentifier() const = 0;
  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. // operating system targeted by exporter
  64. virtual bool isAndroid() const = 0;
  65. virtual bool isWindows() const = 0;
  66. virtual bool isLinux() const = 0;
  67. virtual bool isOSX() const = 0;
  68. virtual bool isiOS() const = 0;
  69. virtual String getNewLineString() const = 0;
  70. virtual String getDescription() { return {}; }
  71. virtual bool supportsPrecompiledHeaders() const { return false; }
  72. //==============================================================================
  73. // cross-platform audio plug-ins supported by exporter
  74. virtual bool supportsTargetType (build_tools::ProjectType::Target::Type type) const = 0;
  75. inline bool shouldBuildTargetType (build_tools::ProjectType::Target::Type type) const
  76. {
  77. return project.shouldBuildTargetType (type) && supportsTargetType (type);
  78. }
  79. inline void callForAllSupportedTargets (std::function<void (build_tools::ProjectType::Target::Type)> callback)
  80. {
  81. for (int i = 0; i < build_tools::ProjectType::Target::unspecified; ++i)
  82. if (shouldBuildTargetType (static_cast<build_tools::ProjectType::Target::Type> (i)))
  83. callback (static_cast<build_tools::ProjectType::Target::Type> (i));
  84. }
  85. //==============================================================================
  86. bool mayCompileOnCurrentOS() const
  87. {
  88. #if JUCE_MAC
  89. return isOSX() || isAndroid() || isiOS();
  90. #elif JUCE_WINDOWS
  91. return isWindows() || isAndroid();
  92. #elif JUCE_LINUX
  93. return isLinux() || isAndroid();
  94. #elif JUCE_BSD
  95. return isLinux();
  96. #else
  97. #error
  98. #endif
  99. }
  100. //==============================================================================
  101. String getUniqueName() const;
  102. File getTargetFolder() const;
  103. Project& getProject() noexcept { return project; }
  104. const Project& getProject() const noexcept { return project; }
  105. UndoManager* getUndoManager() const { return project.getUndoManagerFor (settings); }
  106. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  107. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  108. Value getTargetLocationValue() { return targetLocationValue.getPropertyAsValue(); }
  109. String getTargetLocationString() const { return targetLocationValue.get(); }
  110. StringArray getExternalLibrariesStringArray() const { return getSearchPathsFromString (externalLibrariesValue.get().toString()); }
  111. String getExternalLibrariesString() const { return getExternalLibrariesStringArray().joinIntoString (";"); }
  112. bool shouldUseGNUExtensions() const { return gnuExtensionsValue.get(); }
  113. String getVSTLegacyPathString() const { return vstLegacyPathValueWrapper.getCurrentValue(); }
  114. String getAAXPathString() const { return aaxPathValueWrapper.getCurrentValue(); }
  115. String getARAPathString() const { return araPathValueWrapper.getCurrentValue(); }
  116. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  117. // module folder itself.
  118. ValueTreePropertyWithDefault 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. build_tools::RelativePath getLV2TurtleDumpProgramSource() const
  143. {
  144. return getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  145. .getChildFile ("LV2")
  146. .getChildFile ("juce_LV2TurtleDumpProgram.cpp");
  147. }
  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. enum class PackageDependencyType
  156. {
  157. compile,
  158. link
  159. };
  160. StringArray getLinuxPackages (PackageDependencyType type) const;
  161. //==============================================================================
  162. StringPairArray msvcExtraPreprocessorDefs;
  163. String msvcDelayLoadedDLLs;
  164. StringArray mingwLibs, windowsLibs;
  165. //==============================================================================
  166. StringArray androidLibs;
  167. //==============================================================================
  168. StringArray extraSearchPaths;
  169. StringArray moduleLibSearchPaths;
  170. //==============================================================================
  171. class BuildConfiguration : public ReferenceCountedObject
  172. {
  173. public:
  174. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  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. String getAllCompilerFlagsString() const { return (exporter.extraCompilerFlagsValue.get().toString() + " " + configCompilerFlagsValue.get().toString()).replaceCharacters ("\r\n", " ").trim(); }
  203. String getAllLinkerFlagsString() const { return (exporter.extraLinkerFlagsValue .get().toString() + " " + configLinkerFlagsValue .get().toString()).replaceCharacters ("\r\n", " ").trim(); }
  204. //==============================================================================
  205. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  206. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  207. //==============================================================================
  208. void createPropertyEditors (PropertyListBuilder&);
  209. void addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder&);
  210. void addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder&);
  211. struct CompilerNames
  212. {
  213. static constexpr const char* gcc = "GCC";
  214. static constexpr const char* llvm = "LLVM";
  215. };
  216. struct CompilerWarningFlags
  217. {
  218. static CompilerWarningFlags getRecommendedForGCCAndLLVM()
  219. {
  220. CompilerWarningFlags result;
  221. result.common = { "-Wall", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter",
  222. "-Wswitch-enum", "-Wsign-conversion", "-Wsign-compare",
  223. "-Wunreachable-code", "-Wcast-align", "-Wno-ignored-qualifiers" };
  224. result.cpp = { "-Woverloaded-virtual", "-Wreorder", "-Wzero-as-null-pointer-constant" };
  225. return result;
  226. }
  227. StringArray common, cpp, objc;
  228. };
  229. CompilerWarningFlags getRecommendedCompilerWarningFlags() const;
  230. void addGCCOptimisationProperty (PropertyListBuilder&);
  231. void removeFromExporter();
  232. //==============================================================================
  233. ValueTree config;
  234. Project& project;
  235. const ProjectExporter& exporter;
  236. protected:
  237. ValueTreePropertyWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, recommendedWarningsValue, optimisationLevelValue,
  238. linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue,
  239. usePrecompiledHeaderFileValue, precompiledHeaderFileValue, configCompilerFlagsValue, configLinkerFlagsValue;
  240. private:
  241. std::map<String, CompilerWarningFlags> recommendedCompilerWarningFlags;
  242. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  243. };
  244. void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy);
  245. void addNewConfiguration (bool isDebugConfig);
  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. std::optional<ValueTree> getConfigurationWithName (const String& nameToFind) const;
  276. BuildConfiguration::Ptr getBuildConfigurationWithName (const String& nameToFind) const;
  277. ValueTree getConfigurations() const;
  278. virtual void createDefaultConfigs();
  279. void createDefaultModulePaths();
  280. //==============================================================================
  281. Value getExporterPreprocessorDefsValue() { return extraPPDefsValue.getPropertyAsValue(); }
  282. String getExporterPreprocessorDefsString() const { return extraPPDefsValue.get(); }
  283. // includes exporter, project + config defs
  284. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const;
  285. // includes exporter + project defs
  286. StringPairArray getAllPreprocessorDefs() const;
  287. void addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const;
  288. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  289. ValueTree settings;
  290. enum GCCOptimisationLevel
  291. {
  292. gccO0 = 1,
  293. gccO1 = 4,
  294. gccO2 = 5,
  295. gccO3 = 3,
  296. gccOs = 2,
  297. gccOfast = 6
  298. };
  299. bool isPCHEnabledForAnyConfigurations() const
  300. {
  301. if (supportsPrecompiledHeaders())
  302. for (ConstConfigIterator config (*this); config.next();)
  303. if (config->shouldUsePrecompiledHeaderFile())
  304. return true;
  305. return false;
  306. }
  307. String getCompilerFlagsForProjectItem (const Project::Item& projectItem) const;
  308. protected:
  309. //==============================================================================
  310. String name;
  311. Project& project;
  312. const build_tools::ProjectType& projectType;
  313. const String projectName;
  314. const File projectFolder;
  315. //==============================================================================
  316. ValueTreePropertyWithDefaultWrapper vstLegacyPathValueWrapper, aaxPathValueWrapper, araPathValueWrapper;
  317. ValueTreePropertyWithDefault targetLocationValue, extraCompilerFlagsValue, extraLinkerFlagsValue, externalLibrariesValue,
  318. userNotesValue, gnuExtensionsValue, bigIconValue, smallIconValue, extraPPDefsValue;
  319. Value projectCompilerFlagSchemesValue;
  320. HashMap<String, ValueTreePropertyWithDefault> compilerFlagSchemesMap;
  321. mutable Array<Project::Item> itemGroups;
  322. Project::Item* modulesGroup = nullptr;
  323. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  324. void addDefaultPreprocessorDefs (StringPairArray&) const;
  325. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  326. static String getStaticLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".a"); }
  327. static String getDynamicLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".so"); }
  328. virtual void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) = 0;
  329. //==============================================================================
  330. static void createDirectoryOrThrow (const File& dirToCreate)
  331. {
  332. if (! dirToCreate.createDirectory())
  333. throw build_tools::SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  334. }
  335. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding,
  336. int maxCharsPerLine, bool useUnixNewLines = false)
  337. {
  338. XmlElement::TextFormat format;
  339. format.customEncoding = encoding;
  340. format.lineWrapLength = maxCharsPerLine;
  341. format.newLineChars = useUnixNewLines ? "\n" : "\r\n";
  342. MemoryOutputStream mo (8192);
  343. xml.writeTo (mo, format);
  344. build_tools::overwriteFileIfDifferentOrThrow (file, mo);
  345. }
  346. private:
  347. //==============================================================================
  348. void valueChanged (Value&) override { updateCompilerFlagValues(); }
  349. void updateCompilerFlagValues();
  350. //==============================================================================
  351. static String addLibPrefix (const String name)
  352. {
  353. return name.startsWith ("lib") ? name
  354. : "lib" + name;
  355. }
  356. static String addSuffix (const String name, const String suffix)
  357. {
  358. return name.endsWithIgnoreCase (suffix) ? name
  359. : name + suffix;
  360. }
  361. void createIconProperties (PropertyListBuilder&);
  362. void addExtraIncludePathsIfPluginOrHost();
  363. void addARAPathsIfPluginOrHost();
  364. void addCommonAudioPluginSettings();
  365. void addLegacyVSTFolderToPathIfSpecified();
  366. build_tools::RelativePath getInternalVST3SDKPath();
  367. void addAAXFoldersToPath();
  368. void addARAFoldersToPath();
  369. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  370. };