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.

227 lines
11KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "jucer_ProjectExporter.h"
  19. #include "jucer_ProjectExport_Make.h"
  20. #include "jucer_ProjectExport_MSVC.h"
  21. #include "jucer_ProjectExport_XCode.h"
  22. #include "jucer_ProjectExport_Android.h"
  23. //==============================================================================
  24. ProjectExporter::ProjectExporter (Project& project_, const ValueTree& settings_)
  25. : project (project_), settings (settings_)
  26. {
  27. }
  28. ProjectExporter::~ProjectExporter()
  29. {
  30. }
  31. //==============================================================================
  32. int ProjectExporter::getNumExporters()
  33. {
  34. return 6;
  35. }
  36. const StringArray ProjectExporter::getExporterNames()
  37. {
  38. StringArray s;
  39. s.add (XCodeProjectExporter::getNameMac());
  40. s.add (XCodeProjectExporter::getNameiOS());
  41. s.add (MSVCProjectExporterVC6::getName());
  42. s.add (MSVCProjectExporterVC2005::getName());
  43. s.add (MSVCProjectExporterVC2008::getName());
  44. s.add (MSVCProjectExporterVC2010::getName());
  45. s.add (MakefileProjectExporter::getNameLinux());
  46. s.add (AndroidProjectExporter::getNameAndroid());
  47. return s;
  48. }
  49. ProjectExporter* ProjectExporter::createNewExporter (Project& project, const int index)
  50. {
  51. ProjectExporter* exp = nullptr;
  52. switch (index)
  53. {
  54. case 0: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter::getValueTreeTypeName (false)), false); break;
  55. case 1: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter::getValueTreeTypeName (true)), true); break;
  56. case 2: exp = new MSVCProjectExporterVC6 (project, ValueTree (MSVCProjectExporterVC6::getValueTreeTypeName())); break;
  57. case 3: exp = new MSVCProjectExporterVC2005 (project, ValueTree (MSVCProjectExporterVC2005::getValueTreeTypeName())); break;
  58. case 4: exp = new MSVCProjectExporterVC2008 (project, ValueTree (MSVCProjectExporterVC2008::getValueTreeTypeName())); break;
  59. case 5: exp = new MSVCProjectExporterVC2010 (project, ValueTree (MSVCProjectExporterVC2010::getValueTreeTypeName())); break;
  60. case 6: exp = new MakefileProjectExporter (project, ValueTree (MakefileProjectExporter::getValueTreeTypeName())); break;
  61. case 7: exp = new AndroidProjectExporter (project, ValueTree (AndroidProjectExporter::getValueTreeTypeName())); break;
  62. default: jassertfalse; return 0;
  63. }
  64. File juceFolder (StoredSettings::getInstance()->getLastKnownJuceFolder());
  65. File target (exp->getTargetFolder());
  66. if (FileHelpers::shouldPathsBeRelative (juceFolder.getFullPathName(), project.getFile().getFullPathName()))
  67. exp->getJuceFolder() = juceFolder.getRelativePathFrom (project.getFile().getParentDirectory());
  68. else
  69. exp->getJuceFolder() = juceFolder.getFullPathName();
  70. return exp;
  71. }
  72. ProjectExporter* ProjectExporter::createExporter (Project& project, const ValueTree& settings)
  73. {
  74. ProjectExporter* exp = MSVCProjectExporterVC6::createForSettings (project, settings);
  75. if (exp == nullptr) exp = MSVCProjectExporterVC2005::createForSettings (project, settings);
  76. if (exp == nullptr) exp = MSVCProjectExporterVC2008::createForSettings (project, settings);
  77. if (exp == nullptr) exp = MSVCProjectExporterVC2010::createForSettings (project, settings);
  78. if (exp == nullptr) exp = XCodeProjectExporter::createForSettings (project, settings);
  79. if (exp == nullptr) exp = MakefileProjectExporter::createForSettings (project, settings);
  80. if (exp == nullptr) exp = AndroidProjectExporter::createForSettings (project, settings);
  81. jassert (exp != nullptr);
  82. return exp;
  83. }
  84. ProjectExporter* ProjectExporter::createPlatformDefaultExporter (Project& project)
  85. {
  86. for (int i = 0; i < project.getNumExporters(); ++i)
  87. {
  88. ScopedPointer <ProjectExporter> exp (project.createExporter (i));
  89. if (exp->isDefaultFormatForCurrentOS())
  90. return exp.release();
  91. }
  92. return 0;
  93. }
  94. const File ProjectExporter::getTargetFolder() const
  95. {
  96. return project.resolveFilename (getTargetLocation().toString());
  97. }
  98. const String ProjectExporter::getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const
  99. {
  100. String juceFolderPath (getJuceFolder().toString());
  101. if (juceFolderPath.startsWithChar ('<'))
  102. {
  103. juceFolderPath = FileHelpers::unixStylePath (File::addTrailingSeparator (juceFolderPath.substring (1).dropLastCharacters(1)));
  104. if (juceFolderPath == "/")
  105. juceFolderPath = String::empty;
  106. return "<" + juceFolderPath + pathFromJuceFolder + ">";
  107. }
  108. else
  109. {
  110. const RelativePath juceFromProject (juceFolderPath, RelativePath::projectFolder);
  111. const RelativePath fileFromProject (juceFromProject.getChildFile (pathFromJuceFolder));
  112. const RelativePath fileFromHere (fileFromProject.rebased (project.getFile().getParentDirectory(),
  113. targetIncludeFile.getParentDirectory(), RelativePath::unknown));
  114. return fileFromHere.toUnixStyle().quoted();
  115. }
  116. }
  117. const RelativePath ProjectExporter::getJucePathFromTargetFolder() const
  118. {
  119. return rebaseFromProjectFolderToBuildTarget (RelativePath (getJuceFolder().toString(), RelativePath::projectFolder));
  120. }
  121. const RelativePath ProjectExporter::rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const
  122. {
  123. return path.rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder);
  124. }
  125. bool ProjectExporter::shouldFileBeCompiledByDefault (const RelativePath& file) const
  126. {
  127. return file.hasFileExtension ("cpp;cc;c;cxx");
  128. }
  129. void ProjectExporter::createPropertyEditors (Array <PropertyComponent*>& props)
  130. {
  131. props.add (new TextPropertyComponent (getTargetLocation(), "Target Project Folder", 1024, false));
  132. props.getLast()->setTooltip ("The location of the folder in which the " + name + " project will be created. This path can be absolute, but it's much more sensible to make it relative to the jucer project directory.");
  133. props.add (new TextPropertyComponent (getJuceFolder(), "Juce Location", 1024, false));
  134. props.getLast()->setTooltip ("The location of the Juce library folder that the " + name + " project will use to when compiling. This can be an absolute path, or relative to the jucer project folder, but it must be valid on the filesystem of the machine you use to actually do the compiling.");
  135. if (project.isAudioPlugin())
  136. {
  137. if (project.shouldAddVSTFolderToPath())
  138. {
  139. props.add (new TextPropertyComponent (getVSTFolder(), "VST Folder", 1024, false));
  140. props.getLast()->setTooltip ("If you're building a VST, this must be the folder containing the VST SDK. This should be an absolute path.");
  141. }
  142. if (isRTAS())
  143. {
  144. props.add (new TextPropertyComponent (getRTASFolder(), "RTAS Folder", 1024, false));
  145. props.getLast()->setTooltip ("If you're building an RTAS, this must be the folder containing the RTAS SDK. This should be an absolute path.");
  146. }
  147. }
  148. props.add (new TextPropertyComponent (getExporterPreprocessorDefs(), "Extra Preprocessor Definitions", 32768, false));
  149. props.getLast()->setTooltip ("Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace or commas to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  150. props.add (new TextPropertyComponent (getExtraCompilerFlags(), "Extra compiler flags", 2048, false));
  151. props.getLast()->setTooltip ("Extra command-line flags to be passed to the compiler. This string can contain references to preprocessor definitions in the form ${NAME_OF_DEFINITION}, which will be replaced with their values.");
  152. props.add (new TextPropertyComponent (getExtraLinkerFlags(), "Extra linker flags", 2048, false));
  153. props.getLast()->setTooltip ("Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  154. }
  155. const Array<RelativePath> ProjectExporter::getVSTFilesRequired() const
  156. {
  157. Array<RelativePath> s;
  158. if (isVST())
  159. {
  160. const char* files[] = { JUCE_PLUGINS_PATH_VST "juce_VST_Wrapper.cpp",
  161. JUCE_PLUGINS_PATH_VST "juce_VST_Wrapper.mm" };
  162. for (int i = 0; i < numElementsInArray (files); ++i)
  163. s.add (getJucePathFromTargetFolder().getChildFile (files[i]));
  164. }
  165. return s;
  166. }
  167. const StringPairArray ProjectExporter::getAllPreprocessorDefs (const Project::BuildConfiguration& config) const
  168. {
  169. StringPairArray defs (mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  170. parsePreprocessorDefs (getExporterPreprocessorDefs().toString())));
  171. defs.set (getExporterIdentifierMacro(), "1");
  172. return defs;
  173. }
  174. const StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  175. {
  176. StringPairArray defs (mergePreprocessorDefs (project.getPreprocessorDefs(),
  177. parsePreprocessorDefs (getExporterPreprocessorDefs().toString())));
  178. defs.set (getExporterIdentifierMacro(), "1");
  179. return defs;
  180. }
  181. const String ProjectExporter::replacePreprocessorTokens (const Project::BuildConfiguration& config, const String& sourceString) const
  182. {
  183. return replacePreprocessorDefs (getAllPreprocessorDefs (config), sourceString);
  184. }