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.

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