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.

257 lines
12KB

  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. : libraryFilesGroup (Project::Item::createGroup (project_, project_.getJuceCodeGroupName())),
  26. project (project_),
  27. settings (settings_)
  28. {
  29. }
  30. ProjectExporter::~ProjectExporter()
  31. {
  32. }
  33. //==============================================================================
  34. int ProjectExporter::getNumExporters()
  35. {
  36. return 6;
  37. }
  38. StringArray ProjectExporter::getExporterNames()
  39. {
  40. StringArray s;
  41. s.add (XCodeProjectExporter::getNameMac());
  42. s.add (XCodeProjectExporter::getNameiOS());
  43. s.add (MSVCProjectExporterVC6::getName());
  44. s.add (MSVCProjectExporterVC2005::getName());
  45. s.add (MSVCProjectExporterVC2008::getName());
  46. s.add (MSVCProjectExporterVC2010::getName());
  47. s.add (MakefileProjectExporter::getNameLinux());
  48. s.add (AndroidProjectExporter::getNameAndroid());
  49. return s;
  50. }
  51. ProjectExporter* ProjectExporter::createNewExporter (Project& project, const int index)
  52. {
  53. ProjectExporter* exp = nullptr;
  54. switch (index)
  55. {
  56. case 0: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter::getValueTreeTypeName (false)), false); break;
  57. case 1: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter::getValueTreeTypeName (true)), true); break;
  58. case 2: exp = new MSVCProjectExporterVC6 (project, ValueTree (MSVCProjectExporterVC6::getValueTreeTypeName())); break;
  59. case 3: exp = new MSVCProjectExporterVC2005 (project, ValueTree (MSVCProjectExporterVC2005::getValueTreeTypeName())); break;
  60. case 4: exp = new MSVCProjectExporterVC2008 (project, ValueTree (MSVCProjectExporterVC2008::getValueTreeTypeName())); break;
  61. case 5: exp = new MSVCProjectExporterVC2010 (project, ValueTree (MSVCProjectExporterVC2010::getValueTreeTypeName())); break;
  62. case 6: exp = new MakefileProjectExporter (project, ValueTree (MakefileProjectExporter::getValueTreeTypeName())); break;
  63. case 7: exp = new AndroidProjectExporter (project, ValueTree (AndroidProjectExporter::getValueTreeTypeName())); break;
  64. default: jassertfalse; return 0;
  65. }
  66. File juceFolder (StoredSettings::getInstance()->getLastKnownJuceFolder());
  67. File target (exp->getTargetFolder());
  68. if (FileHelpers::shouldPathsBeRelative (juceFolder.getFullPathName(), project.getFile().getFullPathName()))
  69. exp->getJuceFolder() = juceFolder.getRelativePathFrom (project.getFile().getParentDirectory());
  70. else
  71. exp->getJuceFolder() = juceFolder.getFullPathName();
  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. return exp;
  85. }
  86. ProjectExporter* ProjectExporter::createPlatformDefaultExporter (Project& project)
  87. {
  88. ScopedPointer <ProjectExporter> best;
  89. int bestPref = 0;
  90. for (int i = 0; i < project.getNumExporters(); ++i)
  91. {
  92. ScopedPointer <ProjectExporter> exp (project.createExporter (i));
  93. const int pref = exp->getLaunchPreferenceOrderForCurrentOS();
  94. if (pref > bestPref)
  95. {
  96. bestPref = pref;
  97. best = exp;
  98. }
  99. }
  100. return best.release();
  101. }
  102. File ProjectExporter::getTargetFolder() const
  103. {
  104. return project.resolveFilename (getTargetLocation().toString());
  105. }
  106. String ProjectExporter::getIncludePathForFileInJuceFolder (const String& pathFromJuceFolder, const File& targetIncludeFile) const
  107. {
  108. String juceFolderPath (getJuceFolder().toString());
  109. if (juceFolderPath.startsWithChar ('<'))
  110. {
  111. juceFolderPath = FileHelpers::unixStylePath (File::addTrailingSeparator (juceFolderPath.substring (1).dropLastCharacters(1)));
  112. if (juceFolderPath == "/")
  113. juceFolderPath = String::empty;
  114. return "<" + juceFolderPath + pathFromJuceFolder + ">";
  115. }
  116. else
  117. {
  118. const RelativePath juceFromProject (juceFolderPath, RelativePath::projectFolder);
  119. const RelativePath fileFromProject (juceFromProject.getChildFile (pathFromJuceFolder));
  120. const RelativePath fileFromHere (fileFromProject.rebased (project.getFile().getParentDirectory(),
  121. targetIncludeFile.getParentDirectory(), RelativePath::unknown));
  122. return fileFromHere.toUnixStyle().quoted();
  123. }
  124. }
  125. RelativePath ProjectExporter::getJucePathFromProjectFolder() const
  126. {
  127. return RelativePath (getJuceFolder().toString(), RelativePath::projectFolder);
  128. }
  129. RelativePath ProjectExporter::getJucePathFromTargetFolder() const
  130. {
  131. return rebaseFromProjectFolderToBuildTarget (getJucePathFromProjectFolder());
  132. }
  133. RelativePath ProjectExporter::rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const
  134. {
  135. return path.rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder);
  136. }
  137. bool ProjectExporter::shouldFileBeCompiledByDefault (const RelativePath& file) const
  138. {
  139. return file.hasFileExtension ("cpp;cc;c;cxx");
  140. }
  141. void ProjectExporter::createPropertyEditors (Array <PropertyComponent*>& props)
  142. {
  143. props.add (new TextPropertyComponent (getTargetLocation(), "Target Project Folder", 1024, false));
  144. 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.");
  145. props.add (new TextPropertyComponent (getJuceFolder(), "Juce Location", 1024, false));
  146. 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.");
  147. project.getProjectType().createPropertyEditors (*this, props);
  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. Project::Item ProjectExporter::createVSTGroup (bool forOSX) const
  156. {
  157. jassert (isVST());
  158. Project::Item group (Project::Item::createGroup (project, "Juce VST Wrapper"));
  159. const char* osxFiles[] = { JUCE_PLUGINS_PATH_VST "juce_VST_Wrapper.cpp",
  160. JUCE_PLUGINS_PATH_VST "juce_VST_Wrapper.mm", 0 };
  161. const char* winFiles[] = { JUCE_PLUGINS_PATH_VST "juce_VST_Wrapper.cpp", 0};
  162. for (const char** f = (forOSX ? osxFiles : winFiles); *f != 0; ++f)
  163. group.addRelativeFile (getJucePathFromProjectFolder().getChildFile (*f), -1);
  164. return group;
  165. }
  166. Project::Item ProjectExporter::createRTASGroup (bool forOSX) const
  167. {
  168. jassert (isRTAS());
  169. Project::Item group (Project::Item::createGroup (project, "Juce RTAS Wrapper"));
  170. const char* osxFiles[] = { JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode1.cpp",
  171. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode2.cpp",
  172. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode3.cpp",
  173. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode_Header.h",
  174. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_MacResources.r",
  175. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_MacUtilities.mm",
  176. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_Wrapper.cpp", 0 };
  177. const char* winFiles[] = { JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode1.cpp",
  178. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode2.cpp",
  179. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode3.cpp",
  180. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_DigiCode_Header.h",
  181. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_WinUtilities.cpp",
  182. JUCE_PLUGINS_PATH_RTAS "juce_RTAS_Wrapper.cpp" , 0};
  183. for (const char** f = (forOSX ? osxFiles : winFiles); *f != 0; ++f)
  184. group.addRelativeFile (getJucePathFromProjectFolder().getChildFile (*f), -1);
  185. return group;
  186. }
  187. StringPairArray ProjectExporter::getAllPreprocessorDefs (const Project::BuildConfiguration& config) const
  188. {
  189. StringPairArray defs (mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  190. parsePreprocessorDefs (getExporterPreprocessorDefs().toString())));
  191. defs.set (getExporterIdentifierMacro(), "1");
  192. return defs;
  193. }
  194. StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  195. {
  196. StringPairArray defs (mergePreprocessorDefs (project.getPreprocessorDefs(),
  197. parsePreprocessorDefs (getExporterPreprocessorDefs().toString())));
  198. defs.set (getExporterIdentifierMacro(), "1");
  199. return defs;
  200. }
  201. String ProjectExporter::replacePreprocessorTokens (const Project::BuildConfiguration& config, const String& sourceString) const
  202. {
  203. return replacePreprocessorDefs (getAllPreprocessorDefs (config), sourceString);
  204. }