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.

537 lines
23KB

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