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.

1392 lines
60KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  20. #include "jucer_ProjectExporter.h"
  21. #include "jucer_ProjectSaver.h"
  22. //==============================================================================
  23. class MSVCProjectExporterBase : public ProjectExporter
  24. {
  25. public:
  26. MSVCProjectExporterBase (Project& project_, const ValueTree& settings_, const char* const folderName)
  27. : ProjectExporter (project_, settings_)
  28. {
  29. if (getTargetLocationString().isEmpty())
  30. getTargetLocationValue() = getDefaultBuildsRootFolder() + folderName;
  31. if ((int) getLibraryType().getValue() <= 0)
  32. getLibraryType() = 1;
  33. projectGUID = createGUID (project.getProjectUID());
  34. updateOldSettings();
  35. }
  36. //==============================================================================
  37. bool isPossibleForCurrentProject() { return true; }
  38. bool usesMMFiles() const { return false; }
  39. bool isVisualStudio() const { return true; }
  40. bool canCopeWithDuplicateFiles() { return false; }
  41. void createPropertyEditors (PropertyListBuilder& props)
  42. {
  43. ProjectExporter::createPropertyEditors (props);
  44. if (projectType.isLibrary())
  45. {
  46. const char* const libTypes[] = { "Static Library (.lib)", "Dynamic Library (.dll)", 0 };
  47. const int libTypeValues[] = { 1, 2, 0 };
  48. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type",
  49. StringArray (libTypes), Array<var> (libTypeValues)));
  50. }
  51. }
  52. protected:
  53. String projectGUID;
  54. mutable File rcFile, iconFile;
  55. File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  56. Value getLibraryType() { return getSetting (Ids::libraryType); }
  57. bool isLibraryDLL() const { return msvcIsDLL || (projectType.isLibrary() && (int) settings [Ids::libraryType] == 2); }
  58. void updateOldSettings()
  59. {
  60. {
  61. const String oldStylePrebuildCommand (getSetting (Ids::prebuildCommand).toString());
  62. settings.removeProperty (Ids::prebuildCommand, nullptr);
  63. if (oldStylePrebuildCommand.isNotEmpty())
  64. for (ConfigIterator config (*this); config.next();)
  65. dynamic_cast <MSVCBuildConfiguration&> (*config).getPrebuildCommand() = oldStylePrebuildCommand;
  66. }
  67. {
  68. const String oldStyleLibName (getSetting ("libraryName_Debug").toString());
  69. settings.removeProperty ("libraryName_Debug", nullptr);
  70. if (oldStyleLibName.isNotEmpty())
  71. for (ConfigIterator config (*this); config.next();)
  72. if (config->isDebug())
  73. config->getTargetBinaryName() = oldStyleLibName;
  74. }
  75. {
  76. const String oldStyleLibName (getSetting ("libraryName_Release").toString());
  77. settings.removeProperty ("libraryName_Release", nullptr);
  78. if (oldStyleLibName.isNotEmpty())
  79. for (ConfigIterator config (*this); config.next();)
  80. if (! config->isDebug())
  81. config->getTargetBinaryName() = oldStyleLibName;
  82. }
  83. }
  84. //==============================================================================
  85. class MSVCBuildConfiguration : public BuildConfiguration
  86. {
  87. public:
  88. MSVCBuildConfiguration (Project& project, const ValueTree& settings)
  89. : BuildConfiguration (project, settings)
  90. {
  91. if (getWarningLevel() == 0)
  92. getWarningLevelValue() = 4;
  93. if (shouldGenerateManifestValue().getValue().isVoid())
  94. shouldGenerateManifestValue() = var (true);
  95. }
  96. Value getWarningLevelValue() { return getValue (Ids::winWarningLevel); }
  97. int getWarningLevel() const { return config [Ids::winWarningLevel]; }
  98. Value getPrebuildCommand() { return getValue (Ids::prebuildCommand); }
  99. String getPrebuildCommandString() const { return config [Ids::prebuildCommand]; }
  100. Value getPostbuildCommand() { return getValue (Ids::postbuildCommand); }
  101. String getPostbuildCommandString() const { return config [Ids::postbuildCommand]; }
  102. Value shouldGenerateManifestValue() { return getValue (Ids::generateManifest); }
  103. bool shouldGenerateManifest() const { return config [Ids::generateManifest]; }
  104. String getOutputFilename (const String& suffix, bool forceSuffix) const
  105. {
  106. const String target (File::createLegalFileName (getTargetBinaryNameString().trim()));
  107. if (forceSuffix || ! target.containsChar ('.'))
  108. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  109. return target;
  110. }
  111. void createPropertyEditors (PropertyListBuilder& props)
  112. {
  113. createBasicPropertyEditors (props);
  114. const char* const warningLevelNames[] = { "Low", "Medium", "High", nullptr };
  115. const int warningLevels[] = { 2, 3, 4, 0 };
  116. props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
  117. StringArray (warningLevelNames), Array<var> (warningLevels)));
  118. props.add (new TextPropertyComponent (getPrebuildCommand(), "Pre-build Command", 2048, false));
  119. props.add (new TextPropertyComponent (getPostbuildCommand(), "Post-build Command", 2048, false));
  120. props.add (new BooleanPropertyComponent (shouldGenerateManifestValue(), "Manifest", "Generate Manifest"));
  121. }
  122. };
  123. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  124. {
  125. return new MSVCBuildConfiguration (project, settings);
  126. }
  127. static int getWarningLevel (const BuildConfiguration& config)
  128. {
  129. return dynamic_cast <const MSVCBuildConfiguration&> (config).getWarningLevel();
  130. }
  131. //==============================================================================
  132. String getIntermediatesPath (const BuildConfiguration& config) const
  133. {
  134. return prependDot (File::createLegalFileName (config.getName().trim()));
  135. }
  136. String getConfigTargetPath (const BuildConfiguration& config) const
  137. {
  138. const String binaryPath (config.getTargetBinaryRelativePathString().trim());
  139. if (binaryPath.isEmpty())
  140. return getIntermediatesPath (config);
  141. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  142. if (binaryRelPath.isAbsolute())
  143. return binaryRelPath.toWindowsStyle();
  144. return prependDot (binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  145. .toWindowsStyle());
  146. }
  147. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  148. {
  149. StringPairArray defines (msvcExtraPreprocessorDefs);
  150. defines.set ("WIN32", "");
  151. defines.set ("_WINDOWS", "");
  152. if (config.isDebug())
  153. {
  154. defines.set ("DEBUG", "");
  155. defines.set ("_DEBUG", "");
  156. }
  157. else
  158. {
  159. defines.set ("NDEBUG", "");
  160. }
  161. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  162. StringArray result;
  163. for (int i = 0; i < defines.size(); ++i)
  164. {
  165. String def (defines.getAllKeys()[i]);
  166. const String value (defines.getAllValues()[i]);
  167. if (value.isNotEmpty())
  168. def << "=" << value;
  169. result.add (def);
  170. }
  171. return result.joinIntoString (joinString);
  172. }
  173. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  174. {
  175. StringArray searchPaths (extraSearchPaths);
  176. searchPaths.addArray (config.getHeaderSearchPaths());
  177. searchPaths.removeDuplicates (false);
  178. return searchPaths;
  179. }
  180. virtual String createConfigName (const BuildConfiguration& config) const
  181. {
  182. return config.getName() + "|Win32";
  183. }
  184. //==============================================================================
  185. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString, const File& vcProject) const
  186. {
  187. if (commentString.isNotEmpty())
  188. commentString += newLine;
  189. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  190. << commentString
  191. << "Project(\"" << createGUID (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  192. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  193. << "EndProject" << newLine
  194. << "Global" << newLine
  195. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  196. for (ConstConfigIterator i (*this); i.next();)
  197. {
  198. const String configName (createConfigName (*i));
  199. out << "\t\t" << configName << " = " << configName << newLine;
  200. }
  201. out << "\tEndGlobalSection" << newLine
  202. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  203. for (ConstConfigIterator i (*this); i.next();)
  204. {
  205. const String configName (createConfigName (*i));
  206. out << "\t\t" << projectGUID << "." << configName << ".ActiveCfg = " << configName << newLine;
  207. out << "\t\t" << projectGUID << "." << configName << ".Build.0 = " << configName << newLine;
  208. }
  209. out << "\tEndGlobalSection" << newLine
  210. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  211. << "\t\tHideSolutionNode = FALSE" << newLine
  212. << "\tEndGlobalSection" << newLine
  213. << "EndGlobal" << newLine;
  214. }
  215. //==============================================================================
  216. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  217. {
  218. const int maskStride = (w / 8 + 3) & ~3;
  219. out.writeInt (40); // bitmapinfoheader size
  220. out.writeInt (w);
  221. out.writeInt (h * 2);
  222. out.writeShort (1); // planes
  223. out.writeShort (32); // bits
  224. out.writeInt (0); // compression
  225. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  226. out.writeInt (0); // x pixels per meter
  227. out.writeInt (0); // y pixels per meter
  228. out.writeInt (0); // clr used
  229. out.writeInt (0); // clr important
  230. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  231. const int alphaThreshold = 5;
  232. int y;
  233. for (y = h; --y >= 0;)
  234. {
  235. for (int x = 0; x < w; ++x)
  236. {
  237. const Colour pixel (bitmap.getPixelColour (x, y));
  238. if (pixel.getAlpha() <= alphaThreshold)
  239. {
  240. out.writeInt (0);
  241. }
  242. else
  243. {
  244. out.writeByte ((char) pixel.getBlue());
  245. out.writeByte ((char) pixel.getGreen());
  246. out.writeByte ((char) pixel.getRed());
  247. out.writeByte ((char) pixel.getAlpha());
  248. }
  249. }
  250. }
  251. for (y = h; --y >= 0;)
  252. {
  253. int mask = 0, count = 0;
  254. for (int x = 0; x < w; ++x)
  255. {
  256. const Colour pixel (bitmap.getPixelColour (x, y));
  257. mask <<= 1;
  258. if (pixel.getAlpha() <= alphaThreshold)
  259. mask |= 1;
  260. if (++count == 8)
  261. {
  262. out.writeByte ((char) mask);
  263. count = 0;
  264. mask = 0;
  265. }
  266. }
  267. if (mask != 0)
  268. out.writeByte ((char) mask);
  269. for (int i = maskStride - w / 8; --i >= 0;)
  270. out.writeByte (0);
  271. }
  272. }
  273. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  274. {
  275. out.writeShort (0); // reserved
  276. out.writeShort (1); // .ico tag
  277. out.writeShort ((short) images.size());
  278. MemoryOutputStream dataBlock;
  279. const int imageDirEntrySize = 16;
  280. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  281. for (int i = 0; i < images.size(); ++i)
  282. {
  283. const size_t oldDataSize = dataBlock.getDataSize();
  284. const Image& image = images.getReference (i);
  285. const int w = image.getWidth();
  286. const int h = image.getHeight();
  287. if (w >= 256 || h >= 256)
  288. {
  289. PNGImageFormat pngFormat;
  290. pngFormat.writeImageToStream (image, dataBlock);
  291. }
  292. else
  293. {
  294. writeBMPImage (image, w, h, dataBlock);
  295. }
  296. out.writeByte ((char) w);
  297. out.writeByte ((char) h);
  298. out.writeByte (0);
  299. out.writeByte (0);
  300. out.writeShort (1); // colour planes
  301. out.writeShort (32); // bits per pixel
  302. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  303. out.writeInt (dataBlockStart + oldDataSize);
  304. }
  305. jassert (out.getPosition() == dataBlockStart);
  306. out << dataBlock;
  307. }
  308. bool hasResourceFile() const
  309. {
  310. return ! projectType.isLibrary();
  311. }
  312. void createResourcesAndIcon() const
  313. {
  314. if (hasResourceFile())
  315. {
  316. Array<Image> images;
  317. const int sizes[] = { 16, 32, 48, 256 };
  318. for (int i = 0; i < numElementsInArray (sizes); ++i)
  319. {
  320. Image im (getBestIconForSize (sizes[i], true));
  321. if (im.isValid())
  322. images.add (im);
  323. }
  324. if (images.size() > 0)
  325. {
  326. iconFile = getTargetFolder().getChildFile ("icon.ico");
  327. MemoryOutputStream mo;
  328. writeIconFile (images, mo);
  329. overwriteFileIfDifferentOrThrow (iconFile, mo);
  330. }
  331. createRCFile();
  332. }
  333. }
  334. void createRCFile() const
  335. {
  336. rcFile = getTargetFolder().getChildFile ("resources.rc");
  337. const String version (project.getVersionString());
  338. MemoryOutputStream mo;
  339. mo << "#undef WIN32_LEAN_AND_MEAN" << newLine
  340. << "#define WIN32_LEAN_AND_MEAN" << newLine
  341. << "#include <windows.h>" << newLine
  342. << newLine
  343. << "VS_VERSION_INFO VERSIONINFO" << newLine
  344. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  345. << "BEGIN" << newLine
  346. << " BLOCK \"StringFileInfo\"" << newLine
  347. << " BEGIN" << newLine
  348. << " BLOCK \"040904E4\"" << newLine
  349. << " BEGIN" << newLine;
  350. writeRCValue (mo, "CompanyName", project.getCompanyName().toString());
  351. writeRCValue (mo, "FileDescription", project.getProjectName().toString());
  352. writeRCValue (mo, "FileVersion", version);
  353. writeRCValue (mo, "ProductName", project.getProjectName().toString());
  354. writeRCValue (mo, "ProductVersion", version);
  355. mo << " END" << newLine
  356. << " END" << newLine
  357. << newLine
  358. << " BLOCK \"VarFileInfo\"" << newLine
  359. << " BEGIN" << newLine
  360. << " VALUE \"Translation\", 0x409, 65001" << newLine
  361. << " END" << newLine
  362. << "END" << newLine;
  363. if (iconFile != File::nonexistent)
  364. mo << newLine
  365. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  366. overwriteFileIfDifferentOrThrow (rcFile, mo);
  367. }
  368. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  369. {
  370. if (value.isNotEmpty())
  371. mo << " VALUE \"" << name << "\", \""
  372. << CodeHelpers::addEscapeChars (value) << "\\0\"" << newLine;
  373. }
  374. static String getCommaSeparatedVersionNumber (const String& version)
  375. {
  376. StringArray versionParts;
  377. versionParts.addTokens (version, ",.", "");
  378. versionParts.trim();
  379. versionParts.removeEmptyStrings();
  380. while (versionParts.size() < 4)
  381. versionParts.add ("0");
  382. return versionParts.joinIntoString (",");
  383. }
  384. static String prependDot (const String& filename)
  385. {
  386. return FileHelpers::isAbsolutePath (filename) ? filename
  387. : (".\\" + filename);
  388. }
  389. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase);
  390. };
  391. //==============================================================================
  392. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  393. {
  394. public:
  395. //==============================================================================
  396. MSVCProjectExporterVC2008 (Project& project_, const ValueTree& settings_, const char* folderName = "VisualStudio2008")
  397. : MSVCProjectExporterBase (project_, settings_, folderName)
  398. {
  399. name = getName();
  400. }
  401. static const char* getName() { return "Visual Studio 2008"; }
  402. static const char* getValueTreeTypeName() { return "VS2008"; }
  403. int getVisualStudioVersion() const { return 9; }
  404. void launchProject() { getSLNFile().startAsProcess(); }
  405. int getLaunchPreferenceOrderForCurrentOS()
  406. {
  407. #if JUCE_WINDOWS
  408. return 4;
  409. #else
  410. return 0;
  411. #endif
  412. }
  413. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  414. {
  415. if (settings.hasType (getValueTreeTypeName()))
  416. return new MSVCProjectExporterVC2008 (project, settings);
  417. return nullptr;
  418. }
  419. //==============================================================================
  420. void create (const OwnedArray<LibraryModule>&) const
  421. {
  422. createResourcesAndIcon();
  423. if (hasResourceFile())
  424. {
  425. for (int i = 0; i < groups.size(); ++i)
  426. {
  427. Project::Item& group = groups.getReference(i);
  428. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  429. {
  430. if (iconFile != File::nonexistent)
  431. {
  432. group.addFile (iconFile, -1, true);
  433. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  434. }
  435. group.addFile (rcFile, -1, true);
  436. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  437. break;
  438. }
  439. }
  440. }
  441. {
  442. XmlElement projectXml ("VisualStudioProject");
  443. fillInProjectXml (projectXml);
  444. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  445. }
  446. {
  447. MemoryOutputStream mo;
  448. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  449. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  450. }
  451. }
  452. protected:
  453. virtual String getProjectVersionString() const { return "9.00"; }
  454. virtual String getSolutionVersionString() const { return "10.00" + newLine + "# Visual C++ Express 2008"; }
  455. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  456. File getSLNFile() const { return getProjectFile (".sln"); }
  457. //==============================================================================
  458. void fillInProjectXml (XmlElement& projectXml) const
  459. {
  460. projectXml.setAttribute ("ProjectType", "Visual C++");
  461. projectXml.setAttribute ("Version", getProjectVersionString());
  462. projectXml.setAttribute ("Name", projectName);
  463. projectXml.setAttribute ("ProjectGUID", projectGUID);
  464. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  465. {
  466. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  467. XmlElement* platform = platforms->createNewChildElement ("Platform");
  468. platform->setAttribute ("Name", "Win32");
  469. }
  470. projectXml.createNewChildElement ("ToolFiles");
  471. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  472. projectXml.createNewChildElement ("References");
  473. createFiles (*projectXml.createNewChildElement ("Files"));
  474. projectXml.createNewChildElement ("Globals");
  475. }
  476. //==============================================================================
  477. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall) const
  478. {
  479. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  480. XmlElement* fileXml = parent.createNewChildElement ("File");
  481. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  482. if (excludeFromBuild || useStdcall)
  483. {
  484. for (ConstConfigIterator i (*this); i.next();)
  485. {
  486. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  487. fileConfig->setAttribute ("Name", createConfigName (*i));
  488. if (excludeFromBuild)
  489. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  490. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  491. if (useStdcall)
  492. tool->setAttribute ("CallingConvention", "2");
  493. }
  494. }
  495. }
  496. XmlElement* createGroup (const String& groupName, XmlElement& parent) const
  497. {
  498. XmlElement* filter = parent.createNewChildElement ("Filter");
  499. filter->setAttribute ("Name", groupName);
  500. return filter;
  501. }
  502. void addFiles (const Project::Item& projectItem, XmlElement& parent) const
  503. {
  504. if (projectItem.isGroup())
  505. {
  506. XmlElement* filter = createGroup (projectItem.getName(), parent);
  507. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  508. addFiles (projectItem.getChild(i), *filter);
  509. }
  510. else if (projectItem.shouldBeAddedToTargetProject())
  511. {
  512. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  513. addFile (path, parent,
  514. projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  515. shouldFileBeCompiledByDefault (path) && (bool) projectItem.shouldUseStdCall());
  516. }
  517. }
  518. void createFiles (XmlElement& files) const
  519. {
  520. for (int i = 0; i < groups.size(); ++i)
  521. if (groups.getReference(i).getNumChildren() > 0)
  522. addFiles (groups.getReference(i), files);
  523. }
  524. //==============================================================================
  525. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  526. {
  527. XmlElement* const e = parent.createNewChildElement ("Tool");
  528. e->setAttribute ("Name", toolName);
  529. return e;
  530. }
  531. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  532. {
  533. String binariesPath (getConfigTargetPath (config));
  534. String intermediatesPath (getIntermediatesPath (config));
  535. const bool isDebug = config.isDebug();
  536. xml.setAttribute ("Name", createConfigName (config));
  537. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (binariesPath));
  538. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (intermediatesPath));
  539. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isLibrary() ? "4" : "1"));
  540. xml.setAttribute ("UseOfMFC", "0");
  541. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  542. xml.setAttribute ("CharacterSet", "2");
  543. if (! isDebug)
  544. xml.setAttribute ("WholeProgramOptimization", "1");
  545. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  546. if (config.getPrebuildCommandString().isNotEmpty())
  547. {
  548. preBuildEvent->setAttribute ("Description", "Pre-build");
  549. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  550. }
  551. createToolElement (xml, "VCCustomBuildTool");
  552. createToolElement (xml, "VCXMLDataGeneratorTool");
  553. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  554. if (! projectType.isLibrary())
  555. {
  556. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  557. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  558. midl->setAttribute ("MkTypLibCompatible", "true");
  559. midl->setAttribute ("SuppressStartupBanner", "true");
  560. midl->setAttribute ("TargetEnvironment", "1");
  561. midl->setAttribute ("TypeLibraryName", FileHelpers::windowsStylePath (intermediatesPath + "/"
  562. + config.getOutputFilename (".tlb", true)));
  563. midl->setAttribute ("HeaderFileName", "");
  564. }
  565. {
  566. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  567. const int optimiseLevel = config.getOptimisationLevelInt();
  568. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "1" : "2"));
  569. if (isDebug)
  570. {
  571. compiler->setAttribute ("BufferSecurityCheck", "");
  572. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  573. }
  574. else
  575. {
  576. compiler->setAttribute ("InlineFunctionExpansion", "1");
  577. compiler->setAttribute ("StringPooling", "true");
  578. }
  579. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  580. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  581. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  582. : (isDebug ? 1 : 0)); // MT static
  583. compiler->setAttribute ("RuntimeTypeInfo", "true");
  584. compiler->setAttribute ("UsePrecompiledHeader", "0");
  585. compiler->setAttribute ("PrecompiledHeaderFile", FileHelpers::windowsStylePath (intermediatesPath + "/"
  586. + config.getOutputFilename (".pch", true)));
  587. compiler->setAttribute ("AssemblerListingLocation", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  588. compiler->setAttribute ("ObjectFile", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  589. compiler->setAttribute ("ProgramDataBaseFileName", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  590. compiler->setAttribute ("WarningLevel", String (getWarningLevel (config)));
  591. compiler->setAttribute ("SuppressStartupBanner", "true");
  592. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  593. if (extraFlags.isNotEmpty())
  594. compiler->setAttribute ("AdditionalOptions", extraFlags);
  595. }
  596. createToolElement (xml, "VCManagedResourceCompilerTool");
  597. {
  598. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  599. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  600. }
  601. createToolElement (xml, "VCPreLinkEventTool");
  602. if (! projectType.isLibrary())
  603. {
  604. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  605. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  606. linker->setAttribute ("SuppressStartupBanner", "true");
  607. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  608. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  609. linker->setAttribute ("ProgramDatabaseFile", FileHelpers::windowsStylePath (intermediatesPath + "/"
  610. + config.getOutputFilename (".pdb", true)));
  611. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  612. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  613. if (librarySearchPaths.size() > 0)
  614. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  615. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  616. if (! isDebug)
  617. {
  618. linker->setAttribute ("OptimizeReferences", "2");
  619. linker->setAttribute ("EnableCOMDATFolding", "2");
  620. }
  621. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  622. if (msvcDelayLoadedDLLs.isNotEmpty())
  623. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  624. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  625. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  626. String extraLinkerOptions (getExtraLinkerFlagsString());
  627. if (extraLinkerOptions.isNotEmpty())
  628. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  629. }
  630. else
  631. {
  632. if (isLibraryDLL())
  633. {
  634. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  635. String extraLinkerOptions (getExtraLinkerFlagsString());
  636. extraLinkerOptions << " /IMPLIB:" << FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (".lib", true));
  637. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  638. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  639. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  640. }
  641. else
  642. {
  643. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  644. librarian->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  645. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  646. }
  647. }
  648. createToolElement (xml, "VCALinkTool");
  649. createToolElement (xml, "VCManifestTool");
  650. createToolElement (xml, "VCXDCMakeTool");
  651. {
  652. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  653. bscMake->setAttribute ("SuppressStartupBanner", "true");
  654. bscMake->setAttribute ("OutputFile", FileHelpers::windowsStylePath (intermediatesPath + "/"
  655. + config.getOutputFilename (".bsc", true)));
  656. }
  657. createToolElement (xml, "VCFxCopTool");
  658. if (! projectType.isLibrary())
  659. createToolElement (xml, "VCAppVerifierTool");
  660. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  661. if (config.getPostbuildCommandString().isNotEmpty())
  662. {
  663. postBuildEvent->setAttribute ("Description", "Post-build");
  664. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  665. }
  666. }
  667. void createConfigs (XmlElement& xml) const
  668. {
  669. for (ConstConfigIterator config (*this); config.next();)
  670. createConfig (*xml.createNewChildElement ("Configuration"),
  671. dynamic_cast <const MSVCBuildConfiguration&> (*config));
  672. }
  673. //==============================================================================
  674. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  675. };
  676. //==============================================================================
  677. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  678. {
  679. public:
  680. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  681. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  682. {
  683. name = getName();
  684. }
  685. static const char* getName() { return "Visual Studio 2005"; }
  686. static const char* getValueTreeTypeName() { return "VS2005"; }
  687. int getVisualStudioVersion() const { return 8; }
  688. int getLaunchPreferenceOrderForCurrentOS()
  689. {
  690. #if JUCE_WINDOWS
  691. return 2;
  692. #else
  693. return 0;
  694. #endif
  695. }
  696. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  697. {
  698. if (settings.hasType (getValueTreeTypeName()))
  699. return new MSVCProjectExporterVC2005 (project, settings);
  700. return nullptr;
  701. }
  702. protected:
  703. String getProjectVersionString() const { return "8.00"; }
  704. String getSolutionVersionString() const { return "9.00" + newLine + "# Visual C++ Express 2005"; }
  705. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  706. };
  707. //==============================================================================
  708. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  709. {
  710. public:
  711. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  712. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  713. {
  714. name = getName();
  715. }
  716. static const char* getName() { return "Visual Studio 2010"; }
  717. static const char* getValueTreeTypeName() { return "VS2010"; }
  718. int getVisualStudioVersion() const { return 10; }
  719. int getLaunchPreferenceOrderForCurrentOS()
  720. {
  721. #if JUCE_WINDOWS
  722. return 3;
  723. #else
  724. return 0;
  725. #endif
  726. }
  727. void launchProject() { getSLNFile().startAsProcess(); }
  728. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  729. {
  730. if (settings.hasType (getValueTreeTypeName()))
  731. return new MSVCProjectExporterVC2010 (project, settings);
  732. return nullptr;
  733. }
  734. //==============================================================================
  735. void create (const OwnedArray<LibraryModule>&) const
  736. {
  737. createResourcesAndIcon();
  738. {
  739. XmlElement projectXml ("Project");
  740. fillInProjectXml (projectXml);
  741. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  742. }
  743. {
  744. XmlElement filtersXml ("Project");
  745. fillInFiltersXml (filtersXml);
  746. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  747. }
  748. {
  749. MemoryOutputStream mo;
  750. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  751. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  752. }
  753. }
  754. protected:
  755. //==============================================================================
  756. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  757. {
  758. public:
  759. VC2010BuildConfiguration (Project& project, const ValueTree& settings)
  760. : MSVCBuildConfiguration (project, settings)
  761. {
  762. if (getArchitectureType().toString().isEmpty())
  763. getArchitectureType() = get32BitArchName();
  764. }
  765. //==============================================================================
  766. static const char* get32BitArchName() { return "32-bit"; }
  767. static const char* get64BitArchName() { return "x64"; }
  768. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  769. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  770. //==============================================================================
  771. void createPropertyEditors (PropertyListBuilder& props)
  772. {
  773. MSVCBuildConfiguration::createPropertyEditors (props);
  774. const char* const archTypes[] = { get32BitArchName(), get64BitArchName(), nullptr };
  775. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  776. StringArray (archTypes), Array<var> (archTypes)));
  777. }
  778. };
  779. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  780. {
  781. return new VC2010BuildConfiguration (project, settings);
  782. }
  783. static bool is64Bit (const BuildConfiguration& config)
  784. {
  785. return dynamic_cast <const VC2010BuildConfiguration&> (config).is64Bit();
  786. }
  787. //==============================================================================
  788. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  789. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  790. File getSLNFile() const { return getProjectFile (".sln"); }
  791. String createConfigName (const BuildConfiguration& config) const
  792. {
  793. return config.getName() + (is64Bit (config) ? "|x64"
  794. : "|Win32");
  795. }
  796. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  797. {
  798. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  799. }
  800. //==============================================================================
  801. void fillInProjectXml (XmlElement& projectXml) const
  802. {
  803. projectXml.setAttribute ("DefaultTargets", "Build");
  804. projectXml.setAttribute ("ToolsVersion", "4.0");
  805. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  806. {
  807. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  808. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  809. for (ConstConfigIterator config (*this); config.next();)
  810. {
  811. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  812. e->setAttribute ("Include", createConfigName (*config));
  813. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  814. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  815. }
  816. }
  817. {
  818. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  819. globals->setAttribute ("Label", "Globals");
  820. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  821. }
  822. {
  823. XmlElement* imports = projectXml.createNewChildElement ("Import");
  824. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  825. }
  826. for (ConstConfigIterator config (*this); config.next();)
  827. {
  828. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  829. setConditionAttribute (*e, *config);
  830. e->setAttribute ("Label", "Configuration");
  831. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  832. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  833. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  834. if (! config->isDebug())
  835. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  836. if (is64Bit (*config))
  837. e->createNewChildElement ("PlatformToolset")->addTextElement ("Windows7.1SDK");
  838. }
  839. {
  840. XmlElement* e = projectXml.createNewChildElement ("Import");
  841. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  842. }
  843. {
  844. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  845. e->setAttribute ("Label", "ExtensionSettings");
  846. }
  847. {
  848. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  849. e->setAttribute ("Label", "PropertySheets");
  850. XmlElement* p = e->createNewChildElement ("Import");
  851. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  852. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  853. p->setAttribute ("Label", "LocalAppDataPlatform");
  854. }
  855. {
  856. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  857. e->setAttribute ("Label", "UserMacros");
  858. }
  859. {
  860. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  861. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  862. for (ConstConfigIterator i (*this); i.next();)
  863. {
  864. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  865. {
  866. XmlElement* outdir = props->createNewChildElement ("OutDir");
  867. setConditionAttribute (*outdir, config);
  868. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  869. }
  870. {
  871. XmlElement* intdir = props->createNewChildElement ("IntDir");
  872. setConditionAttribute (*intdir, config);
  873. intdir->addTextElement (getConfigTargetPath (config) + "\\");
  874. }
  875. {
  876. XmlElement* name = props->createNewChildElement ("TargetName");
  877. setConditionAttribute (*name, config);
  878. name->addTextElement (config.getOutputFilename (String::empty, true));
  879. }
  880. {
  881. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  882. setConditionAttribute (*manifest, config);
  883. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  884. }
  885. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  886. if (librarySearchPaths.size() > 0)
  887. {
  888. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  889. setConditionAttribute (*libPath, config);
  890. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  891. }
  892. }
  893. }
  894. for (ConstConfigIterator i (*this); i.next();)
  895. {
  896. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  897. String binariesPath (getConfigTargetPath (config));
  898. String intermediatesPath (getIntermediatesPath (config));
  899. const bool isDebug = config.isDebug();
  900. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  901. setConditionAttribute (*group, config);
  902. {
  903. XmlElement* midl = group->createNewChildElement ("Midl");
  904. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  905. : "NDEBUG;%(PreprocessorDefinitions)");
  906. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  907. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  908. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  909. midl->createNewChildElement ("HeaderFileName");
  910. }
  911. {
  912. XmlElement* cl = group->createNewChildElement ("ClCompile");
  913. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  914. if (isDebug)
  915. cl->createNewChildElement ("DebugInformationFormat")->addTextElement (is64Bit (config) ? "ProgramDatabase"
  916. : "EditAndContinue");
  917. StringArray includePaths (getHeaderSearchPaths (config));
  918. includePaths.add ("%(AdditionalIncludeDirectories)");
  919. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  920. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  921. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  922. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  923. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  924. cl->createNewChildElement ("PrecompiledHeader");
  925. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  926. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  927. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  928. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (getWarningLevel (config)));
  929. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  930. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  931. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  932. if (extraFlags.isNotEmpty())
  933. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  934. }
  935. {
  936. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  937. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  938. : "NDEBUG;%(PreprocessorDefinitions)");
  939. }
  940. {
  941. XmlElement* link = group->createNewChildElement ("Link");
  942. link->createNewChildElement ("OutputFile")
  943. ->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  944. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  945. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  946. : "%(IgnoreSpecificDefaultLibraries)");
  947. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  948. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"
  949. + config.getOutputFilename (".pdb", true)));
  950. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  951. if (! is64Bit (config))
  952. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  953. if (! isDebug)
  954. {
  955. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  956. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  957. }
  958. String extraLinkerOptions (getExtraLinkerFlagsString());
  959. if (extraLinkerOptions.isNotEmpty())
  960. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  961. + " %(AdditionalOptions)");
  962. if (msvcDelayLoadedDLLs.isNotEmpty())
  963. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  964. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  965. link->createNewChildElement ("ModuleDefinitionFile")
  966. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  967. }
  968. {
  969. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  970. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  971. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath
  972. + "/" + config.getOutputFilename (".bsc", true)));
  973. }
  974. if (config.getPrebuildCommandString().isNotEmpty())
  975. group->createNewChildElement ("PreBuildEvent")
  976. ->createNewChildElement ("Command")
  977. ->addTextElement (config.getPrebuildCommandString());
  978. if (config.getPostbuildCommandString().isNotEmpty())
  979. group->createNewChildElement ("PostBuildEvent")
  980. ->createNewChildElement ("Command")
  981. ->addTextElement (config.getPostbuildCommandString());
  982. }
  983. {
  984. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  985. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  986. for (int i = 0; i < groups.size(); ++i)
  987. if (groups.getReference(i).getNumChildren() > 0)
  988. addFilesToCompile (groups.getReference(i), *cppFiles, *headerFiles);
  989. }
  990. if (iconFile != File::nonexistent)
  991. {
  992. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  993. XmlElement* e = iconGroup->createNewChildElement ("None");
  994. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  995. }
  996. if (hasResourceFile())
  997. {
  998. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  999. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1000. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1001. }
  1002. {
  1003. XmlElement* e = projectXml.createNewChildElement ("Import");
  1004. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1005. }
  1006. {
  1007. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1008. e->setAttribute ("Label", "ExtensionTargets");
  1009. }
  1010. }
  1011. String getProjectType() const
  1012. {
  1013. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1014. else if (isLibraryDLL()) return "DynamicLibrary";
  1015. else if (projectType.isLibrary()) return "StaticLibrary";
  1016. jassertfalse;
  1017. return String::empty;
  1018. }
  1019. //==============================================================================
  1020. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall) const
  1021. {
  1022. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1023. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1024. {
  1025. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1026. e->setAttribute ("Include", file.toWindowsStyle());
  1027. if (excludeFromBuild)
  1028. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1029. if (useStdcall)
  1030. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1031. }
  1032. else if (file.hasFileExtension (headerFileExtensions))
  1033. {
  1034. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1035. }
  1036. }
  1037. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers) const
  1038. {
  1039. if (projectItem.isGroup())
  1040. {
  1041. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1042. addFilesToCompile (projectItem.getChild(i), cpps, headers);
  1043. }
  1044. else
  1045. {
  1046. if (projectItem.shouldBeAddedToTargetProject())
  1047. {
  1048. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1049. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx")))
  1050. addFileToCompile (path, cpps, headers, ! projectItem.shouldBeCompiled(), projectItem.shouldUseStdCall());
  1051. }
  1052. }
  1053. }
  1054. //==============================================================================
  1055. void addFilterGroup (XmlElement& groups, const String& path) const
  1056. {
  1057. XmlElement* e = groups.createNewChildElement ("Filter");
  1058. e->setAttribute ("Include", path);
  1059. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1060. }
  1061. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers) const
  1062. {
  1063. XmlElement* e;
  1064. if (file.hasFileExtension (headerFileExtensions))
  1065. e = headers.createNewChildElement ("ClInclude");
  1066. else
  1067. e = cpps.createNewChildElement ("ClCompile");
  1068. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1069. e->setAttribute ("Include", file.toWindowsStyle());
  1070. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1071. }
  1072. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups) const
  1073. {
  1074. if (projectItem.isGroup())
  1075. {
  1076. addFilterGroup (groups, path);
  1077. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1078. addFilesToFilter (projectItem.getChild(i),
  1079. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1080. cpps, headers, groups);
  1081. }
  1082. else
  1083. {
  1084. if (projectItem.shouldBeAddedToTargetProject())
  1085. {
  1086. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1087. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1088. }
  1089. }
  1090. }
  1091. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1092. {
  1093. if (files.size() > 0)
  1094. {
  1095. addFilterGroup (groups, path);
  1096. for (int i = 0; i < files.size(); ++i)
  1097. addFileToFilter (files.getReference(i), path, cpps, headers);
  1098. }
  1099. }
  1100. void fillInFiltersXml (XmlElement& filterXml) const
  1101. {
  1102. filterXml.setAttribute ("ToolsVersion", "4.0");
  1103. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1104. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1105. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1106. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1107. for (int i = 0; i < groups.size(); ++i)
  1108. if (groups.getReference(i).getNumChildren() > 0)
  1109. addFilesToFilter (groups.getReference(i), groups.getReference(i).getName(), *cpps, *headers, *groupsXml);
  1110. if (iconFile.exists())
  1111. {
  1112. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1113. XmlElement* e = iconGroup->createNewChildElement ("None");
  1114. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1115. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1116. }
  1117. if (hasResourceFile())
  1118. {
  1119. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1120. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1121. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1122. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1123. }
  1124. }
  1125. //==============================================================================
  1126. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1127. };
  1128. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__