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.

580 lines
25KB

  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_LV2TurtleDumpProgram.cpp");
  167. }
  168. std::vector<build_tools::RelativePath> getVST3HelperProgramSources (const ProjectExporter& exporter) const
  169. {
  170. const auto base = getModuleFolderRelativeToProject ("juce_audio_processors").getChildFile ("format_types")
  171. .getChildFile ("VST3_SDK");
  172. const auto publicSdk = base.getChildFile ("public.sdk");
  173. const auto source = publicSdk.getChildFile ("source");
  174. const auto vst = source.getChildFile ("vst");
  175. const auto hosting = vst.getChildFile ("hosting");
  176. const auto plugBase = base.getChildFile ("pluginterfaces")
  177. .getChildFile ("base");
  178. std::vector<build_tools::RelativePath> result
  179. {
  180. hosting.getChildFile ("module.cpp"),
  181. base.getChildFile ("public.sdk")
  182. .getChildFile ("samples")
  183. .getChildFile ("vst-utilities")
  184. .getChildFile ("moduleinfotool")
  185. .getChildFile ("source")
  186. .getChildFile ("main.cpp"),
  187. source.getChildFile ("common")
  188. .getChildFile ("memorystream.cpp"),
  189. vst.getChildFile ("moduleinfo")
  190. .getChildFile ("moduleinfocreator.cpp"),
  191. vst.getChildFile ("moduleinfo")
  192. .getChildFile ("moduleinfoparser.cpp"),
  193. vst.getChildFile ("utility")
  194. .getChildFile ("stringconvert.cpp"),
  195. vst.getChildFile ("vstinitiids.cpp"),
  196. plugBase.getChildFile ("coreiids.cpp"),
  197. plugBase.getChildFile ("funknown.cpp"),
  198. };
  199. if (exporter.isOSX())
  200. result.push_back (hosting.getChildFile ("module_mac.mm"));
  201. else if (exporter.isLinux())
  202. result.push_back (hosting.getChildFile ("module_linux.cpp"));
  203. else if (exporter.isWindows())
  204. result.push_back (hosting.getChildFile ("module_win32.cpp"));
  205. return result;
  206. }
  207. //==============================================================================
  208. void copyMainGroupFromProject();
  209. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  210. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  211. Project::Item& getModulesGroup();
  212. //==============================================================================
  213. StringArray linuxLibs, linuxPackages, makefileExtraLinkerFlags;
  214. enum class PackageDependencyType
  215. {
  216. compile,
  217. link
  218. };
  219. StringArray getLinuxPackages (PackageDependencyType type) const;
  220. //==============================================================================
  221. StringPairArray msvcExtraPreprocessorDefs;
  222. String msvcDelayLoadedDLLs;
  223. StringArray mingwLibs, windowsLibs;
  224. //==============================================================================
  225. StringArray androidLibs;
  226. //==============================================================================
  227. StringArray extraSearchPaths;
  228. StringArray moduleLibSearchPaths;
  229. //==============================================================================
  230. const LinuxSubprocessHelperProperties linuxSubprocessHelperProperties { *this };
  231. //==============================================================================
  232. class BuildConfiguration : public ReferenceCountedObject
  233. {
  234. public:
  235. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  236. using Ptr = ReferenceCountedObjectPtr<BuildConfiguration>;
  237. //==============================================================================
  238. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  239. virtual String getModuleLibraryArchName() const = 0;
  240. //==============================================================================
  241. String getName() const { return configNameValue.get(); }
  242. bool isDebug() const { return isDebugValue.get(); }
  243. String getTargetBinaryRelativePathString() const { return targetBinaryPathValue.get(); }
  244. String getTargetBinaryNameString (bool isUnityPlugin = false) const
  245. {
  246. return (isUnityPlugin ? Project::addUnityPluginPrefixIfNecessary (targetNameValue.get().toString())
  247. : targetNameValue.get().toString());
  248. }
  249. int getOptimisationLevelInt() const { return optimisationLevelValue.get(); }
  250. String getGCCOptimisationFlag() const;
  251. bool isLinkTimeOptimisationEnabled() const { return linkTimeOptimisationValue.get(); }
  252. String getBuildConfigPreprocessorDefsString() const { return ppDefinesValue.get(); }
  253. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  254. String getHeaderSearchPathString() const { return headerSearchPathValue.get(); }
  255. StringArray getHeaderSearchPaths() const;
  256. String getLibrarySearchPathString() const { return librarySearchPathValue.get(); }
  257. StringArray getLibrarySearchPaths() const;
  258. String getPrecompiledHeaderFilename() const { return "JucePrecompiledHeader_" + getName(); }
  259. static String getSkipPrecompiledHeaderDefine() { return "JUCE_SKIP_PRECOMPILED_HEADER"; }
  260. bool shouldUsePrecompiledHeaderFile() const { return usePrecompiledHeaderFileValue.get(); }
  261. String getPrecompiledHeaderFileContent() const;
  262. String getAllCompilerFlagsString() const { return (exporter.extraCompilerFlagsValue.get().toString() + " " + configCompilerFlagsValue.get().toString()).replaceCharacters ("\r\n", " ").trim(); }
  263. String getAllLinkerFlagsString() const { return (exporter.extraLinkerFlagsValue .get().toString() + " " + configLinkerFlagsValue .get().toString()).replaceCharacters ("\r\n", " ").trim(); }
  264. //==============================================================================
  265. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  266. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  267. //==============================================================================
  268. void createPropertyEditors (PropertyListBuilder&);
  269. void addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder&);
  270. void addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder&);
  271. struct CompilerNames
  272. {
  273. static constexpr const char* gcc = "GCC";
  274. static constexpr const char* llvm = "LLVM";
  275. };
  276. struct CompilerWarningFlags
  277. {
  278. static CompilerWarningFlags getRecommendedForGCCAndLLVM()
  279. {
  280. CompilerWarningFlags result;
  281. result.common = {
  282. "-Wall",
  283. "-Wcast-align",
  284. "-Wfloat-equal",
  285. "-Wno-ignored-qualifiers",
  286. "-Wsign-compare",
  287. "-Wsign-conversion",
  288. "-Wstrict-aliasing",
  289. "-Wswitch-enum",
  290. "-Wuninitialized",
  291. "-Wunreachable-code",
  292. "-Wunused-parameter"
  293. };
  294. result.cpp = {
  295. "-Woverloaded-virtual",
  296. "-Wreorder",
  297. "-Wzero-as-null-pointer-constant"
  298. };
  299. return result;
  300. }
  301. StringArray common, cpp, objc;
  302. };
  303. CompilerWarningFlags getRecommendedCompilerWarningFlags() const;
  304. void addGCCOptimisationProperty (PropertyListBuilder&);
  305. void removeFromExporter();
  306. //==============================================================================
  307. ValueTree config;
  308. Project& project;
  309. const ProjectExporter& exporter;
  310. protected:
  311. ValueTreePropertyWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, recommendedWarningsValue, optimisationLevelValue,
  312. linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue,
  313. usePrecompiledHeaderFileValue, precompiledHeaderFileValue, configCompilerFlagsValue, configLinkerFlagsValue;
  314. private:
  315. std::map<String, CompilerWarningFlags> recommendedCompilerWarningFlags;
  316. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  317. };
  318. void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy);
  319. void addNewConfiguration (bool isDebugConfig);
  320. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  321. //==============================================================================
  322. struct ConfigIterator
  323. {
  324. ConfigIterator (ProjectExporter& exporter);
  325. bool next();
  326. BuildConfiguration& operator*() const { return *config; }
  327. BuildConfiguration* operator->() const { return config.get(); }
  328. BuildConfiguration::Ptr config;
  329. int index;
  330. private:
  331. ProjectExporter& exporter;
  332. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  333. };
  334. struct ConstConfigIterator
  335. {
  336. ConstConfigIterator (const ProjectExporter& exporter);
  337. bool next();
  338. const BuildConfiguration& operator*() const { return *config; }
  339. const BuildConfiguration* operator->() const { return config.get(); }
  340. BuildConfiguration::Ptr config;
  341. int index;
  342. private:
  343. const ProjectExporter& exporter;
  344. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  345. };
  346. int getNumConfigurations() const;
  347. BuildConfiguration::Ptr getConfiguration (int index) const;
  348. ValueTree getConfigurations() const;
  349. virtual void createDefaultConfigs();
  350. void createDefaultModulePaths();
  351. //==============================================================================
  352. Value getExporterPreprocessorDefsValue() { return extraPPDefsValue.getPropertyAsValue(); }
  353. String getExporterPreprocessorDefsString() const { return extraPPDefsValue.get(); }
  354. // includes exporter, project + config defs
  355. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const;
  356. // includes exporter + project defs
  357. StringPairArray getAllPreprocessorDefs() const;
  358. void addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const;
  359. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  360. ValueTree settings;
  361. enum GCCOptimisationLevel
  362. {
  363. gccO0 = 1,
  364. gccO1 = 4,
  365. gccO2 = 5,
  366. gccO3 = 3,
  367. gccOs = 2,
  368. gccOfast = 6
  369. };
  370. bool isPCHEnabledForAnyConfigurations() const
  371. {
  372. if (supportsPrecompiledHeaders())
  373. for (ConstConfigIterator config (*this); config.next();)
  374. if (config->shouldUsePrecompiledHeaderFile())
  375. return true;
  376. return false;
  377. }
  378. String getCompilerFlagsForFileCompilerFlagScheme (StringRef) const;
  379. String getCompilerFlagsForProjectItem (const Project::Item&) const;
  380. protected:
  381. //==============================================================================
  382. String name;
  383. Project& project;
  384. const build_tools::ProjectType& projectType;
  385. const String projectName;
  386. const File projectFolder;
  387. //==============================================================================
  388. ValueTreePropertyWithDefaultWrapper vstLegacyPathValueWrapper, aaxPathValueWrapper, araPathValueWrapper;
  389. ValueTreePropertyWithDefault targetLocationValue, extraCompilerFlagsValue, extraLinkerFlagsValue, externalLibrariesValue,
  390. userNotesValue, gnuExtensionsValue, bigIconValue, smallIconValue, extraPPDefsValue;
  391. Value projectCompilerFlagSchemesValue;
  392. mutable Array<Project::Item> itemGroups;
  393. Project::Item* modulesGroup = nullptr;
  394. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  395. void addDefaultPreprocessorDefs (StringPairArray&) const;
  396. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  397. static String getStaticLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".a"); }
  398. static String getDynamicLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".so"); }
  399. virtual void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) = 0;
  400. //==============================================================================
  401. static void createDirectoryOrThrow (const File& dirToCreate)
  402. {
  403. if (! dirToCreate.createDirectory())
  404. throw build_tools::SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  405. }
  406. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding,
  407. int maxCharsPerLine, bool useUnixNewLines = false)
  408. {
  409. XmlElement::TextFormat format;
  410. format.customEncoding = encoding;
  411. format.lineWrapLength = maxCharsPerLine;
  412. format.newLineChars = useUnixNewLines ? "\n" : "\r\n";
  413. MemoryOutputStream mo (8192);
  414. xml.writeTo (mo, format);
  415. build_tools::overwriteFileIfDifferentOrThrow (file, mo);
  416. }
  417. private:
  418. //==============================================================================
  419. std::map<String, ValueTreePropertyWithDefault> compilerFlagSchemesMap;
  420. //==============================================================================
  421. void valueChanged (Value&) override { updateCompilerFlagValues(); }
  422. void updateCompilerFlagValues();
  423. //==============================================================================
  424. static String addLibPrefix (const String name)
  425. {
  426. return name.startsWith ("lib") ? name
  427. : "lib" + name;
  428. }
  429. static String addSuffix (const String name, const String suffix)
  430. {
  431. return name.endsWithIgnoreCase (suffix) ? name
  432. : name + suffix;
  433. }
  434. void createIconProperties (PropertyListBuilder&);
  435. void addExtraIncludePathsIfPluginOrHost();
  436. void addARAPathsIfPluginOrHost();
  437. void addCommonAudioPluginSettings();
  438. void addLegacyVSTFolderToPathIfSpecified();
  439. build_tools::RelativePath getInternalVST3SDKPath();
  440. void addAAXFoldersToPath();
  441. void addARAFoldersToPath();
  442. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  443. };