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 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 getLV2HelperProgramSource() const
  163. {
  164. return getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  165. .getChildFile ("LV2")
  166. .getChildFile ("juce_LV2ManifestHelper.cpp");
  167. }
  168. build_tools::RelativePath getVST3HelperProgramSource() const
  169. {
  170. const auto suffix = isOSX() ? "mm" : "cpp";
  171. return getModuleFolderRelativeToProject ("juce_audio_plugin_client")
  172. .getChildFile ("VST3")
  173. .getChildFile (String ("juce_VST3ManifestHelper.") + suffix);
  174. }
  175. //==============================================================================
  176. void copyMainGroupFromProject();
  177. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  178. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  179. Project::Item& getModulesGroup();
  180. //==============================================================================
  181. StringArray linuxLibs, linuxPackages, makefileExtraLinkerFlags;
  182. enum class PackageDependencyType
  183. {
  184. compile,
  185. link
  186. };
  187. StringArray getLinuxPackages (PackageDependencyType type) const;
  188. //==============================================================================
  189. StringPairArray msvcExtraPreprocessorDefs;
  190. String msvcDelayLoadedDLLs;
  191. StringArray mingwLibs, windowsLibs;
  192. //==============================================================================
  193. StringArray androidLibs;
  194. //==============================================================================
  195. StringArray extraSearchPaths;
  196. StringArray moduleLibSearchPaths;
  197. //==============================================================================
  198. const LinuxSubprocessHelperProperties linuxSubprocessHelperProperties { *this };
  199. //==============================================================================
  200. class BuildConfiguration : public ReferenceCountedObject
  201. {
  202. public:
  203. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  204. using Ptr = ReferenceCountedObjectPtr<BuildConfiguration>;
  205. //==============================================================================
  206. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  207. virtual String getModuleLibraryArchName() const = 0;
  208. //==============================================================================
  209. String getName() const { return configNameValue.get(); }
  210. bool isDebug() const { return isDebugValue.get(); }
  211. String getTargetBinaryRelativePathString() const { return targetBinaryPathValue.get(); }
  212. String getTargetBinaryNameString (bool isUnityPlugin = false) const
  213. {
  214. return (isUnityPlugin ? Project::addUnityPluginPrefixIfNecessary (targetNameValue.get().toString())
  215. : targetNameValue.get().toString());
  216. }
  217. int getOptimisationLevelInt() const { return optimisationLevelValue.get(); }
  218. String getGCCOptimisationFlag() const;
  219. bool isLinkTimeOptimisationEnabled() const { return linkTimeOptimisationValue.get(); }
  220. String getBuildConfigPreprocessorDefsString() const { return ppDefinesValue.get(); }
  221. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  222. String getHeaderSearchPathString() const { return headerSearchPathValue.get(); }
  223. StringArray getHeaderSearchPaths() const;
  224. String getLibrarySearchPathString() const { return librarySearchPathValue.get(); }
  225. StringArray getLibrarySearchPaths() const;
  226. String getPrecompiledHeaderFilename() const { return "JucePrecompiledHeader_" + getName(); }
  227. static String getSkipPrecompiledHeaderDefine() { return "JUCE_SKIP_PRECOMPILED_HEADER"; }
  228. bool shouldUsePrecompiledHeaderFile() const { return usePrecompiledHeaderFileValue.get(); }
  229. String getPrecompiledHeaderFileContent() const;
  230. String getAllCompilerFlagsString() const { return (exporter.extraCompilerFlagsValue.get().toString() + " " + configCompilerFlagsValue.get().toString()).replaceCharacters ("\r\n", " ").trim(); }
  231. String getAllLinkerFlagsString() const { return (exporter.extraLinkerFlagsValue .get().toString() + " " + configLinkerFlagsValue .get().toString()).replaceCharacters ("\r\n", " ").trim(); }
  232. //==============================================================================
  233. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  234. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  235. //==============================================================================
  236. void createPropertyEditors (PropertyListBuilder&);
  237. void addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder&);
  238. void addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder&);
  239. struct CompilerNames
  240. {
  241. static constexpr const char* gcc = "GCC";
  242. static constexpr const char* llvm = "LLVM";
  243. };
  244. struct CompilerWarningFlags
  245. {
  246. static CompilerWarningFlags getRecommendedForGCCAndLLVM()
  247. {
  248. CompilerWarningFlags result;
  249. result.common = {
  250. "-Wall",
  251. "-Wcast-align",
  252. "-Wfloat-equal",
  253. "-Wno-ignored-qualifiers",
  254. "-Wsign-compare",
  255. "-Wsign-conversion",
  256. "-Wstrict-aliasing",
  257. "-Wswitch-enum",
  258. "-Wuninitialized",
  259. "-Wunreachable-code",
  260. "-Wunused-parameter"
  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. };