2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-10 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "jucer_ProjectExporter.h"
27 #include "jucer_ProjectExport_Make.h"
28 #include "jucer_ProjectExport_MSVC.h"
29 #include "jucer_ProjectExport_XCode.h"
30 #include "jucer_ProjectExport_Android.h"
33 //==============================================================================
34 ProjectExporter::ProjectExporter (Project
& project_
, const ValueTree
& settings_
)
35 : project (project_
), settings (settings_
)
39 ProjectExporter::~ProjectExporter()
43 //==============================================================================
44 int ProjectExporter::getNumExporters()
49 const StringArray
ProjectExporter::getExporterNames()
52 s
.add (XCodeProjectExporter::getNameMac());
53 s
.add (XCodeProjectExporter::getNameiOS());
54 s
.add (MSVCProjectExporterVC6::getName());
55 s
.add (MSVCProjectExporterVC2005::getName());
56 s
.add (MSVCProjectExporterVC2008::getName());
57 s
.add (MSVCProjectExporterVC2010::getName());
58 s
.add (MakefileProjectExporter::getNameLinux());
59 s
.add (AndroidProjectExporter::getNameAndroid());
63 ProjectExporter
* ProjectExporter::createNewExporter (Project
& project
, const int index
)
65 ProjectExporter
* exp
= nullptr;
69 case 0: exp
= new XCodeProjectExporter (project
, ValueTree (XCodeProjectExporter::getValueTreeTypeName (false)), false); break;
70 case 1: exp
= new XCodeProjectExporter (project
, ValueTree (XCodeProjectExporter::getValueTreeTypeName (true)), true); break;
71 case 2: exp
= new MSVCProjectExporterVC6 (project
, ValueTree (MSVCProjectExporterVC6::getValueTreeTypeName())); break;
72 case 3: exp
= new MSVCProjectExporterVC2005 (project
, ValueTree (MSVCProjectExporterVC2005::getValueTreeTypeName())); break;
73 case 4: exp
= new MSVCProjectExporterVC2008 (project
, ValueTree (MSVCProjectExporterVC2008::getValueTreeTypeName())); break;
74 case 5: exp
= new MSVCProjectExporterVC2010 (project
, ValueTree (MSVCProjectExporterVC2010::getValueTreeTypeName())); break;
75 case 6: exp
= new MakefileProjectExporter (project
, ValueTree (MakefileProjectExporter::getValueTreeTypeName())); break;
76 case 7: exp
= new AndroidProjectExporter (project
, ValueTree (AndroidProjectExporter::getValueTreeTypeName())); break;
77 default: jassertfalse
; return 0;
80 File
juceFolder (StoredSettings::getInstance()->getLastKnownJuceFolder());
81 File
target (exp
->getTargetFolder());
83 if (FileHelpers::shouldPathsBeRelative (juceFolder
.getFullPathName(), project
.getFile().getFullPathName()))
84 exp
->getJuceFolder() = juceFolder
.getRelativePathFrom (project
.getFile().getParentDirectory());
86 exp
->getJuceFolder() = juceFolder
.getFullPathName();
91 ProjectExporter
* ProjectExporter::createExporter (Project
& project
, const ValueTree
& settings
)
93 ProjectExporter
* exp
= MSVCProjectExporterVC6::createForSettings (project
, settings
);
94 if (exp
== nullptr) exp
= MSVCProjectExporterVC2005::createForSettings (project
, settings
);
95 if (exp
== nullptr) exp
= MSVCProjectExporterVC2008::createForSettings (project
, settings
);
96 if (exp
== nullptr) exp
= MSVCProjectExporterVC2010::createForSettings (project
, settings
);
97 if (exp
== nullptr) exp
= XCodeProjectExporter::createForSettings (project
, settings
);
98 if (exp
== nullptr) exp
= MakefileProjectExporter::createForSettings (project
, settings
);
99 if (exp
== nullptr) exp
= AndroidProjectExporter::createForSettings (project
, settings
);
101 jassert (exp
!= nullptr);
105 ProjectExporter
* ProjectExporter::createPlatformDefaultExporter (Project
& project
)
107 for (int i
= 0; i
< project
.getNumExporters(); ++i
)
109 ScopedPointer
<ProjectExporter
> exp (project
.createExporter (i
));
111 if (exp
->isDefaultFormatForCurrentOS())
112 return exp
.release();
118 const File
ProjectExporter::getTargetFolder() const
120 return project
.resolveFilename (getTargetLocation().toString());
123 const String
ProjectExporter::getIncludePathForFileInJuceFolder (const String
& pathFromJuceFolder
, const File
& targetIncludeFile
) const
125 String
juceFolderPath (getJuceFolder().toString());
127 if (juceFolderPath
.startsWithChar ('<'))
129 juceFolderPath
= FileHelpers::unixStylePath (File::addTrailingSeparator (juceFolderPath
.substring (1).dropLastCharacters(1)));
130 if (juceFolderPath
== "/")
131 juceFolderPath
= String::empty
;
133 return "<" + juceFolderPath
+ pathFromJuceFolder
+ ">";
137 const RelativePath
juceFromProject (juceFolderPath
, RelativePath::projectFolder
);
138 const RelativePath
fileFromProject (juceFromProject
.getChildFile (pathFromJuceFolder
));
139 const RelativePath
fileFromHere (fileFromProject
.rebased (project
.getFile().getParentDirectory(),
140 targetIncludeFile
.getParentDirectory(), RelativePath::unknown
));
141 return fileFromHere
.toUnixStyle().quoted();
145 const RelativePath
ProjectExporter::getJucePathFromTargetFolder() const
147 return rebaseFromProjectFolderToBuildTarget (RelativePath (getJuceFolder().toString(), RelativePath::projectFolder
));
150 const RelativePath
ProjectExporter::rebaseFromProjectFolderToBuildTarget (const RelativePath
& path
) const
152 return path
.rebased (project
.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder
);
155 bool ProjectExporter::shouldFileBeCompiledByDefault (const RelativePath
& file
) const
157 return file
.hasFileExtension ("cpp;cc;c;cxx");
160 void ProjectExporter::createPropertyEditors (Array
<PropertyComponent
*>& props
)
162 props
.add (new TextPropertyComponent (getTargetLocation(), "Target Project Folder", 1024, false));
163 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.");
165 props
.add (new TextPropertyComponent (getJuceFolder(), "Juce Location", 1024, false));
166 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.");
168 if (project
.isAudioPlugin())
170 if (project
.shouldAddVSTFolderToPath())
172 props
.add (new TextPropertyComponent (getVSTFolder(), "VST Folder", 1024, false));
173 props
.getLast()->setTooltip ("If you're building a VST, this must be the folder containing the VST SDK. This should be an absolute path.");
178 props
.add (new TextPropertyComponent (getRTASFolder(), "RTAS Folder", 1024, false));
179 props
.getLast()->setTooltip ("If you're building an RTAS, this must be the folder containing the RTAS SDK. This should be an absolute path.");
183 props
.add (new TextPropertyComponent (getExporterPreprocessorDefs(), "Extra Preprocessor Definitions", 32768, false));
184 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.");
186 props
.add (new TextPropertyComponent (getExtraCompilerFlags(), "Extra compiler flags", 2048, false));
187 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.");
188 props
.add (new TextPropertyComponent (getExtraLinkerFlags(), "Extra linker flags", 2048, false));
189 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.");
192 const Array
<RelativePath
> ProjectExporter::getVSTFilesRequired() const
194 Array
<RelativePath
> s
;
197 const char* files
[] = { JUCE_PLUGINS_PATH_VST
"juce_VST_Wrapper.cpp",
198 JUCE_PLUGINS_PATH_VST
"juce_VST_Wrapper.mm" };
200 for (int i
= 0; i
< numElementsInArray (files
); ++i
)
201 s
.add (getJucePathFromTargetFolder().getChildFile (files
[i
]));
207 const StringPairArray
ProjectExporter::getAllPreprocessorDefs (const Project::BuildConfiguration
& config
) const
209 StringPairArray
defs (mergePreprocessorDefs (config
.getAllPreprocessorDefs(),
210 parsePreprocessorDefs (getExporterPreprocessorDefs().toString())));
211 defs
.set (getExporterIdentifierMacro(), "1");
215 const StringPairArray
ProjectExporter::getAllPreprocessorDefs() const
217 StringPairArray
defs (mergePreprocessorDefs (project
.getPreprocessorDefs(),
218 parsePreprocessorDefs (getExporterPreprocessorDefs().toString())));
219 defs
.set (getExporterIdentifierMacro(), "1");
223 const String
ProjectExporter::replacePreprocessorTokens (const Project::BuildConfiguration
& config
, const String
& sourceString
) const
225 return replacePreprocessorDefs (getAllPreprocessorDefs (config
), sourceString
);