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.

749 lines
30KB

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