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.

215 lines
10KB

  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. //==============================================================================
  23. ProjectExporter::ProjectExporter (Project& project_, const ValueTree& settings_)
  24. : project (project_), settings (settings_)
  25. {
  26. }
  27. ProjectExporter::~ProjectExporter()
  28. {
  29. }
  30. //==============================================================================
  31. int ProjectExporter::getNumExporters()
  32. {
  33. return 6;
  34. }
  35. const StringArray ProjectExporter::getExporterNames()
  36. {
  37. StringArray s;
  38. s.add (XCodeProjectExporter::getNameMac());
  39. s.add (XCodeProjectExporter::getNameiOS());
  40. s.add (MSVCProjectExporterVC6::getName());
  41. s.add (MSVCProjectExporterVC2005::getName());
  42. s.add (MSVCProjectExporterVC2008::getName());
  43. s.add (MSVCProjectExporterVC2010::getName());
  44. s.add (MakefileProjectExporter::getNameLinux());
  45. return s;
  46. }
  47. ProjectExporter* ProjectExporter::createNewExporter (Project& project, const int index)
  48. {
  49. ProjectExporter* exp = 0;
  50. switch (index)
  51. {
  52. case 0: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter::getValueTreeTypeName (false)), false); break;
  53. case 1: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter::getValueTreeTypeName (true)), true); break;
  54. case 2: exp = new MSVCProjectExporterVC6 (project, ValueTree (MSVCProjectExporterVC6::getValueTreeTypeName())); break;
  55. case 3: exp = new MSVCProjectExporterVC2005 (project, ValueTree (MSVCProjectExporterVC2005::getValueTreeTypeName())); break;
  56. case 4: exp = new MSVCProjectExporterVC2008 (project, ValueTree (MSVCProjectExporterVC2008::getValueTreeTypeName())); break;
  57. case 5: exp = new MSVCProjectExporterVC2010 (project, ValueTree (MSVCProjectExporterVC2010::getValueTreeTypeName())); break;
  58. case 6: exp = new MakefileProjectExporter (project, ValueTree (MakefileProjectExporter::getValueTreeTypeName())); break;
  59. default: jassertfalse; return 0;
  60. }
  61. File juceFolder (StoredSettings::getInstance()->getLastKnownJuceFolder());
  62. File target (exp->getTargetFolder());
  63. if (FileHelpers::shouldPathsBeRelative (juceFolder.getFullPathName(), project.getFile().getFullPathName()))
  64. exp->getJuceFolder() = juceFolder.getRelativePathFrom (project.getFile().getParentDirectory());
  65. else
  66. exp->getJuceFolder() = juceFolder.getFullPathName();
  67. return exp;
  68. }
  69. ProjectExporter* ProjectExporter::createExporter (Project& project, const ValueTree& settings)
  70. {
  71. ProjectExporter* exp = MSVCProjectExporterVC6::createForSettings (project, settings);
  72. if (exp == 0) exp = MSVCProjectExporterVC2005::createForSettings (project, settings);
  73. if (exp == 0) exp = MSVCProjectExporterVC2008::createForSettings (project, settings);
  74. if (exp == 0) exp = MSVCProjectExporterVC2010::createForSettings (project, settings);
  75. if (exp == 0) exp = XCodeProjectExporter::createForSettings (project, settings);
  76. if (exp == 0) exp = MakefileProjectExporter::createForSettings (project, settings);
  77. jassert (exp != 0);
  78. return exp;
  79. }
  80. ProjectExporter* ProjectExporter::createPlatformDefaultExporter (Project& project)
  81. {
  82. for (int i = 0; i < project.getNumExporters(); ++i)
  83. {
  84. ScopedPointer <ProjectExporter> exp (project.createExporter (i));
  85. if (exp->isDefaultFormatForCurrentOS())
  86. return exp.release();
  87. }
  88. return 0;
  89. }
  90. const File ProjectExporter::getTargetFolder() const
  91. {
  92. return project.resolveFilename (getTargetLocation().toString());
  93. }
  94. const String ProjectExporter::getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const
  95. {
  96. String juceFolderPath (getJuceFolder().toString());
  97. if (juceFolderPath.startsWithChar ('<'))
  98. {
  99. juceFolderPath = FileHelpers::unixStylePath (File::addTrailingSeparator (juceFolderPath.substring (1).dropLastCharacters(1)));
  100. if (juceFolderPath == "/")
  101. juceFolderPath = String::empty;
  102. return "<" + juceFolderPath + pathFromJuceFolder + ">";
  103. }
  104. else
  105. {
  106. const RelativePath juceFromProject (juceFolderPath, RelativePath::projectFolder);
  107. const RelativePath fileFromProject (juceFromProject.getChildFile (pathFromJuceFolder));
  108. const RelativePath fileFromHere (fileFromProject.rebased (project.getFile().getParentDirectory(),
  109. targetIncludeFile.getParentDirectory(), RelativePath::unknown));
  110. return fileFromHere.toUnixStyle().quoted();
  111. }
  112. }
  113. const RelativePath ProjectExporter::getJucePathFromTargetFolder() const
  114. {
  115. return rebaseFromProjectFolderToBuildTarget (RelativePath (getJuceFolder().toString(), RelativePath::projectFolder));
  116. }
  117. const RelativePath ProjectExporter::rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const
  118. {
  119. return path.rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder);
  120. }
  121. bool ProjectExporter::shouldFileBeCompiledByDefault (const RelativePath& file) const
  122. {
  123. return file.hasFileExtension ("cpp;cc;c;cxx");
  124. }
  125. void ProjectExporter::createPropertyEditors (Array <PropertyComponent*>& props)
  126. {
  127. props.add (new TextPropertyComponent (getTargetLocation(), "Target Project Folder", 1024, false));
  128. 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.");
  129. props.add (new TextPropertyComponent (getJuceFolder(), "Juce Location", 1024, false));
  130. 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.");
  131. if (project.isAudioPlugin())
  132. {
  133. if (project.shouldAddVSTFolderToPath())
  134. {
  135. props.add (new TextPropertyComponent (getVSTFolder(), "VST Folder", 1024, false));
  136. props.getLast()->setTooltip ("If you're building a VST, this must be the folder containing the VST SDK. This should be an absolute path.");
  137. }
  138. if (isRTAS())
  139. {
  140. props.add (new TextPropertyComponent (getRTASFolder(), "RTAS Folder", 1024, false));
  141. props.getLast()->setTooltip ("If you're building an RTAS, this must be the folder containing the RTAS SDK. This should be an absolute path.");
  142. }
  143. }
  144. props.add (new TextPropertyComponent (getExporterPreprocessorDefs(), "Extra Preprocessor Definitions", 32768, false));
  145. 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.");
  146. props.add (new TextPropertyComponent (getExtraCompilerFlags(), "Extra compiler flags", 2048, false));
  147. 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.");
  148. props.add (new TextPropertyComponent (getExtraLinkerFlags(), "Extra linker flags", 2048, false));
  149. 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.");
  150. }
  151. const Array<RelativePath> ProjectExporter::getVSTFilesRequired() const
  152. {
  153. Array<RelativePath> s;
  154. if (isVST())
  155. {
  156. const char* files[] = { "extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp",
  157. "extras/audio plugins/wrapper/VST/juce_VST_Wrapper.mm" };
  158. for (int i = 0; i < numElementsInArray (files); ++i)
  159. s.add (getJucePathFromTargetFolder().getChildFile (files[i]));
  160. }
  161. return s;
  162. }
  163. const StringPairArray ProjectExporter::getAllPreprocessorDefs (const Project::BuildConfiguration& config) const
  164. {
  165. StringPairArray defs (mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  166. parsePreprocessorDefs (getExporterPreprocessorDefs().toString())));
  167. defs.set (getExporterIdentifierMacro(), "1");
  168. return defs;
  169. }
  170. const String ProjectExporter::replacePreprocessorTokens (const Project::BuildConfiguration& config, const String& sourceString) const
  171. {
  172. return replacePreprocessorDefs (getAllPreprocessorDefs (config), sourceString);
  173. }