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.

702 lines
27KB

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