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.

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