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.

480 lines
21KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "../Project/jucer_Project.h"
  15. #include "../Utility/UI/PropertyComponents/jucer_PropertyComponentsWithEnablement.h"
  16. #include "../Utility/Helpers/jucer_ValueTreePropertyWithDefaultWrapper.h"
  17. #include "../Project/Modules/jucer_Modules.h"
  18. class ProjectSaver;
  19. //==============================================================================
  20. class ProjectExporter : private Value::Listener
  21. {
  22. public:
  23. ProjectExporter (Project&, const ValueTree& settings);
  24. virtual ~ProjectExporter() override = default;
  25. //==============================================================================
  26. struct ExporterTypeInfo
  27. {
  28. Identifier identifier;
  29. String displayName;
  30. String targetFolder;
  31. Image icon;
  32. };
  33. static std::vector<ExporterTypeInfo> getExporterTypeInfos();
  34. static ExporterTypeInfo getTypeInfoForExporter (const Identifier& exporterIdentifier);
  35. static ExporterTypeInfo getCurrentPlatformExporterTypeInfo();
  36. static std::unique_ptr<ProjectExporter> createNewExporter (Project&, const Identifier& exporterIdentifier);
  37. static std::unique_ptr<ProjectExporter> createExporterFromSettings (Project&, const ValueTree& settings);
  38. static bool canProjectBeLaunched (Project*);
  39. virtual Identifier getExporterIdentifier() const = 0;
  40. //==============================================================================
  41. // capabilities of exporter
  42. virtual bool usesMMFiles() const = 0;
  43. virtual void createExporterProperties (PropertyListBuilder&) = 0;
  44. virtual bool canLaunchProject() = 0;
  45. virtual bool launchProject() = 0;
  46. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  47. virtual bool shouldFileBeCompiledByDefault (const File& path) const;
  48. virtual bool canCopeWithDuplicateFiles() = 0;
  49. virtual bool supportsUserDefinedConfigurations() const = 0; // false if exporter only supports two configs Debug and Release
  50. virtual void updateDeprecatedSettings() {}
  51. virtual void updateDeprecatedSettingsInteractively() {}
  52. virtual void initialiseDependencyPathValues() {}
  53. // IDE targeted by exporter
  54. virtual bool isXcode() const = 0;
  55. virtual bool isVisualStudio() const = 0;
  56. virtual bool isCodeBlocks() const = 0;
  57. virtual bool isMakefile() const = 0;
  58. virtual bool isAndroidStudio() const = 0;
  59. virtual bool isCLion() const = 0;
  60. // operating system targeted by exporter
  61. virtual bool isAndroid() const = 0;
  62. virtual bool isWindows() const = 0;
  63. virtual bool isLinux() const = 0;
  64. virtual bool isOSX() const = 0;
  65. virtual bool isiOS() const = 0;
  66. virtual String getNewLineString() const = 0;
  67. virtual String getDescription() { return {}; }
  68. virtual bool supportsPrecompiledHeaders() const { return false; }
  69. //==============================================================================
  70. // cross-platform audio plug-ins supported by exporter
  71. virtual bool supportsTargetType (build_tools::ProjectType::Target::Type type) const = 0;
  72. inline bool shouldBuildTargetType (build_tools::ProjectType::Target::Type type) const
  73. {
  74. return project.shouldBuildTargetType (type) && supportsTargetType (type);
  75. }
  76. inline void callForAllSupportedTargets (std::function<void (build_tools::ProjectType::Target::Type)> callback)
  77. {
  78. for (int i = 0; i < build_tools::ProjectType::Target::unspecified; ++i)
  79. if (shouldBuildTargetType (static_cast<build_tools::ProjectType::Target::Type> (i)))
  80. callback (static_cast<build_tools::ProjectType::Target::Type> (i));
  81. }
  82. //==============================================================================
  83. bool mayCompileOnCurrentOS() const
  84. {
  85. #if JUCE_MAC
  86. return isOSX() || isAndroid() || isiOS();
  87. #elif JUCE_WINDOWS
  88. return isWindows() || isAndroid();
  89. #elif JUCE_LINUX
  90. return isLinux() || isAndroid();
  91. #elif JUCE_BSD
  92. return isLinux();
  93. #else
  94. #error
  95. #endif
  96. }
  97. //==============================================================================
  98. String getUniqueName() const;
  99. File getTargetFolder() const;
  100. Project& getProject() noexcept { return project; }
  101. const Project& getProject() const noexcept { return project; }
  102. UndoManager* getUndoManager() const { return project.getUndoManagerFor (settings); }
  103. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  104. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  105. Value getTargetLocationValue() { return targetLocationValue.getPropertyAsValue(); }
  106. String getTargetLocationString() const { return targetLocationValue.get(); }
  107. String getExtraCompilerFlagsString() const { return extraCompilerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  108. String getExtraLinkerFlagsString() const { return extraLinkerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  109. StringArray getExternalLibrariesStringArray() const { return getSearchPathsFromString (externalLibrariesValue.get().toString()); }
  110. String getExternalLibrariesString() const { return getExternalLibrariesStringArray().joinIntoString (";"); }
  111. bool shouldUseGNUExtensions() const { return gnuExtensionsValue.get(); }
  112. String getVSTLegacyPathString() const { return vstLegacyPathValueWrapper.getCurrentValue(); }
  113. String getAAXPathString() const { return aaxPathValueWrapper.getCurrentValue(); }
  114. String getARAPathString() const { return araPathValueWrapper.getCurrentValue(); }
  115. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  116. // module folder itself.
  117. ValueTreePropertyWithDefault getPathForModuleValue (const String& moduleID);
  118. String getPathForModuleString (const String& moduleID) const;
  119. void removePathForModule (const String& moduleID);
  120. TargetOS::OS getTargetOSForExporter() const;
  121. build_tools::RelativePath getLegacyModulePath (const String& moduleID) const;
  122. String getLegacyModulePath() const;
  123. // Returns a path to the actual module folder itself
  124. build_tools::RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  125. void updateOldModulePaths();
  126. build_tools::RelativePath rebaseFromProjectFolderToBuildTarget (const build_tools::RelativePath& path) const;
  127. void addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index = -1);
  128. void addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder);
  129. void addProjectPathToBuildPathList (StringArray&, const build_tools::RelativePath&, int index = -1) const;
  130. std::unique_ptr<Drawable> getBigIcon() const;
  131. std::unique_ptr<Drawable> getSmallIcon() const;
  132. build_tools::Icons getIcons() const { return { getSmallIcon(), getBigIcon() }; }
  133. String getExporterIdentifierMacro() const
  134. {
  135. return "JUCER_" + settings.getType().toString() + "_"
  136. + String::toHexString (getTargetLocationString().hashCode()).toUpperCase();
  137. }
  138. // An exception that can be thrown by the create() method.
  139. void createPropertyEditors (PropertyListBuilder&);
  140. void addSettingsForProjectType (const build_tools::ProjectType&);
  141. build_tools::RelativePath getLV2TurtleDumpProgramSource() const
  142. {
  143. return getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  144. .getChildFile ("LV2")
  145. .getChildFile ("juce_LV2TurtleDumpProgram.cpp");
  146. }
  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, cpp, objc;
  226. };
  227. CompilerWarningFlags getRecommendedCompilerWarningFlags() const;
  228. void addGCCOptimisationProperty (PropertyListBuilder&);
  229. void removeFromExporter();
  230. //==============================================================================
  231. ValueTree config;
  232. Project& project;
  233. const ProjectExporter& exporter;
  234. protected:
  235. ValueTreePropertyWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, recommendedWarningsValue, optimisationLevelValue,
  236. linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue,
  237. usePrecompiledHeaderFileValue, precompiledHeaderFileValue;
  238. private:
  239. std::map<String, CompilerWarningFlags> recommendedCompilerWarningFlags;
  240. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  241. };
  242. void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy);
  243. void addNewConfiguration (bool isDebugConfig);
  244. bool hasConfigurationNamed (const String& name) const;
  245. String getUniqueConfigName (String name) const;
  246. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  247. //==============================================================================
  248. struct ConfigIterator
  249. {
  250. ConfigIterator (ProjectExporter& exporter);
  251. bool next();
  252. BuildConfiguration& operator*() const { return *config; }
  253. BuildConfiguration* operator->() const { return config.get(); }
  254. BuildConfiguration::Ptr config;
  255. int index;
  256. private:
  257. ProjectExporter& exporter;
  258. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  259. };
  260. struct ConstConfigIterator
  261. {
  262. ConstConfigIterator (const ProjectExporter& exporter);
  263. bool next();
  264. const BuildConfiguration& operator*() const { return *config; }
  265. const BuildConfiguration* operator->() const { return config.get(); }
  266. BuildConfiguration::Ptr config;
  267. int index;
  268. private:
  269. const ProjectExporter& exporter;
  270. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  271. };
  272. int getNumConfigurations() const;
  273. BuildConfiguration::Ptr getConfiguration (int index) const;
  274. ValueTree getConfigurations() const;
  275. virtual void createDefaultConfigs();
  276. void createDefaultModulePaths();
  277. //==============================================================================
  278. Value getExporterPreprocessorDefsValue() { return extraPPDefsValue.getPropertyAsValue(); }
  279. String getExporterPreprocessorDefsString() const { return extraPPDefsValue.get(); }
  280. // includes exporter, project + config defs
  281. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const;
  282. // includes exporter + project defs
  283. StringPairArray getAllPreprocessorDefs() const;
  284. void addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const;
  285. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  286. ValueTree settings;
  287. enum GCCOptimisationLevel
  288. {
  289. gccO0 = 1,
  290. gccO1 = 4,
  291. gccO2 = 5,
  292. gccO3 = 3,
  293. gccOs = 2,
  294. gccOfast = 6
  295. };
  296. bool isPCHEnabledForAnyConfigurations() const
  297. {
  298. if (supportsPrecompiledHeaders())
  299. for (ConstConfigIterator config (*this); config.next();)
  300. if (config->shouldUsePrecompiledHeaderFile())
  301. return true;
  302. return false;
  303. }
  304. protected:
  305. //==============================================================================
  306. String name;
  307. Project& project;
  308. const build_tools::ProjectType& projectType;
  309. const String projectName;
  310. const File projectFolder;
  311. //==============================================================================
  312. ValueTreePropertyWithDefaultWrapper vstLegacyPathValueWrapper, aaxPathValueWrapper, araPathValueWrapper;
  313. ValueTreePropertyWithDefault targetLocationValue, extraCompilerFlagsValue, extraLinkerFlagsValue, externalLibrariesValue,
  314. userNotesValue, gnuExtensionsValue, bigIconValue, smallIconValue, extraPPDefsValue;
  315. Value projectCompilerFlagSchemesValue;
  316. HashMap<String, ValueTreePropertyWithDefault> compilerFlagSchemesMap;
  317. mutable Array<Project::Item> itemGroups;
  318. Project::Item* modulesGroup = nullptr;
  319. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  320. void addDefaultPreprocessorDefs (StringPairArray&) const;
  321. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  322. static String getStaticLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".a"); }
  323. static String getDynamicLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".so"); }
  324. virtual void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) = 0;
  325. //==============================================================================
  326. static void createDirectoryOrThrow (const File& dirToCreate)
  327. {
  328. if (! dirToCreate.createDirectory())
  329. throw build_tools::SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  330. }
  331. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding,
  332. int maxCharsPerLine, bool useUnixNewLines = false)
  333. {
  334. XmlElement::TextFormat format;
  335. format.customEncoding = encoding;
  336. format.lineWrapLength = maxCharsPerLine;
  337. format.newLineChars = useUnixNewLines ? "\n" : "\r\n";
  338. MemoryOutputStream mo (8192);
  339. xml.writeTo (mo, format);
  340. build_tools::overwriteFileIfDifferentOrThrow (file, mo);
  341. }
  342. private:
  343. //==============================================================================
  344. void valueChanged (Value&) override { updateCompilerFlagValues(); }
  345. void updateCompilerFlagValues();
  346. //==============================================================================
  347. static String addLibPrefix (const String name)
  348. {
  349. return name.startsWith ("lib") ? name
  350. : "lib" + name;
  351. }
  352. static String addSuffix (const String name, const String suffix)
  353. {
  354. return name.endsWithIgnoreCase (suffix) ? name
  355. : name + suffix;
  356. }
  357. void createIconProperties (PropertyListBuilder&);
  358. void addExtraIncludePathsIfPluginOrHost();
  359. void addARAPathsIfPluginOrHost();
  360. void addCommonAudioPluginSettings();
  361. void addLegacyVSTFolderToPathIfSpecified();
  362. build_tools::RelativePath getInternalVST3SDKPath();
  363. void addAAXFoldersToPath();
  364. void addARAFoldersToPath();
  365. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  366. };