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.

486 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. // 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. #elif JUCE_BSD
  96. return isLinux();
  97. #else
  98. #error
  99. #endif
  100. }
  101. //==============================================================================
  102. String getUniqueName() const;
  103. File getTargetFolder() const;
  104. Project& getProject() noexcept { return project; }
  105. const Project& getProject() const noexcept { return project; }
  106. UndoManager* getUndoManager() const { return project.getUndoManagerFor (settings); }
  107. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  108. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  109. Value getTargetLocationValue() { return targetLocationValue.getPropertyAsValue(); }
  110. String getTargetLocationString() const { return targetLocationValue.get(); }
  111. String getExtraCompilerFlagsString() const { return extraCompilerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  112. String getExtraLinkerFlagsString() const { return extraLinkerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  113. StringArray getExternalLibrariesStringArray() const { return getSearchPathsFromString (externalLibrariesValue.get().toString()); }
  114. String getExternalLibrariesString() const { return getExternalLibrariesStringArray().joinIntoString (";"); }
  115. bool shouldUseGNUExtensions() const { return gnuExtensionsValue.get(); }
  116. String getVSTLegacyPathString() const { return vstLegacyPathValueWrapper.getCurrentValue(); }
  117. String getAAXPathString() const { return aaxPathValueWrapper.getCurrentValue(); }
  118. String getARAPathString() const { return araPathValueWrapper.getCurrentValue(); }
  119. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  120. // module folder itself.
  121. ValueTreePropertyWithDefault getPathForModuleValue (const String& moduleID);
  122. String getPathForModuleString (const String& moduleID) const;
  123. void removePathForModule (const String& moduleID);
  124. TargetOS::OS getTargetOSForExporter() const;
  125. build_tools::RelativePath getLegacyModulePath (const String& moduleID) const;
  126. String getLegacyModulePath() const;
  127. // Returns a path to the actual module folder itself
  128. build_tools::RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  129. void updateOldModulePaths();
  130. build_tools::RelativePath rebaseFromProjectFolderToBuildTarget (const build_tools::RelativePath& path) const;
  131. void addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index = -1);
  132. void addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder);
  133. void addProjectPathToBuildPathList (StringArray&, const build_tools::RelativePath&, int index = -1) const;
  134. std::unique_ptr<Drawable> getBigIcon() const;
  135. std::unique_ptr<Drawable> getSmallIcon() const;
  136. build_tools::Icons getIcons() const { return { getSmallIcon(), getBigIcon() }; }
  137. String getExporterIdentifierMacro() const
  138. {
  139. return "JUCER_" + settings.getType().toString() + "_"
  140. + String::toHexString (getTargetLocationString().hashCode()).toUpperCase();
  141. }
  142. // An exception that can be thrown by the create() method.
  143. void createPropertyEditors (PropertyListBuilder&);
  144. void addSettingsForProjectType (const build_tools::ProjectType&);
  145. build_tools::RelativePath getLV2TurtleDumpProgramSource() const
  146. {
  147. return getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  148. .getChildFile ("LV2")
  149. .getChildFile ("juce_LV2TurtleDumpProgram.cpp");
  150. }
  151. //==============================================================================
  152. void copyMainGroupFromProject();
  153. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  154. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  155. Project::Item& getModulesGroup();
  156. //==============================================================================
  157. StringArray linuxLibs, linuxPackages, makefileExtraLinkerFlags;
  158. enum class PackageDependencyType
  159. {
  160. compile,
  161. link
  162. };
  163. StringArray getLinuxPackages (PackageDependencyType type) const;
  164. //==============================================================================
  165. StringPairArray msvcExtraPreprocessorDefs;
  166. String msvcDelayLoadedDLLs;
  167. StringArray mingwLibs, windowsLibs;
  168. //==============================================================================
  169. StringArray androidLibs;
  170. //==============================================================================
  171. StringArray extraSearchPaths;
  172. StringArray moduleLibSearchPaths;
  173. //==============================================================================
  174. class BuildConfiguration : public ReferenceCountedObject
  175. {
  176. public:
  177. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  178. ~BuildConfiguration();
  179. using Ptr = ReferenceCountedObjectPtr<BuildConfiguration>;
  180. //==============================================================================
  181. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  182. virtual String getModuleLibraryArchName() const = 0;
  183. //==============================================================================
  184. String getName() const { return configNameValue.get(); }
  185. bool isDebug() const { return isDebugValue.get(); }
  186. String getTargetBinaryRelativePathString() const { return targetBinaryPathValue.get(); }
  187. String getTargetBinaryNameString (bool isUnityPlugin = false) const
  188. {
  189. return (isUnityPlugin ? Project::addUnityPluginPrefixIfNecessary (targetNameValue.get().toString())
  190. : targetNameValue.get().toString());
  191. }
  192. int getOptimisationLevelInt() const { return optimisationLevelValue.get(); }
  193. String getGCCOptimisationFlag() const;
  194. bool isLinkTimeOptimisationEnabled() const { return linkTimeOptimisationValue.get(); }
  195. String getBuildConfigPreprocessorDefsString() const { return ppDefinesValue.get(); }
  196. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  197. StringPairArray getUniquePreprocessorDefs() const; // returns pre-processor definitions that are not already in the project pre-processor defs
  198. String getHeaderSearchPathString() const { return headerSearchPathValue.get(); }
  199. StringArray getHeaderSearchPaths() const;
  200. String getLibrarySearchPathString() const { return librarySearchPathValue.get(); }
  201. StringArray getLibrarySearchPaths() const;
  202. String getPrecompiledHeaderFilename() const { return "JucePrecompiledHeader_" + getName(); }
  203. static String getSkipPrecompiledHeaderDefine() { return "JUCE_SKIP_PRECOMPILED_HEADER"; }
  204. bool shouldUsePrecompiledHeaderFile() const { return usePrecompiledHeaderFileValue.get(); }
  205. String getPrecompiledHeaderFileContent() const;
  206. //==============================================================================
  207. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  208. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  209. //==============================================================================
  210. void createPropertyEditors (PropertyListBuilder&);
  211. void addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder&);
  212. void addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder&);
  213. struct CompilerNames
  214. {
  215. static constexpr const char* gcc = "GCC";
  216. static constexpr const char* llvm = "LLVM";
  217. };
  218. struct CompilerWarningFlags
  219. {
  220. static CompilerWarningFlags getRecommendedForGCCAndLLVM()
  221. {
  222. CompilerWarningFlags result;
  223. result.common = { "-Wall", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter",
  224. "-Wswitch-enum", "-Wsign-conversion", "-Wsign-compare",
  225. "-Wunreachable-code", "-Wcast-align", "-Wno-ignored-qualifiers" };
  226. result.cpp = { "-Woverloaded-virtual", "-Wreorder", "-Wzero-as-null-pointer-constant" };
  227. return result;
  228. }
  229. StringArray common, cpp, objc;
  230. };
  231. CompilerWarningFlags getRecommendedCompilerWarningFlags() const;
  232. void addGCCOptimisationProperty (PropertyListBuilder&);
  233. void removeFromExporter();
  234. //==============================================================================
  235. ValueTree config;
  236. Project& project;
  237. const ProjectExporter& exporter;
  238. protected:
  239. ValueTreePropertyWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, recommendedWarningsValue, optimisationLevelValue,
  240. linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue,
  241. usePrecompiledHeaderFileValue, precompiledHeaderFileValue;
  242. private:
  243. std::map<String, CompilerWarningFlags> recommendedCompilerWarningFlags;
  244. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  245. };
  246. void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy);
  247. void addNewConfiguration (bool isDebugConfig);
  248. bool hasConfigurationNamed (const String& name) const;
  249. String getUniqueConfigName (String name) const;
  250. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  251. //==============================================================================
  252. struct ConfigIterator
  253. {
  254. ConfigIterator (ProjectExporter& exporter);
  255. bool next();
  256. BuildConfiguration& operator*() const { return *config; }
  257. BuildConfiguration* operator->() const { return config.get(); }
  258. BuildConfiguration::Ptr config;
  259. int index;
  260. private:
  261. ProjectExporter& exporter;
  262. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  263. };
  264. struct ConstConfigIterator
  265. {
  266. ConstConfigIterator (const ProjectExporter& exporter);
  267. bool next();
  268. const BuildConfiguration& operator*() const { return *config; }
  269. const BuildConfiguration* operator->() const { return config.get(); }
  270. BuildConfiguration::Ptr config;
  271. int index;
  272. private:
  273. const ProjectExporter& exporter;
  274. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  275. };
  276. int getNumConfigurations() const;
  277. BuildConfiguration::Ptr getConfiguration (int index) const;
  278. ValueTree getConfigurations() const;
  279. virtual void createDefaultConfigs();
  280. void createDefaultModulePaths();
  281. //==============================================================================
  282. Value getExporterPreprocessorDefsValue() { return extraPPDefsValue.getPropertyAsValue(); }
  283. String getExporterPreprocessorDefsString() const { return extraPPDefsValue.get(); }
  284. // includes exporter, project + config defs
  285. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const;
  286. // includes exporter + project defs
  287. StringPairArray getAllPreprocessorDefs() const;
  288. void addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const;
  289. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  290. ValueTree settings;
  291. enum GCCOptimisationLevel
  292. {
  293. gccO0 = 1,
  294. gccO1 = 4,
  295. gccO2 = 5,
  296. gccO3 = 3,
  297. gccOs = 2,
  298. gccOfast = 6
  299. };
  300. bool isPCHEnabledForAnyConfigurations() const
  301. {
  302. if (supportsPrecompiledHeaders())
  303. for (ConstConfigIterator config (*this); config.next();)
  304. if (config->shouldUsePrecompiledHeaderFile())
  305. return true;
  306. return false;
  307. }
  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. };