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.

460 lines
20KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  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. class ProjectSaver;
  17. //==============================================================================
  18. class ProjectExporter : private Value::Listener
  19. {
  20. public:
  21. ProjectExporter (Project&, const ValueTree& settings);
  22. virtual ~ProjectExporter() override;
  23. struct ExporterTypeInfo
  24. {
  25. String name;
  26. const void* iconData;
  27. int iconDataSize;
  28. Image getIcon() const
  29. {
  30. Image image (Image::ARGB, 200, 200, true);
  31. Graphics g (image);
  32. std::unique_ptr<Drawable> svgDrawable (Drawable::createFromImageData (iconData, (size_t) iconDataSize));
  33. svgDrawable->drawWithin (g, image.getBounds().toFloat(), RectanglePlacement::fillDestination, 1.0f);
  34. return image;
  35. }
  36. };
  37. static StringArray getExporterNames();
  38. static StringArray getExporterValueTreeNames();
  39. static Array<ExporterTypeInfo> getExporterTypes();
  40. static String getValueTreeNameForExporter (const String& exporterName);
  41. static String getTargetFolderForExporter (const String& exporterValueTreeName);
  42. static StringArray getAllDefaultBuildsFolders();
  43. static ProjectExporter* createNewExporter (Project&, const int index);
  44. static ProjectExporter* createNewExporter (Project&, const String& name);
  45. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  46. static bool canProjectBeLaunched (Project*);
  47. static String getCurrentPlatformExporterName();
  48. //==============================================================================
  49. // capabilities of exporter
  50. virtual bool usesMMFiles() const = 0;
  51. virtual void createExporterProperties (PropertyListBuilder&) = 0;
  52. virtual bool canLaunchProject() = 0;
  53. virtual bool launchProject() = 0;
  54. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  55. virtual bool shouldFileBeCompiledByDefault (const File& path) const;
  56. virtual bool canCopeWithDuplicateFiles() = 0;
  57. virtual bool supportsUserDefinedConfigurations() const = 0; // false if exporter only supports two configs Debug and Release
  58. virtual void updateDeprecatedSettings() {}
  59. virtual void updateDeprecatedSettingsInteractively() {}
  60. virtual void initialiseDependencyPathValues() {}
  61. // IDE targeted by exporter
  62. virtual bool isXcode() const = 0;
  63. virtual bool isVisualStudio() const = 0;
  64. virtual bool isCodeBlocks() const = 0;
  65. virtual bool isMakefile() const = 0;
  66. virtual bool isAndroidStudio() const = 0;
  67. virtual bool isCLion() const = 0;
  68. // operating system targeted by exporter
  69. virtual bool isAndroid() const = 0;
  70. virtual bool isWindows() const = 0;
  71. virtual bool isLinux() const = 0;
  72. virtual bool isOSX() const = 0;
  73. virtual bool isiOS() const = 0;
  74. virtual String getDescription() { return {}; }
  75. //==============================================================================
  76. // cross-platform audio plug-ins supported by exporter
  77. virtual bool supportsTargetType (build_tools::ProjectType::Target::Type type) const = 0;
  78. inline bool shouldBuildTargetType (build_tools::ProjectType::Target::Type type) const
  79. {
  80. return project.shouldBuildTargetType (type) && supportsTargetType (type);
  81. }
  82. inline void callForAllSupportedTargets (std::function<void (build_tools::ProjectType::Target::Type)> callback)
  83. {
  84. for (int i = 0; i < build_tools::ProjectType::Target::unspecified; ++i)
  85. if (shouldBuildTargetType (static_cast<build_tools::ProjectType::Target::Type> (i)))
  86. callback (static_cast<build_tools::ProjectType::Target::Type> (i));
  87. }
  88. //==============================================================================
  89. bool mayCompileOnCurrentOS() const
  90. {
  91. #if JUCE_MAC
  92. return isOSX() || isAndroid() || isiOS();
  93. #elif JUCE_WINDOWS
  94. return isWindows() || isAndroid();
  95. #elif JUCE_LINUX
  96. return isLinux() || isAndroid();
  97. #else
  98. #error
  99. #endif
  100. }
  101. //==============================================================================
  102. String getName() const;
  103. File getTargetFolder() const;
  104. Project& getProject() noexcept { return project; }
  105. const Project& getProject() const noexcept { return project; }
  106. UndoManager* getUndoManager() const { return project.getUndoManagerFor (settings); }
  107. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  108. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  109. Value getTargetLocationValue() { return targetLocationValue.getPropertyAsValue(); }
  110. String getTargetLocationString() const { return targetLocationValue.get(); }
  111. String getExtraCompilerFlagsString() const { return extraCompilerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  112. String getExtraLinkerFlagsString() const { return extraLinkerFlagsValue.get().toString().replaceCharacters ("\r\n", " "); }
  113. String getExternalLibrariesString() const { return getSearchPathsFromString (externalLibrariesValue.get().toString()).joinIntoString (";"); }
  114. bool shouldUseGNUExtensions() const { return gnuExtensionsValue.get(); }
  115. String getVSTLegacyPathString() const { return vstLegacyPathValueWrapper.wrappedValue.get(); }
  116. String getAAXPathString() const { return aaxPathValueWrapper.wrappedValue.get(); }
  117. String getRTASPathString() const { return rtasPathValueWrapper.wrappedValue.get(); }
  118. // NB: this is the path to the parent "modules" folder that contains the named module, not the
  119. // module folder itself.
  120. ValueWithDefault getPathForModuleValue (const String& moduleID);
  121. String getPathForModuleString (const String& moduleID) const;
  122. void removePathForModule (const String& moduleID);
  123. TargetOS::OS getTargetOSForExporter() const;
  124. build_tools::RelativePath getLegacyModulePath (const String& moduleID) const;
  125. String getLegacyModulePath() const;
  126. // Returns a path to the actual module folder itself
  127. build_tools::RelativePath getModuleFolderRelativeToProject (const String& moduleID) const;
  128. void updateOldModulePaths();
  129. build_tools::RelativePath rebaseFromProjectFolderToBuildTarget (const build_tools::RelativePath& path) const;
  130. void addToExtraSearchPaths (const build_tools::RelativePath& pathFromProjectFolder, int index = -1);
  131. void addToModuleLibPaths (const build_tools::RelativePath& pathFromProjectFolder);
  132. void addProjectPathToBuildPathList (StringArray&, const build_tools::RelativePath&, int index = -1) const;
  133. std::unique_ptr<Drawable> getBigIcon() const;
  134. std::unique_ptr<Drawable> getSmallIcon() const;
  135. build_tools::Icons getIcons() const { return { getSmallIcon(), getBigIcon() }; }
  136. String getExporterIdentifierMacro() const
  137. {
  138. return "JUCER_" + settings.getType().toString() + "_"
  139. + String::toHexString (getTargetLocationString().hashCode()).toUpperCase();
  140. }
  141. // An exception that can be thrown by the create() method.
  142. void createPropertyEditors (PropertyListBuilder&);
  143. void addSettingsForProjectType (const build_tools::ProjectType&);
  144. //==============================================================================
  145. void copyMainGroupFromProject();
  146. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  147. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  148. Project::Item& getModulesGroup();
  149. //==============================================================================
  150. StringArray linuxLibs, linuxPackages, makefileExtraLinkerFlags;
  151. //==============================================================================
  152. StringPairArray msvcExtraPreprocessorDefs;
  153. String msvcDelayLoadedDLLs;
  154. StringArray mingwLibs, windowsLibs;
  155. //==============================================================================
  156. StringArray androidLibs;
  157. //==============================================================================
  158. StringArray extraSearchPaths;
  159. StringArray moduleLibSearchPaths;
  160. //==============================================================================
  161. class BuildConfiguration : public ReferenceCountedObject
  162. {
  163. public:
  164. BuildConfiguration (Project& project, const ValueTree& configNode, const ProjectExporter&);
  165. ~BuildConfiguration();
  166. using Ptr = ReferenceCountedObjectPtr<BuildConfiguration>;
  167. //==============================================================================
  168. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  169. virtual String getModuleLibraryArchName() const = 0;
  170. //==============================================================================
  171. String getName() const { return configNameValue.get(); }
  172. bool isDebug() const { return isDebugValue.get(); }
  173. String getTargetBinaryRelativePathString() const { return targetBinaryPathValue.get(); }
  174. String getTargetBinaryNameString (bool isUnityPlugin = false) const
  175. {
  176. return (isUnityPlugin ? Project::addUnityPluginPrefixIfNecessary (targetNameValue.get().toString())
  177. : targetNameValue.get().toString());
  178. }
  179. int getOptimisationLevelInt() const { return optimisationLevelValue.get(); }
  180. String getGCCOptimisationFlag() const;
  181. bool isLinkTimeOptimisationEnabled() const { return linkTimeOptimisationValue.get(); }
  182. String getBuildConfigPreprocessorDefsString() const { return ppDefinesValue.get(); }
  183. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  184. StringPairArray getUniquePreprocessorDefs() const; // returns pre-processor definitions that are not already in the project pre-processor defs
  185. String getHeaderSearchPathString() const { return headerSearchPathValue.get(); }
  186. StringArray getHeaderSearchPaths() const;
  187. String getLibrarySearchPathString() const { return librarySearchPathValue.get(); }
  188. StringArray getLibrarySearchPaths() const;
  189. String getGCCLibraryPathFlags() const;
  190. //==============================================================================
  191. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  192. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  193. //==============================================================================
  194. void createPropertyEditors (PropertyListBuilder&);
  195. void addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder&);
  196. void addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder&);
  197. StringArray getRecommendedCompilerWarningFlags() const;
  198. void addGCCOptimisationProperty (PropertyListBuilder&);
  199. void removeFromExporter();
  200. //==============================================================================
  201. ValueTree config;
  202. Project& project;
  203. const ProjectExporter& exporter;
  204. protected:
  205. ValueWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, recommendedWarningsValue, optimisationLevelValue,
  206. linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue;
  207. private:
  208. std::map<String, StringArray> recommendedCompilerWarningFlags;
  209. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  210. };
  211. void addNewConfigurationFromExisting (const BuildConfiguration& configToCopy);
  212. void addNewConfiguration (bool isDebugConfig);
  213. bool hasConfigurationNamed (const String& name) const;
  214. String getUniqueConfigName (String name) const;
  215. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  216. //==============================================================================
  217. struct ConfigIterator
  218. {
  219. ConfigIterator (ProjectExporter& exporter);
  220. bool next();
  221. BuildConfiguration& operator*() const { return *config; }
  222. BuildConfiguration* operator->() const { return config.get(); }
  223. BuildConfiguration::Ptr config;
  224. int index;
  225. private:
  226. ProjectExporter& exporter;
  227. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  228. };
  229. struct ConstConfigIterator
  230. {
  231. ConstConfigIterator (const ProjectExporter& exporter);
  232. bool next();
  233. const BuildConfiguration& operator*() const { return *config; }
  234. const BuildConfiguration* operator->() const { return config.get(); }
  235. BuildConfiguration::Ptr config;
  236. int index;
  237. private:
  238. const ProjectExporter& exporter;
  239. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  240. };
  241. int getNumConfigurations() const;
  242. BuildConfiguration::Ptr getConfiguration (int index) const;
  243. ValueTree getConfigurations() const;
  244. virtual void createDefaultConfigs();
  245. void createDefaultModulePaths();
  246. //==============================================================================
  247. Value getExporterPreprocessorDefsValue() { return extraPPDefsValue.getPropertyAsValue(); }
  248. String getExporterPreprocessorDefsString() const { return extraPPDefsValue.get(); }
  249. // includes exporter, project + config defs
  250. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config, const build_tools::ProjectType::Target::Type targetType) const;
  251. // includes exporter + project defs
  252. StringPairArray getAllPreprocessorDefs() const;
  253. // just appconfig defs
  254. StringPairArray getAppConfigDefs() const;
  255. void addTargetSpecificPreprocessorDefs (StringPairArray& defs, const build_tools::ProjectType::Target::Type targetType) const;
  256. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  257. ValueTree settings;
  258. enum GCCOptimisationLevel
  259. {
  260. gccO0 = 1,
  261. gccO1 = 4,
  262. gccO2 = 5,
  263. gccO3 = 3,
  264. gccOs = 2,
  265. gccOfast = 6
  266. };
  267. protected:
  268. //==============================================================================
  269. String name;
  270. Project& project;
  271. const build_tools::ProjectType& projectType;
  272. const String projectName;
  273. const File projectFolder;
  274. //==============================================================================
  275. // Wraps a ValueWithDefault object that has a default which depends on a global value.
  276. // Used for the VST, RTAS and AAX project-specific path options.
  277. struct ValueWithDefaultWrapper : public Value::Listener
  278. {
  279. void init (const ValueWithDefault& vwd, ValueWithDefault global, TargetOS::OS targetOS)
  280. {
  281. wrappedValue = vwd;
  282. globalValue = global.getPropertyAsValue();
  283. globalIdentifier = global.getPropertyID();
  284. os = targetOS;
  285. if (wrappedValue.get() == var())
  286. wrappedValue.resetToDefault();
  287. globalValue.addListener (this);
  288. valueChanged (globalValue);
  289. }
  290. void valueChanged (Value&) override
  291. {
  292. wrappedValue.setDefault (getAppSettings().getStoredPath (globalIdentifier, os).get());
  293. }
  294. ValueWithDefault wrappedValue;
  295. Value globalValue;
  296. Identifier globalIdentifier;
  297. TargetOS::OS os;
  298. };
  299. ValueWithDefaultWrapper vstLegacyPathValueWrapper, rtasPathValueWrapper, aaxPathValueWrapper;
  300. ValueWithDefault targetLocationValue, extraCompilerFlagsValue, extraLinkerFlagsValue, externalLibrariesValue,
  301. userNotesValue, gnuExtensionsValue, bigIconValue, smallIconValue, extraPPDefsValue;
  302. Value projectCompilerFlagSchemesValue;
  303. HashMap<String, ValueWithDefault> compilerFlagSchemesMap;
  304. mutable Array<Project::Item> itemGroups;
  305. Project::Item* modulesGroup = nullptr;
  306. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  307. void addDefaultPreprocessorDefs (StringPairArray&) const;
  308. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  309. static String getStaticLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".a"); }
  310. static String getDynamicLibbedFilename (String name) { return addSuffix (addLibPrefix (name), ".so"); }
  311. virtual void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) = 0;
  312. //==============================================================================
  313. static void createDirectoryOrThrow (const File& dirToCreate)
  314. {
  315. if (! dirToCreate.createDirectory())
  316. throw build_tools::SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  317. }
  318. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding,
  319. int maxCharsPerLine, bool useUnixNewLines = false)
  320. {
  321. XmlElement::TextFormat format;
  322. format.customEncoding = encoding;
  323. format.lineWrapLength = maxCharsPerLine;
  324. format.newLineChars = useUnixNewLines ? "\n" : "\r\n";
  325. MemoryOutputStream mo (8192);
  326. xml.writeTo (mo, format);
  327. build_tools::overwriteFileIfDifferentOrThrow (file, mo);
  328. }
  329. private:
  330. //==============================================================================
  331. void valueChanged (Value&) override { updateCompilerFlagValues(); }
  332. void updateCompilerFlagValues();
  333. //==============================================================================
  334. static String addLibPrefix (const String name)
  335. {
  336. return name.startsWith ("lib") ? name
  337. : "lib" + name;
  338. }
  339. static String addSuffix (const String name, const String suffix)
  340. {
  341. return name.endsWithIgnoreCase (suffix) ? name
  342. : name + suffix;
  343. }
  344. void createDependencyPathProperties (PropertyListBuilder&);
  345. void createIconProperties (PropertyListBuilder&);
  346. void addVSTPathsIfPluginOrHost();
  347. void addCommonAudioPluginSettings();
  348. void addLegacyVSTFolderToPathIfSpecified();
  349. build_tools::RelativePath getInternalVST3SDKPath();
  350. void addAAXFoldersToPath();
  351. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  352. };