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