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.

757 lines
31KB

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