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.

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