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.

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