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.

841 lines
34KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_ProjectExporter.h"
  19. #include "jucer_ProjectSaver.h"
  20. #include "jucer_ProjectExport_Make.h"
  21. #include "jucer_ProjectExport_MSVC.h"
  22. #include "jucer_ProjectExport_XCode.h"
  23. #include "jucer_ProjectExport_AndroidBase.h"
  24. #include "jucer_ProjectExport_AndroidStudio.h"
  25. #include "jucer_ProjectExport_AndroidAnt.h"
  26. #include "jucer_ProjectExport_CodeBlocks.h"
  27. //==============================================================================
  28. static void addType (Array<ProjectExporter::ExporterTypeInfo>& list,
  29. const char* name, const void* iconData, int iconDataSize)
  30. {
  31. ProjectExporter::ExporterTypeInfo type = { name, iconData, iconDataSize };
  32. list.add (type);
  33. }
  34. Array<ProjectExporter::ExporterTypeInfo> ProjectExporter::getExporterTypes()
  35. {
  36. Array<ProjectExporter::ExporterTypeInfo> types;
  37. addType (types, XCodeProjectExporter::getNameMac(), BinaryData::projectIconXcode_png, BinaryData::projectIconXcode_pngSize);
  38. addType (types, XCodeProjectExporter::getNameiOS(), BinaryData::projectIconXcodeIOS_png, BinaryData::projectIconXcodeIOS_pngSize);
  39. addType (types, MSVCProjectExporterVC2015::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  40. addType (types, MSVCProjectExporterVC2013::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  41. addType (types, MSVCProjectExporterVC2012::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  42. addType (types, MSVCProjectExporterVC2010::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  43. addType (types, MSVCProjectExporterVC2008::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  44. addType (types, MSVCProjectExporterVC2005::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  45. addType (types, MakefileProjectExporter::getNameLinux(), BinaryData::projectIconLinuxMakefile_png, BinaryData::projectIconLinuxMakefile_pngSize);
  46. addType (types, AndroidStudioProjectExporter::getName(), BinaryData::projectIconAndroid_png, BinaryData::projectIconAndroid_pngSize);
  47. addType (types, AndroidAntProjectExporter::getName(), BinaryData::projectIconAndroid_png, BinaryData::projectIconAndroid_pngSize);
  48. addType (types, CodeBlocksProjectExporter::getNameWindows(), BinaryData::projectIconCodeblocks_png, BinaryData::projectIconCodeblocks_pngSize);
  49. addType (types, CodeBlocksProjectExporter::getNameLinux(), BinaryData::projectIconCodeblocks_png, BinaryData::projectIconCodeblocks_pngSize);
  50. return types;
  51. }
  52. ProjectExporter* ProjectExporter::createNewExporter (Project& project, const int index)
  53. {
  54. ProjectExporter* exp = nullptr;
  55. switch (index)
  56. {
  57. case 0: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter ::getValueTreeTypeName (false)), false); break;
  58. case 1: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter ::getValueTreeTypeName (true)), true); break;
  59. case 2: exp = new MSVCProjectExporterVC2015 (project, ValueTree (MSVCProjectExporterVC2015 ::getValueTreeTypeName())); break;
  60. case 3: exp = new MSVCProjectExporterVC2013 (project, ValueTree (MSVCProjectExporterVC2013 ::getValueTreeTypeName())); break;
  61. case 4: exp = new MSVCProjectExporterVC2012 (project, ValueTree (MSVCProjectExporterVC2012 ::getValueTreeTypeName())); break;
  62. case 5: exp = new MSVCProjectExporterVC2010 (project, ValueTree (MSVCProjectExporterVC2010 ::getValueTreeTypeName())); break;
  63. case 6: exp = new MSVCProjectExporterVC2008 (project, ValueTree (MSVCProjectExporterVC2008 ::getValueTreeTypeName())); break;
  64. case 7: exp = new MSVCProjectExporterVC2005 (project, ValueTree (MSVCProjectExporterVC2005 ::getValueTreeTypeName())); break;
  65. case 8: exp = new MakefileProjectExporter (project, ValueTree (MakefileProjectExporter ::getValueTreeTypeName())); break;
  66. case 9: exp = new AndroidStudioProjectExporter (project, ValueTree (AndroidStudioProjectExporter ::getValueTreeTypeName())); break;
  67. case 10: exp = new AndroidAntProjectExporter (project, ValueTree (AndroidAntProjectExporter ::getValueTreeTypeName())); break;
  68. case 11: exp = new CodeBlocksProjectExporter (project, ValueTree (CodeBlocksProjectExporter ::getValueTreeTypeName (CodeBlocksProjectExporter::windowsTarget)), CodeBlocksProjectExporter::windowsTarget); break;
  69. case 12: exp = new CodeBlocksProjectExporter (project, ValueTree (CodeBlocksProjectExporter ::getValueTreeTypeName (CodeBlocksProjectExporter::linuxTarget)), CodeBlocksProjectExporter::linuxTarget); break;
  70. default: jassertfalse; return 0;
  71. }
  72. exp->createDefaultConfigs();
  73. exp->createDefaultModulePaths();
  74. return exp;
  75. }
  76. StringArray ProjectExporter::getExporterNames()
  77. {
  78. StringArray s;
  79. Array<ExporterTypeInfo> types (getExporterTypes());
  80. for (int i = 0; i < types.size(); ++i)
  81. s.add (types.getReference(i).name);
  82. return s;
  83. }
  84. String ProjectExporter::getCurrentPlatformExporterName()
  85. {
  86. #if JUCE_MAC
  87. return XCodeProjectExporter::getNameMac();
  88. #elif JUCE_WINDOWS
  89. return MSVCProjectExporterVC2010::getName();
  90. #elif JUCE_LINUX
  91. return MakefileProjectExporter::getNameLinux();
  92. #else
  93. #error // huh?
  94. #endif
  95. }
  96. ProjectExporter* ProjectExporter::createNewExporter (Project& project, const String& name)
  97. {
  98. return createNewExporter (project, getExporterNames().indexOf (name));
  99. }
  100. ProjectExporter* ProjectExporter::createExporter (Project& project, const ValueTree& settings)
  101. {
  102. ProjectExporter* exp = MSVCProjectExporterVC2005 ::createForSettings (project, settings);
  103. if (exp == nullptr) exp = MSVCProjectExporterVC2008 ::createForSettings (project, settings);
  104. if (exp == nullptr) exp = MSVCProjectExporterVC2010 ::createForSettings (project, settings);
  105. if (exp == nullptr) exp = MSVCProjectExporterVC2012 ::createForSettings (project, settings);
  106. if (exp == nullptr) exp = MSVCProjectExporterVC2013 ::createForSettings (project, settings);
  107. if (exp == nullptr) exp = MSVCProjectExporterVC2015 ::createForSettings (project, settings);
  108. if (exp == nullptr) exp = XCodeProjectExporter ::createForSettings (project, settings);
  109. if (exp == nullptr) exp = MakefileProjectExporter ::createForSettings (project, settings);
  110. if (exp == nullptr) exp = AndroidStudioProjectExporter ::createForSettings (project, settings);
  111. if (exp == nullptr) exp = AndroidAntProjectExporter ::createForSettings (project, settings);
  112. if (exp == nullptr) exp = CodeBlocksProjectExporter ::createForSettings (project, settings);
  113. jassert (exp != nullptr);
  114. return exp;
  115. }
  116. bool ProjectExporter::canProjectBeLaunched (Project* project)
  117. {
  118. if (project != nullptr)
  119. {
  120. const char* types[] =
  121. {
  122. #if JUCE_MAC
  123. XCodeProjectExporter::getValueTreeTypeName (false),
  124. XCodeProjectExporter::getValueTreeTypeName (true),
  125. #elif JUCE_WINDOWS
  126. MSVCProjectExporterVC2005::getValueTreeTypeName(),
  127. MSVCProjectExporterVC2008::getValueTreeTypeName(),
  128. MSVCProjectExporterVC2010::getValueTreeTypeName(),
  129. MSVCProjectExporterVC2012::getValueTreeTypeName(),
  130. MSVCProjectExporterVC2013::getValueTreeTypeName(),
  131. MSVCProjectExporterVC2015::getValueTreeTypeName(),
  132. #elif JUCE_LINUX
  133. // (this doesn't currently launch.. not really sure what it would do on linux)
  134. //MakefileProjectExporter::getValueTreeTypeName(),
  135. #endif
  136. AndroidStudioProjectExporter::getValueTreeTypeName(),
  137. nullptr
  138. };
  139. for (const char** type = types; *type != nullptr; ++type)
  140. if (project->getExporters().getChildWithName (*type).isValid())
  141. return true;
  142. }
  143. return false;
  144. }
  145. //==============================================================================
  146. ProjectExporter::ProjectExporter (Project& p, const ValueTree& state)
  147. : makefileIsDLL (false),
  148. msvcIsDLL (false),
  149. msvcIsWindowsSubsystem (true),
  150. settings (state),
  151. project (p),
  152. projectType (p.getProjectType()),
  153. projectName (p.getTitle()),
  154. projectFolder (p.getProjectFolder()),
  155. modulesGroup (nullptr)
  156. {
  157. }
  158. ProjectExporter::~ProjectExporter()
  159. {
  160. }
  161. File ProjectExporter::getTargetFolder() const
  162. {
  163. return project.resolveFilename (getTargetLocationString());
  164. }
  165. RelativePath ProjectExporter::rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const
  166. {
  167. return path.rebased (project.getProjectFolder(), getTargetFolder(), RelativePath::buildTargetFolder);
  168. }
  169. bool ProjectExporter::shouldFileBeCompiledByDefault (const RelativePath& file) const
  170. {
  171. return file.hasFileExtension (cOrCppFileExtensions)
  172. || file.hasFileExtension (asmFileExtensions);
  173. }
  174. //==============================================================================
  175. void ProjectExporter::createPropertyEditors (PropertyListBuilder& props)
  176. {
  177. props.add (new TextPropertyComponent (getTargetLocationValue(), "Target Project Folder", 2048, false),
  178. "The location of the folder in which the " + name + " project will be created. "
  179. "This path can be absolute, but it's much more sensible to make it relative to the jucer project directory.");
  180. createDependencyPathProperties (props);
  181. props.add (new TextPropertyComponent (getExporterPreprocessorDefs(), "Extra Preprocessor Definitions", 32768, true),
  182. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, "
  183. "or new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  184. props.add (new TextPropertyComponent (getExtraCompilerFlags(), "Extra compiler flags", 8192, true),
  185. "Extra command-line flags to be passed to the compiler. This string can contain references to preprocessor definitions in the "
  186. "form ${NAME_OF_DEFINITION}, which will be replaced with their values.");
  187. props.add (new TextPropertyComponent (getExtraLinkerFlags(), "Extra linker flags", 8192, true),
  188. "Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. "
  189. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  190. props.add (new TextPropertyComponent (getExternalLibraries(), "External libraries to link", 8192, true),
  191. "Additional libraries to link (one per line). You should not add any platform specific decoration to these names. "
  192. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  193. createIconProperties (props);
  194. createExporterProperties (props);
  195. props.add (new TextPropertyComponent (getUserNotes(), "Notes", 32768, true),
  196. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  197. }
  198. void ProjectExporter::createDependencyPathProperties (PropertyListBuilder& props)
  199. {
  200. if (supportsVST() && (project.shouldBuildVST().getValue() || project.isVSTPluginHost()))
  201. {
  202. props.add (new DependencyPathPropertyComponent (getVSTPathValue (false), "VST SDK Folder"),
  203. "If you're building a VST plugin or host, this must be the folder containing the VST SDK. This should be an absolute path.");
  204. }
  205. if (supportsVST3() && (project.shouldBuildVST3().getValue() || project.isVST3PluginHost()))
  206. {
  207. props.add (new DependencyPathPropertyComponent (getVSTPathValue (true), "VST3 SDK Folder"),
  208. "If you're building a VST3 plugin or host, this must be the folder containing the VST3 SDK. This should be an absolute path.");
  209. }
  210. if (supportsAAX() && project.shouldBuildAAX().getValue())
  211. {
  212. props.add (new DependencyPathPropertyComponent (getAAXPathValue(), "AAX SDK Folder"),
  213. "If you're building an AAX plugin, this must be the folder containing the AAX SDK. This should be an absolute path.");
  214. }
  215. if (supportsRTAS() && project.shouldBuildRTAS().getValue())
  216. {
  217. props.add (new DependencyPathPropertyComponent (getRTASPathValue(), "RTAS SDK Folder"),
  218. "If you're building an RTAS, this must be the folder containing the RTAS SDK. This should be an absolute path.");
  219. }
  220. }
  221. void ProjectExporter::createIconProperties (PropertyListBuilder& props)
  222. {
  223. OwnedArray<Project::Item> images;
  224. project.findAllImageItems (images);
  225. StringArray choices;
  226. Array<var> ids;
  227. choices.add ("<None>");
  228. ids.add (var::null);
  229. choices.add (String::empty);
  230. ids.add (var::null);
  231. for (int i = 0; i < images.size(); ++i)
  232. {
  233. choices.add (images.getUnchecked(i)->getName());
  234. ids.add (images.getUnchecked(i)->getID());
  235. }
  236. props.add (new ChoicePropertyComponent (getSmallIconImageItemID(), "Icon (small)", choices, ids),
  237. "Sets an icon to use for the executable.");
  238. props.add (new ChoicePropertyComponent (getBigIconImageItemID(), "Icon (large)", choices, ids),
  239. "Sets an icon to use for the executable.");
  240. }
  241. //==============================================================================
  242. void ProjectExporter::addSettingsForProjectType (const ProjectType& type)
  243. {
  244. addVSTPathsIfPluginOrHost();
  245. if (type.isAudioPlugin())
  246. addCommonAudioPluginSettings();
  247. addPlatformSpecificSettingsForProjectType (type);
  248. }
  249. void ProjectExporter::addVSTPathsIfPluginOrHost()
  250. {
  251. if (supportsVST() && (project.shouldBuildVST().getValue() || project.isVSTPluginHost()))
  252. {
  253. makefileTargetSuffix = ".so";
  254. addVSTFolderToPath (false);
  255. }
  256. if (supportsVST3() && (project.shouldBuildVST3().getValue() || project.isVST3PluginHost()))
  257. {
  258. makefileTargetSuffix = ".so";
  259. addVSTFolderToPath (true);
  260. }
  261. }
  262. void ProjectExporter::addCommonAudioPluginSettings()
  263. {
  264. if (isLinux() && (getProject().shouldBuildVST().getValue() || getProject().shouldBuildVST3().getValue()))
  265. makefileExtraLinkerFlags.add ("-Wl,--no-undefined");
  266. if (supportsAAX() && getProject().shouldBuildAAX().getValue())
  267. addAAXFoldersToPath();
  268. // Note: RTAS paths are platform-dependent, impl -> addPlatformSpecificSettingsForProjectType
  269. }
  270. void ProjectExporter::addVSTFolderToPath (bool isVST3)
  271. {
  272. const String vstFolder (getVSTPathValue (isVST3).toString());
  273. if (vstFolder.isNotEmpty())
  274. addToExtraSearchPaths (RelativePath (vstFolder, RelativePath::projectFolder), 0);
  275. }
  276. void ProjectExporter::addAAXFoldersToPath()
  277. {
  278. const String aaxFolder = getAAXPathValue().toString();
  279. if (aaxFolder.isNotEmpty())
  280. {
  281. const RelativePath aaxFolderPath (getAAXPathValue().toString(), RelativePath::projectFolder);
  282. addToExtraSearchPaths (aaxFolderPath);
  283. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces"));
  284. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces").getChildFile ("ACF"));
  285. }
  286. }
  287. //==============================================================================
  288. StringPairArray ProjectExporter::getAllPreprocessorDefs (const ProjectExporter::BuildConfiguration& config) const
  289. {
  290. StringPairArray defs (mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  291. parsePreprocessorDefs (getExporterPreprocessorDefsString())));
  292. addDefaultPreprocessorDefs (defs);
  293. return defs;
  294. }
  295. StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  296. {
  297. StringPairArray defs (mergePreprocessorDefs (project.getPreprocessorDefs(),
  298. parsePreprocessorDefs (getExporterPreprocessorDefsString())));
  299. addDefaultPreprocessorDefs (defs);
  300. return defs;
  301. }
  302. void ProjectExporter::addDefaultPreprocessorDefs (StringPairArray& defs) const
  303. {
  304. defs.set (getExporterIdentifierMacro(), "1");
  305. defs.set ("JUCE_APP_VERSION", project.getVersionString());
  306. defs.set ("JUCE_APP_VERSION_HEX", project.getVersionAsHex());
  307. }
  308. String ProjectExporter::replacePreprocessorTokens (const ProjectExporter::BuildConfiguration& config, const String& sourceString) const
  309. {
  310. return replacePreprocessorDefs (getAllPreprocessorDefs (config), sourceString);
  311. }
  312. void ProjectExporter::copyMainGroupFromProject()
  313. {
  314. jassert (itemGroups.size() == 0);
  315. itemGroups.add (project.getMainGroup().createCopy());
  316. }
  317. Project::Item& ProjectExporter::getModulesGroup()
  318. {
  319. if (modulesGroup == nullptr)
  320. {
  321. jassert (itemGroups.size() > 0); // must call copyMainGroupFromProject before this.
  322. itemGroups.add (Project::Item::createGroup (project, "Juce Modules", "__modulesgroup__", true));
  323. modulesGroup = &(itemGroups.getReference (itemGroups.size() - 1));
  324. }
  325. return *modulesGroup;
  326. }
  327. void ProjectExporter::addToExtraSearchPaths (const RelativePath& pathFromProjectFolder, int index)
  328. {
  329. RelativePath localPath (rebaseFromProjectFolderToBuildTarget (pathFromProjectFolder));
  330. const String path (isVisualStudio() ? localPath.toWindowsStyle() : localPath.toUnixStyle());
  331. if (! extraSearchPaths.contains (path))
  332. extraSearchPaths.insert (index, path);
  333. }
  334. Value ProjectExporter::getPathForModuleValue (const String& moduleID)
  335. {
  336. UndoManager* um = project.getUndoManagerFor (settings);
  337. ValueTree paths (settings.getOrCreateChildWithName (Ids::MODULEPATHS, um));
  338. ValueTree m (paths.getChildWithProperty (Ids::ID, moduleID));
  339. if (! m.isValid())
  340. {
  341. m = ValueTree (Ids::MODULEPATH);
  342. m.setProperty (Ids::ID, moduleID, um);
  343. paths.addChild (m, -1, um);
  344. }
  345. return m.getPropertyAsValue (Ids::path, um);
  346. }
  347. String ProjectExporter::getPathForModuleString (const String& moduleID) const
  348. {
  349. return settings.getChildWithName (Ids::MODULEPATHS)
  350. .getChildWithProperty (Ids::ID, moduleID) [Ids::path].toString();
  351. }
  352. void ProjectExporter::removePathForModule (const String& moduleID)
  353. {
  354. ValueTree paths (settings.getChildWithName (Ids::MODULEPATHS));
  355. ValueTree m (paths.getChildWithProperty (Ids::ID, moduleID));
  356. paths.removeChild (m, project.getUndoManagerFor (settings));
  357. }
  358. RelativePath ProjectExporter::getModuleFolderRelativeToProject (const String& moduleID) const
  359. {
  360. if (project.getModules().shouldCopyModuleFilesLocally (moduleID).getValue())
  361. return RelativePath (project.getRelativePathForFile (project.getLocalModuleFolder (moduleID)),
  362. RelativePath::projectFolder);
  363. String path (getPathForModuleString (moduleID));
  364. if (path.isEmpty())
  365. return getLegacyModulePath (moduleID).getChildFile (moduleID);
  366. return RelativePath (path, RelativePath::projectFolder).getChildFile (moduleID);
  367. }
  368. String ProjectExporter::getLegacyModulePath() const
  369. {
  370. return getSettingString ("juceFolder");
  371. }
  372. RelativePath ProjectExporter::getLegacyModulePath (const String& moduleID) const
  373. {
  374. if (project.getModules().state.getChildWithProperty (Ids::ID, moduleID) ["useLocalCopy"])
  375. return RelativePath (project.getRelativePathForFile (project.getGeneratedCodeFolder()
  376. .getChildFile ("modules")
  377. .getChildFile (moduleID)), RelativePath::projectFolder);
  378. String oldJucePath (getLegacyModulePath());
  379. if (oldJucePath.isEmpty())
  380. return RelativePath();
  381. RelativePath p (oldJucePath, RelativePath::projectFolder);
  382. if (p.getFileName() != "modules")
  383. p = p.getChildFile ("modules");
  384. return p.getChildFile (moduleID);
  385. }
  386. void ProjectExporter::updateOldModulePaths()
  387. {
  388. String oldPath (getLegacyModulePath());
  389. if (oldPath.isNotEmpty())
  390. {
  391. for (int i = project.getModules().getNumModules(); --i >= 0;)
  392. {
  393. String modID (project.getModules().getModuleID(i));
  394. getPathForModuleValue (modID) = getLegacyModulePath (modID).getParentDirectory().toUnixStyle();
  395. }
  396. settings.removeProperty ("juceFolder", nullptr);
  397. }
  398. }
  399. static bool areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  400. {
  401. return (p1.isVisualStudio() && p2.isVisualStudio())
  402. || (p1.isXcode() && p2.isXcode())
  403. || (p1.isMakefile() && p2.isMakefile())
  404. || (p1.isAndroid() && p2.isAndroid())
  405. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  406. }
  407. void ProjectExporter::createDefaultModulePaths()
  408. {
  409. for (Project::ExporterIterator exporter (project); exporter.next();)
  410. {
  411. if (areCompatibleExporters (*this, *exporter))
  412. {
  413. for (int i = project.getModules().getNumModules(); --i >= 0;)
  414. {
  415. String modID (project.getModules().getModuleID(i));
  416. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID).getValue();
  417. }
  418. return;
  419. }
  420. }
  421. for (Project::ExporterIterator exporter (project); exporter.next();)
  422. {
  423. if (exporter->canLaunchProject())
  424. {
  425. for (int i = project.getModules().getNumModules(); --i >= 0;)
  426. {
  427. String modID (project.getModules().getModuleID(i));
  428. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID).getValue();
  429. }
  430. return;
  431. }
  432. }
  433. for (int i = project.getModules().getNumModules(); --i >= 0;)
  434. {
  435. String modID (project.getModules().getModuleID(i));
  436. getPathForModuleValue (modID) = "../../juce";
  437. }
  438. }
  439. //==============================================================================
  440. ValueTree ProjectExporter::getConfigurations() const
  441. {
  442. return settings.getChildWithName (Ids::CONFIGURATIONS);
  443. }
  444. int ProjectExporter::getNumConfigurations() const
  445. {
  446. return getConfigurations().getNumChildren();
  447. }
  448. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  449. {
  450. return createBuildConfig (getConfigurations().getChild (index));
  451. }
  452. bool ProjectExporter::hasConfigurationNamed (const String& nameToFind) const
  453. {
  454. const ValueTree configs (getConfigurations());
  455. for (int i = configs.getNumChildren(); --i >= 0;)
  456. if (configs.getChild(i) [Ids::name].toString() == nameToFind)
  457. return true;
  458. return false;
  459. }
  460. String ProjectExporter::getUniqueConfigName (String nm) const
  461. {
  462. String nameRoot (nm);
  463. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  464. nameRoot = nameRoot.dropLastCharacters (1);
  465. nameRoot = nameRoot.trim();
  466. int suffix = 2;
  467. while (hasConfigurationNamed (name))
  468. nm = nameRoot + " " + String (suffix++);
  469. return nm;
  470. }
  471. void ProjectExporter::addNewConfiguration (const BuildConfiguration* configToCopy)
  472. {
  473. const String configName (getUniqueConfigName (configToCopy != nullptr ? configToCopy->config [Ids::name].toString()
  474. : "New Build Configuration"));
  475. ValueTree configs (getConfigurations());
  476. if (! configs.isValid())
  477. {
  478. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  479. configs = getConfigurations();
  480. }
  481. ValueTree newConfig (Ids::CONFIGURATION);
  482. if (configToCopy != nullptr)
  483. newConfig = configToCopy->config.createCopy();
  484. newConfig.setProperty (Ids::name, configName, 0);
  485. configs.addChild (newConfig, -1, project.getUndoManagerFor (configs));
  486. }
  487. void ProjectExporter::BuildConfiguration::removeFromExporter()
  488. {
  489. ValueTree configs (config.getParent());
  490. configs.removeChild (config, project.getUndoManagerFor (configs));
  491. }
  492. void ProjectExporter::createDefaultConfigs()
  493. {
  494. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  495. for (int i = 0; i < 2; ++i)
  496. {
  497. addNewConfiguration (nullptr);
  498. BuildConfiguration::Ptr config (getConfiguration (i));
  499. const bool debugConfig = i == 0;
  500. config->getNameValue() = debugConfig ? "Debug" : "Release";
  501. config->isDebugValue() = debugConfig;
  502. config->getOptimisationLevel() = config->getDefaultOptimisationLevel();
  503. config->getTargetBinaryName() = project.getProjectFilenameRoot();
  504. }
  505. }
  506. Drawable* ProjectExporter::getBigIcon() const
  507. {
  508. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  509. }
  510. Drawable* ProjectExporter::getSmallIcon() const
  511. {
  512. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  513. }
  514. Image ProjectExporter::getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const
  515. {
  516. Drawable* im = nullptr;
  517. ScopedPointer<Drawable> im1 (getSmallIcon());
  518. ScopedPointer<Drawable> im2 (getBigIcon());
  519. if (im1 != nullptr && im2 != nullptr)
  520. {
  521. if (im1->getWidth() >= size && im2->getWidth() >= size)
  522. im = im1->getWidth() < im2->getWidth() ? im1 : im2;
  523. else if (im1->getWidth() >= size)
  524. im = im1;
  525. else if (im2->getWidth() >= size)
  526. im = im2;
  527. }
  528. else
  529. {
  530. im = im1 != nullptr ? im1 : im2;
  531. }
  532. if (im == nullptr)
  533. return Image();
  534. if (returnNullIfNothingBigEnough && im->getWidth() < size && im->getHeight() < size)
  535. return Image();
  536. return rescaleImageForIcon (*im, size);
  537. }
  538. Image ProjectExporter::rescaleImageForIcon (Drawable& d, const int size)
  539. {
  540. if (DrawableImage* drawableImage = dynamic_cast<DrawableImage*> (&d))
  541. {
  542. Image im = SoftwareImageType().convert (drawableImage->getImage());
  543. if (size == im.getWidth() && size == im.getHeight())
  544. return im;
  545. // (scale it down in stages for better resampling)
  546. while (im.getWidth() > 2 * size && im.getHeight() > 2 * size)
  547. im = im.rescaled (im.getWidth() / 2,
  548. im.getHeight() / 2);
  549. Image newIm (Image::ARGB, size, size, true, SoftwareImageType());
  550. Graphics g (newIm);
  551. g.drawImageWithin (im, 0, 0, size, size,
  552. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  553. return newIm;
  554. }
  555. Image im (Image::ARGB, size, size, true, SoftwareImageType());
  556. Graphics g (im);
  557. d.drawWithin (g, im.getBounds().toFloat(), RectanglePlacement::centred, 1.0f);
  558. return im;
  559. }
  560. //==============================================================================
  561. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  562. : index (-1), exporter (e)
  563. {
  564. }
  565. bool ProjectExporter::ConfigIterator::next()
  566. {
  567. if (++index >= exporter.getNumConfigurations())
  568. return false;
  569. config = exporter.getConfiguration (index);
  570. return true;
  571. }
  572. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  573. : index (-1), exporter (exporter_)
  574. {
  575. }
  576. bool ProjectExporter::ConstConfigIterator::next()
  577. {
  578. if (++index >= exporter.getNumConfigurations())
  579. return false;
  580. config = exporter.getConfiguration (index);
  581. return true;
  582. }
  583. //==============================================================================
  584. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  585. : config (configNode), project (p), exporter (e)
  586. {
  587. }
  588. ProjectExporter::BuildConfiguration::~BuildConfiguration()
  589. {
  590. }
  591. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  592. {
  593. switch (getOptimisationLevelInt())
  594. {
  595. case gccO0: return "0";
  596. case gccO1: return "1";
  597. case gccO2: return "2";
  598. case gccO3: return "3";
  599. case gccOs: return "s";
  600. case gccOfast: return "fast";
  601. default: break;
  602. }
  603. return "0";
  604. }
  605. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  606. {
  607. static const char* optimisationLevels[] = { "-O0 (no optimisation)",
  608. "-Os (minimise code size)",
  609. "-O1 (fast)",
  610. "-O2 (faster)",
  611. "-O3 (fastest with safe optimisations)",
  612. "-Ofast (uses aggressive optimisations)",
  613. nullptr };
  614. static const int optimisationLevelValues[] = { gccO0,
  615. gccOs,
  616. gccO1,
  617. gccO2,
  618. gccO3,
  619. gccOfast,
  620. 0 };
  621. props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation",
  622. StringArray (optimisationLevels),
  623. Array<var> (optimisationLevelValues)),
  624. "The optimisation level for this configuration");
  625. }
  626. void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
  627. {
  628. if (exporter.supportsUserDefinedConfigurations())
  629. props.add (new TextPropertyComponent (getNameValue(), "Name", 96, false),
  630. "The name of this configuration.");
  631. props.add (new BooleanPropertyComponent (isDebugValue(), "Debug mode", "Debugging enabled"),
  632. "If enabled, this means that the configuration should be built with debug symbols.");
  633. props.add (new TextPropertyComponent (getTargetBinaryName(), "Binary name", 256, false),
  634. "The filename to use for the destination binary executable file. If you don't add a suffix to this name, "
  635. "a suitable platform-specific suffix will be added automatically.");
  636. props.add (new TextPropertyComponent (getTargetBinaryRelativePath(), "Binary location", 1024, false),
  637. "The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed "
  638. "in its default location in the build folder.");
  639. props.addSearchPathProperty (getHeaderSearchPathValue(), "Header search paths", "Extra header search paths.");
  640. props.addSearchPathProperty (getLibrarySearchPathValue(), "Extra library search paths", "Extra library search paths.");
  641. props.add (new TextPropertyComponent (getBuildConfigPreprocessorDefs(), "Preprocessor definitions", 32768, true),
  642. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  643. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  644. createConfigProperties (props);
  645. props.add (new TextPropertyComponent (getUserNotes(), "Notes", 32768, true),
  646. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  647. }
  648. StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() const
  649. {
  650. return mergePreprocessorDefs (project.getPreprocessorDefs(),
  651. parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  652. }
  653. StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const
  654. {
  655. return getSearchPathsFromString (getHeaderSearchPathString());
  656. }
  657. StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const
  658. {
  659. return getSearchPathsFromString (getLibrarySearchPathString());
  660. }
  661. String ProjectExporter::BuildConfiguration::getGCCLibraryPathFlags() const
  662. {
  663. String s;
  664. const StringArray libraryPaths (getLibrarySearchPaths());
  665. for (int i = 0; i < libraryPaths.size(); ++i)
  666. s << " -L" << escapeSpaces (libraryPaths[i]);
  667. return s;
  668. }
  669. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  670. {
  671. StringArray libraries;
  672. libraries.addTokens (getExternalLibrariesString(), ";\n", "\"'");
  673. libraries.removeEmptyStrings (true);
  674. if (libraries.size() != 0)
  675. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  676. return String::empty;
  677. }