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.

370 lines
15KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_PROJECTEXPORTER_JUCEHEADER__
  18. #define __JUCER_PROJECTEXPORTER_JUCEHEADER__
  19. #include "../jucer_Headers.h"
  20. #include "../Project/jucer_Project.h"
  21. #include "../Project/jucer_ProjectType.h"
  22. class ProjectSaver;
  23. //==============================================================================
  24. class ProjectExporter
  25. {
  26. public:
  27. ProjectExporter (Project&, const ValueTree& settings);
  28. virtual ~ProjectExporter();
  29. static StringArray getExporterNames();
  30. static ProjectExporter* createNewExporter (Project&, const int index);
  31. static ProjectExporter* createNewExporter (Project&, const String& name);
  32. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  33. static bool canProjectBeLaunched (Project*);
  34. static String getCurrentPlatformExporterName();
  35. //=============================================================================
  36. virtual bool usesMMFiles() const = 0;
  37. virtual void createExporterProperties (PropertyListBuilder&) = 0;
  38. virtual bool canLaunchProject() = 0;
  39. virtual bool launchProject() = 0;
  40. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  41. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  42. virtual bool canCopeWithDuplicateFiles() = 0;
  43. virtual bool isXcode() const { return false; }
  44. virtual bool isVisualStudio() const { return false; }
  45. virtual int getVisualStudioVersion() const { return 0; }
  46. virtual bool isCodeBlocks() const { return false; }
  47. virtual bool isAndroid() const { return false; }
  48. virtual bool isWindows() const { return false; }
  49. virtual bool isLinux() const { return false; }
  50. virtual bool isOSX() const { return false; }
  51. bool mayCompileOnCurrentOS() const
  52. {
  53. #if JUCE_MAC
  54. return isOSX() || isAndroid();
  55. #elif JUCE_WINDOWS
  56. return isWindows() || isAndroid();
  57. #elif JUCE_LINUX
  58. return isLinux() || isAndroid();
  59. #else
  60. #error
  61. #endif
  62. }
  63. //==============================================================================
  64. String getName() const { return name; }
  65. File getTargetFolder() const;
  66. Project& getProject() noexcept { return project; }
  67. const Project& getProject() const noexcept { return project; }
  68. Value getSetting (const Identifier& nm) { return settings.getPropertyAsValue (nm, project.getUndoManagerFor (settings)); }
  69. String getSettingString (const Identifier& nm) const { return settings [nm]; }
  70. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  71. String getTargetLocationString() const { return getSettingString (Ids::targetFolder); }
  72. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  73. String getExtraCompilerFlagsString() const { return getSettingString (Ids::extraCompilerFlags).replaceCharacters ("\r\n", " "); }
  74. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  75. String getExtraLinkerFlagsString() const { return getSettingString (Ids::extraLinkerFlags).replaceCharacters ("\r\n", " "); }
  76. Value getExternalLibraries() { return getSetting (Ids::externalLibraries); }
  77. String getExternalLibrariesString() const { return getSettingString (Ids::externalLibraries).replaceCharacters ("\r\n", " ;"); }
  78. Value getUserNotes() { return getSetting (Ids::userNotes); }
  79. Value getPathForModuleValue (const String& moduleID);
  80. String getPathForModuleString (const String& moduleID) const;
  81. void removePathForModule (const String& moduleID);
  82. RelativePath getLegacyModulePath (const String& moduleID) const;
  83. String getLegacyModulePath() const;
  84. // Returns a path to the actual module folder itself
  85. RelativePath getModuleFolderRelativeToProject (const String& moduleID, ProjectSaver& projectSaver) const;
  86. void updateOldModulePaths();
  87. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  88. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  89. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  90. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  91. Image getBigIcon() const;
  92. Image getSmallIcon() const;
  93. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  94. String getExporterIdentifierMacro() const
  95. {
  96. return "JUCER_" + settings.getType().toString() + "_"
  97. + String::toHexString (getSettingString (Ids::targetFolder).hashCode()).toUpperCase();
  98. }
  99. // An exception that can be thrown by the create() method.
  100. class SaveError
  101. {
  102. public:
  103. SaveError (const String& error) : message (error)
  104. {}
  105. SaveError (const File& fileThatFailedToWrite)
  106. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  107. {}
  108. String message;
  109. };
  110. void createPropertyEditors (PropertyListBuilder& props);
  111. //==============================================================================
  112. void copyMainGroupFromProject();
  113. Array<Project::Item>& getAllGroups() noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  114. const Array<Project::Item>& getAllGroups() const noexcept { jassert (itemGroups.size() > 0); return itemGroups; }
  115. Project::Item& getModulesGroup();
  116. //==============================================================================
  117. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  118. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  119. String xcodeOtherRezFlags, xcodeExcludedFiles64Bit;
  120. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  121. StringArray xcodeFrameworks;
  122. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  123. Array<XmlElement> xcodeExtraPListEntries;
  124. //==============================================================================
  125. String makefileTargetSuffix;
  126. bool makefileIsDLL;
  127. StringArray linuxLibs;
  128. //==============================================================================
  129. String msvcTargetSuffix;
  130. StringPairArray msvcExtraPreprocessorDefs;
  131. bool msvcIsDLL, msvcIsWindowsSubsystem;
  132. String msvcDelayLoadedDLLs;
  133. StringArray mingwLibs;
  134. //==============================================================================
  135. StringArray extraSearchPaths;
  136. //==============================================================================
  137. class BuildConfiguration : public ReferenceCountedObject
  138. {
  139. public:
  140. BuildConfiguration (Project& project, const ValueTree& configNode);
  141. ~BuildConfiguration();
  142. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  143. //==============================================================================
  144. virtual void createConfigProperties (PropertyListBuilder&) = 0;
  145. //==============================================================================
  146. Value getNameValue() { return getValue (Ids::name); }
  147. String getName() const { return config [Ids::name]; }
  148. Value isDebugValue() { return getValue (Ids::isDebug); }
  149. bool isDebug() const { return config [Ids::isDebug]; }
  150. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  151. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  152. // the path relative to the build folder in which the binary should go
  153. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  154. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  155. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  156. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  157. String getGCCOptimisationFlag() const;
  158. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  159. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  160. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  161. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  162. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  163. StringArray getHeaderSearchPaths() const;
  164. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  165. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  166. StringArray getLibrarySearchPaths() const;
  167. String getGCCLibraryPathFlags() const;
  168. Value getUserNotes() { return getValue (Ids::userNotes); }
  169. Value getValue (const Identifier& nm) { return config.getPropertyAsValue (nm, getUndoManager()); }
  170. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  171. void createPropertyEditors (PropertyListBuilder&);
  172. void removeFromExporter();
  173. //==============================================================================
  174. ValueTree config;
  175. Project& project;
  176. protected:
  177. private:
  178. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
  179. };
  180. void addNewConfiguration (const BuildConfiguration* configToCopy);
  181. bool hasConfigurationNamed (const String& name) const;
  182. String getUniqueConfigName (String name) const;
  183. String getExternalLibraryFlags (const BuildConfiguration& config) const;
  184. //==============================================================================
  185. struct ConfigIterator
  186. {
  187. ConfigIterator (ProjectExporter& exporter);
  188. bool next();
  189. BuildConfiguration& operator*() const { return *config; }
  190. BuildConfiguration* operator->() const { return config; }
  191. BuildConfiguration::Ptr config;
  192. int index;
  193. private:
  194. ProjectExporter& exporter;
  195. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator)
  196. };
  197. struct ConstConfigIterator
  198. {
  199. ConstConfigIterator (const ProjectExporter& exporter);
  200. bool next();
  201. const BuildConfiguration& operator*() const { return *config; }
  202. const BuildConfiguration* operator->() const { return config; }
  203. BuildConfiguration::Ptr config;
  204. int index;
  205. private:
  206. const ProjectExporter& exporter;
  207. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator)
  208. };
  209. int getNumConfigurations() const;
  210. BuildConfiguration::Ptr getConfiguration (int index) const;
  211. ValueTree getConfigurations() const;
  212. void createDefaultConfigs();
  213. void createDefaultModulePaths();
  214. //==============================================================================
  215. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  216. String getExporterPreprocessorDefsString() const { return getSettingString (Ids::extraDefs); }
  217. // includes exporter, project + config defs
  218. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  219. // includes exporter + project defs..
  220. StringPairArray getAllPreprocessorDefs() const;
  221. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  222. ValueTree settings;
  223. //==============================================================================
  224. enum OptimisationLevel
  225. {
  226. optimisationOff = 1,
  227. optimiseMinSize = 2,
  228. optimiseMaxSpeed = 3
  229. };
  230. protected:
  231. //==============================================================================
  232. String name;
  233. Project& project;
  234. const ProjectType& projectType;
  235. const String projectName;
  236. const File projectFolder;
  237. mutable Array<Project::Item> itemGroups;
  238. void initItemGroups() const;
  239. Project::Item* modulesGroup;
  240. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  241. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  242. static String getLibbedFilename (String name)
  243. {
  244. if (! name.startsWith ("lib"))
  245. name = "lib" + name;
  246. if (! name.endsWithIgnoreCase (".a"))
  247. name = name + ".a";
  248. return name;
  249. }
  250. //==============================================================================
  251. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  252. {
  253. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  254. throw SaveError (file);
  255. }
  256. static void createDirectoryOrThrow (const File& dirToCreate)
  257. {
  258. if (! dirToCreate.createDirectory())
  259. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  260. }
  261. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  262. {
  263. MemoryOutputStream mo;
  264. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  265. if (useUnixNewLines)
  266. {
  267. MemoryOutputStream mo2;
  268. mo2 << mo.toString().replace ("\r\n", "\n");
  269. overwriteFileIfDifferentOrThrow (file, mo2);
  270. }
  271. else
  272. {
  273. overwriteFileIfDifferentOrThrow (file, mo);
  274. }
  275. }
  276. static Image rescaleImageForIcon (Image image, int iconSize);
  277. private:
  278. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter)
  279. };
  280. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__