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.

326 lines
14KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECTEXPORTER_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORTER_JUCEHEADER__
  20. #include "../jucer_Headers.h"
  21. #include "../Project/jucer_Project.h"
  22. #include "../Project/jucer_ProjectType.h"
  23. //==============================================================================
  24. class ProjectExporter
  25. {
  26. public:
  27. ProjectExporter (Project&, const ValueTree& settings);
  28. virtual ~ProjectExporter();
  29. static int getNumExporters();
  30. static StringArray getExporterNames();
  31. static ProjectExporter* createNewExporter (Project&, const int index);
  32. static ProjectExporter* createNewExporter (Project&, const String& name);
  33. static ProjectExporter* createExporter (Project&, const ValueTree& settings);
  34. static ProjectExporter* createPlatformDefaultExporter (Project&);
  35. static StringArray getDefaultExporters();
  36. //=============================================================================
  37. // return 0 if this can't be opened in the current OS, or a higher value, where higher numbers are more preferable.
  38. virtual int getLaunchPreferenceOrderForCurrentOS() = 0;
  39. virtual bool isPossibleForCurrentProject() = 0;
  40. virtual bool usesMMFiles() const = 0;
  41. virtual void createPropertyEditors (PropertyListBuilder&);
  42. virtual void launchProject() = 0;
  43. virtual void create (const OwnedArray<LibraryModule>&) const = 0; // may throw a SaveError
  44. virtual bool shouldFileBeCompiledByDefault (const RelativePath& path) const;
  45. virtual bool canCopeWithDuplicateFiles() = 0;
  46. virtual bool isXcode() const { return false; }
  47. virtual bool isVisualStudio() const { return false; }
  48. virtual bool isLinux() const { return false; }
  49. virtual bool isOSX() const { return false; }
  50. //==============================================================================
  51. String getName() const { return name; }
  52. File getTargetFolder() const;
  53. Project& getProject() noexcept { return project; }
  54. const Project& getProject() const noexcept { return project; }
  55. Value getSetting (const Identifier& name_) { return settings.getPropertyAsValue (name_, project.getUndoManagerFor (settings)); }
  56. Value getJuceFolderValue() { return getSetting (Ids::juceFolder); }
  57. String getJuceFolderString() const { return settings [Ids::juceFolder]; }
  58. Value getTargetLocationValue() { return getSetting (Ids::targetFolder); }
  59. String getTargetLocationString() const { return settings [Ids::targetFolder]; }
  60. Value getExtraCompilerFlags() { return getSetting (Ids::extraCompilerFlags); }
  61. String getExtraCompilerFlagsString() const { return settings [Ids::extraCompilerFlags]; }
  62. Value getExtraLinkerFlags() { return getSetting (Ids::extraLinkerFlags); }
  63. String getExtraLinkerFlagsString() const { return settings [Ids::extraLinkerFlags]; }
  64. // This adds the quotes, and may return angle-brackets, eg: <foo/bar.h> or normal quotes.
  65. String getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const;
  66. RelativePath rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const;
  67. void addToExtraSearchPaths (const RelativePath& pathFromProjectFolder);
  68. Value getBigIconImageItemID() { return getSetting (Ids::bigIcon); }
  69. Value getSmallIconImageItemID() { return getSetting (Ids::smallIcon); }
  70. Image getBigIcon() const;
  71. Image getSmallIcon() const;
  72. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const;
  73. String getExporterIdentifierMacro() const
  74. {
  75. return "JUCER_" + settings.getType().toString() + "_"
  76. + String::toHexString (settings [Ids::targetFolder].toString().hashCode()).toUpperCase();
  77. }
  78. // An exception that can be thrown by the create() method.
  79. class SaveError
  80. {
  81. public:
  82. SaveError (const String& error) : message (error)
  83. {}
  84. SaveError (const File& fileThatFailedToWrite)
  85. : message ("Can't write to the file: " + fileThatFailedToWrite.getFullPathName())
  86. {}
  87. String message;
  88. };
  89. RelativePath getJucePathFromTargetFolder() const;
  90. RelativePath getJucePathFromProjectFolder() const;
  91. //==============================================================================
  92. Array<Project::Item> groups;
  93. Project::Item& getModulesGroup();
  94. //==============================================================================
  95. String xcodePackageType, xcodeBundleSignature, xcodeBundleExtension;
  96. String xcodeProductType, xcodeProductInstallPath, xcodeFileType;
  97. String xcodeShellScript, xcodeShellScriptTitle, xcodeOtherRezFlags;
  98. String xcodeExcludedFiles64Bit;
  99. bool xcodeIsBundle, xcodeCreatePList, xcodeCanUseDwarf;
  100. StringArray xcodeFrameworks;
  101. Array<RelativePath> xcodeExtraLibrariesDebug, xcodeExtraLibrariesRelease;
  102. Array<XmlElement> xcodeExtraPListEntries;
  103. //==============================================================================
  104. String makefileTargetSuffix;
  105. bool makefileIsDLL;
  106. //==============================================================================
  107. String msvcTargetSuffix;
  108. StringPairArray msvcExtraPreprocessorDefs;
  109. bool msvcIsDLL, msvcIsWindowsSubsystem, msvcNeedsDLLRuntimeLib;
  110. String msvcDelayLoadedDLLs;
  111. //==============================================================================
  112. StringArray extraSearchPaths;
  113. //==============================================================================
  114. class BuildConfiguration : public ReferenceCountedObject
  115. {
  116. public:
  117. BuildConfiguration (Project& project, const ValueTree& configNode);
  118. ~BuildConfiguration();
  119. typedef ReferenceCountedObjectPtr<BuildConfiguration> Ptr;
  120. //==============================================================================
  121. virtual void createPropertyEditors (PropertyListBuilder&) = 0;
  122. //==============================================================================
  123. Value getNameValue() { return getValue (Ids::name); }
  124. String getName() const { return config [Ids::name]; }
  125. Value isDebugValue() { return getValue (Ids::isDebug); }
  126. bool isDebug() const { return config [Ids::isDebug]; }
  127. Value getTargetBinaryName() { return getValue (Ids::targetName); }
  128. String getTargetBinaryNameString() const { return config [Ids::targetName]; }
  129. // the path relative to the build folder in which the binary should go
  130. Value getTargetBinaryRelativePath() { return getValue (Ids::binaryPath); }
  131. String getTargetBinaryRelativePathString() const { return config [Ids::binaryPath]; }
  132. Value getOptimisationLevel() { return getValue (Ids::optimisation); }
  133. int getOptimisationLevelInt() const { return config [Ids::optimisation]; }
  134. String getGCCOptimisationFlag() const;
  135. Value getBuildConfigPreprocessorDefs() { return getValue (Ids::defines); }
  136. String getBuildConfigPreprocessorDefsString() const { return config [Ids::defines]; }
  137. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  138. Value getHeaderSearchPathValue() { return getValue (Ids::headerPath); }
  139. String getHeaderSearchPathString() const { return config [Ids::headerPath]; }
  140. StringArray getHeaderSearchPaths() const;
  141. Value getLibrarySearchPathValue() { return getValue (Ids::libraryPath); }
  142. String getLibrarySearchPathString() const { return config [Ids::libraryPath]; }
  143. StringArray getLibrarySearchPaths() const;
  144. String getGCCLibraryPathFlags() const;
  145. Value getValue (const Identifier& name) { return config.getPropertyAsValue (name, getUndoManager()); }
  146. UndoManager* getUndoManager() const { return project.getUndoManagerFor (config); }
  147. //==============================================================================
  148. ValueTree config;
  149. Project& project;
  150. protected:
  151. void createBasicPropertyEditors (PropertyListBuilder&);
  152. private:
  153. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration);
  154. };
  155. void addNewConfiguration (const BuildConfiguration* configToCopy);
  156. void deleteConfiguration (int index);
  157. bool hasConfigurationNamed (const String& name) const;
  158. String getUniqueConfigName (String name) const;
  159. //==============================================================================
  160. struct ConfigIterator
  161. {
  162. ConfigIterator (ProjectExporter& exporter);
  163. bool next();
  164. BuildConfiguration& operator*() const { return *config; }
  165. BuildConfiguration* operator->() const { return config; }
  166. BuildConfiguration::Ptr config;
  167. int index;
  168. private:
  169. ProjectExporter& exporter;
  170. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigIterator);
  171. };
  172. struct ConstConfigIterator
  173. {
  174. ConstConfigIterator (const ProjectExporter& exporter);
  175. bool next();
  176. const BuildConfiguration& operator*() const { return *config; }
  177. const BuildConfiguration* operator->() const { return config; }
  178. BuildConfiguration::Ptr config;
  179. int index;
  180. private:
  181. const ProjectExporter& exporter;
  182. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConstConfigIterator);
  183. };
  184. int getNumConfigurations() const;
  185. BuildConfiguration::Ptr getConfiguration (int index) const;
  186. ValueTree getConfigurations() const;
  187. void createDefaultConfigs();
  188. static const Identifier configurations, configuration;
  189. //==============================================================================
  190. Value getExporterPreprocessorDefs() { return getSetting (Ids::extraDefs); }
  191. String getExporterPreprocessorDefsString() const { return settings [Ids::extraDefs]; }
  192. // includes exporter, project + config defs
  193. StringPairArray getAllPreprocessorDefs (const BuildConfiguration& config) const;
  194. // includes exporter + project defs..
  195. StringPairArray getAllPreprocessorDefs() const;
  196. String replacePreprocessorTokens (const BuildConfiguration&, const String& sourceString) const;
  197. ValueTree settings;
  198. protected:
  199. //==============================================================================
  200. String name;
  201. Project& project;
  202. const ProjectType& projectType;
  203. const String projectName;
  204. const File projectFolder;
  205. Project::Item* modulesGroup;
  206. virtual BuildConfiguration::Ptr createBuildConfig (const ValueTree&) const = 0;
  207. static String getDefaultBuildsRootFolder() { return "Builds/"; }
  208. static String getLibbedFilename (String name)
  209. {
  210. if (! name.startsWith ("lib"))
  211. name = "lib" + name;
  212. if (! name.endsWithIgnoreCase (".a"))
  213. name = name + ".a";
  214. return name;
  215. }
  216. //==============================================================================
  217. static void overwriteFileIfDifferentOrThrow (const File& file, const MemoryOutputStream& newData)
  218. {
  219. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (file, newData))
  220. throw SaveError (file);
  221. }
  222. static void createDirectoryOrThrow (const File& dirToCreate)
  223. {
  224. if (! dirToCreate.createDirectory())
  225. throw SaveError ("Can't create folder: " + dirToCreate.getFullPathName());
  226. }
  227. static void writeXmlOrThrow (const XmlElement& xml, const File& file, const String& encoding, int maxCharsPerLine, bool useUnixNewLines = false)
  228. {
  229. MemoryOutputStream mo;
  230. xml.writeToStream (mo, String::empty, false, true, encoding, maxCharsPerLine);
  231. if (useUnixNewLines)
  232. {
  233. MemoryOutputStream mo2;
  234. mo2 << mo.toString().replace ("\r\n", "\n");
  235. overwriteFileIfDifferentOrThrow (file, mo2);
  236. }
  237. else
  238. {
  239. overwriteFileIfDifferentOrThrow (file, mo);
  240. }
  241. }
  242. private:
  243. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectExporter);
  244. };
  245. #endif // __JUCER_PROJECTEXPORTER_JUCEHEADER__