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.

1384 lines
59KB

  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 ".\\" + 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 ".\\" + 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. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase);
  385. };
  386. //==============================================================================
  387. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  388. {
  389. public:
  390. //==============================================================================
  391. MSVCProjectExporterVC2008 (Project& project_, const ValueTree& settings_, const char* folderName = "VisualStudio2008")
  392. : MSVCProjectExporterBase (project_, settings_, folderName)
  393. {
  394. name = getName();
  395. }
  396. static const char* getName() { return "Visual Studio 2008"; }
  397. static const char* getValueTreeTypeName() { return "VS2008"; }
  398. void launchProject() { getSLNFile().startAsProcess(); }
  399. int getLaunchPreferenceOrderForCurrentOS()
  400. {
  401. #if JUCE_WINDOWS
  402. return 4;
  403. #else
  404. return 0;
  405. #endif
  406. }
  407. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  408. {
  409. if (settings.hasType (getValueTreeTypeName()))
  410. return new MSVCProjectExporterVC2008 (project, settings);
  411. return nullptr;
  412. }
  413. //==============================================================================
  414. void create (const OwnedArray<LibraryModule>&) const
  415. {
  416. createResourcesAndIcon();
  417. if (hasResourceFile())
  418. {
  419. for (int i = 0; i < groups.size(); ++i)
  420. {
  421. Project::Item& group = groups.getReference(i);
  422. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  423. {
  424. if (iconFile != File::nonexistent)
  425. {
  426. group.addFile (iconFile, -1, true);
  427. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  428. }
  429. group.addFile (rcFile, -1, true);
  430. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  431. break;
  432. }
  433. }
  434. }
  435. {
  436. XmlElement projectXml ("VisualStudioProject");
  437. fillInProjectXml (projectXml);
  438. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  439. }
  440. {
  441. MemoryOutputStream mo;
  442. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  443. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  444. }
  445. }
  446. protected:
  447. virtual String getProjectVersionString() const { return "9.00"; }
  448. virtual String getSolutionVersionString() const { return "10.00" + newLine + "# Visual C++ Express 2008"; }
  449. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  450. File getSLNFile() const { return getProjectFile (".sln"); }
  451. //==============================================================================
  452. void fillInProjectXml (XmlElement& projectXml) const
  453. {
  454. projectXml.setAttribute ("ProjectType", "Visual C++");
  455. projectXml.setAttribute ("Version", getProjectVersionString());
  456. projectXml.setAttribute ("Name", projectName);
  457. projectXml.setAttribute ("ProjectGUID", projectGUID);
  458. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  459. {
  460. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  461. XmlElement* platform = platforms->createNewChildElement ("Platform");
  462. platform->setAttribute ("Name", "Win32");
  463. }
  464. projectXml.createNewChildElement ("ToolFiles");
  465. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  466. projectXml.createNewChildElement ("References");
  467. createFiles (*projectXml.createNewChildElement ("Files"));
  468. projectXml.createNewChildElement ("Globals");
  469. }
  470. //==============================================================================
  471. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall) const
  472. {
  473. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  474. XmlElement* fileXml = parent.createNewChildElement ("File");
  475. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  476. if (excludeFromBuild || useStdcall)
  477. {
  478. for (ConstConfigIterator i (*this); i.next();)
  479. {
  480. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  481. fileConfig->setAttribute ("Name", createConfigName (*i));
  482. if (excludeFromBuild)
  483. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  484. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  485. if (useStdcall)
  486. tool->setAttribute ("CallingConvention", "2");
  487. }
  488. }
  489. }
  490. XmlElement* createGroup (const String& groupName, XmlElement& parent) const
  491. {
  492. XmlElement* filter = parent.createNewChildElement ("Filter");
  493. filter->setAttribute ("Name", groupName);
  494. return filter;
  495. }
  496. void addFiles (const Project::Item& projectItem, XmlElement& parent) const
  497. {
  498. if (projectItem.isGroup())
  499. {
  500. XmlElement* filter = createGroup (projectItem.getName(), parent);
  501. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  502. addFiles (projectItem.getChild(i), *filter);
  503. }
  504. else if (projectItem.shouldBeAddedToTargetProject())
  505. {
  506. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  507. addFile (path, parent,
  508. projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  509. shouldFileBeCompiledByDefault (path) && (bool) projectItem.shouldUseStdCall());
  510. }
  511. }
  512. void createFiles (XmlElement& files) const
  513. {
  514. for (int i = 0; i < groups.size(); ++i)
  515. if (groups.getReference(i).getNumChildren() > 0)
  516. addFiles (groups.getReference(i), files);
  517. }
  518. //==============================================================================
  519. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  520. {
  521. XmlElement* const e = parent.createNewChildElement ("Tool");
  522. e->setAttribute ("Name", toolName);
  523. return e;
  524. }
  525. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  526. {
  527. String binariesPath (getConfigTargetPath (config));
  528. String intermediatesPath (getIntermediatesPath (config));
  529. const bool isDebug = config.isDebug();
  530. xml.setAttribute ("Name", createConfigName (config));
  531. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (binariesPath));
  532. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (intermediatesPath));
  533. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isLibrary() ? "4" : "1"));
  534. xml.setAttribute ("UseOfMFC", "0");
  535. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  536. xml.setAttribute ("CharacterSet", "2");
  537. if (! isDebug)
  538. xml.setAttribute ("WholeProgramOptimization", "1");
  539. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  540. if (config.getPrebuildCommandString().isNotEmpty())
  541. {
  542. preBuildEvent->setAttribute ("Description", "Pre-build");
  543. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  544. }
  545. createToolElement (xml, "VCCustomBuildTool");
  546. createToolElement (xml, "VCXMLDataGeneratorTool");
  547. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  548. if (! projectType.isLibrary())
  549. {
  550. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  551. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  552. midl->setAttribute ("MkTypLibCompatible", "true");
  553. midl->setAttribute ("SuppressStartupBanner", "true");
  554. midl->setAttribute ("TargetEnvironment", "1");
  555. midl->setAttribute ("TypeLibraryName", FileHelpers::windowsStylePath (intermediatesPath + "/"
  556. + config.getOutputFilename (".tlb", true)));
  557. midl->setAttribute ("HeaderFileName", "");
  558. }
  559. {
  560. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  561. const int optimiseLevel = config.getOptimisationLevelInt();
  562. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "1" : "2"));
  563. if (isDebug)
  564. {
  565. compiler->setAttribute ("BufferSecurityCheck", "");
  566. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  567. }
  568. else
  569. {
  570. compiler->setAttribute ("InlineFunctionExpansion", "1");
  571. compiler->setAttribute ("StringPooling", "true");
  572. }
  573. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  574. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  575. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  576. : (isDebug ? 1 : 0)); // MT static
  577. compiler->setAttribute ("RuntimeTypeInfo", "true");
  578. compiler->setAttribute ("UsePrecompiledHeader", "0");
  579. compiler->setAttribute ("PrecompiledHeaderFile", FileHelpers::windowsStylePath (intermediatesPath + "/"
  580. + config.getOutputFilename (".pch", true)));
  581. compiler->setAttribute ("AssemblerListingLocation", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  582. compiler->setAttribute ("ObjectFile", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  583. compiler->setAttribute ("ProgramDataBaseFileName", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  584. compiler->setAttribute ("WarningLevel", String (getWarningLevel (config)));
  585. compiler->setAttribute ("SuppressStartupBanner", "true");
  586. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  587. if (extraFlags.isNotEmpty())
  588. compiler->setAttribute ("AdditionalOptions", extraFlags);
  589. }
  590. createToolElement (xml, "VCManagedResourceCompilerTool");
  591. {
  592. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  593. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  594. }
  595. createToolElement (xml, "VCPreLinkEventTool");
  596. if (! projectType.isLibrary())
  597. {
  598. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  599. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  600. linker->setAttribute ("SuppressStartupBanner", "true");
  601. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  602. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  603. linker->setAttribute ("ProgramDatabaseFile", FileHelpers::windowsStylePath (intermediatesPath + "/"
  604. + config.getOutputFilename (".pdb", true)));
  605. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  606. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  607. if (librarySearchPaths.size() > 0)
  608. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  609. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  610. if (! isDebug)
  611. {
  612. linker->setAttribute ("OptimizeReferences", "2");
  613. linker->setAttribute ("EnableCOMDATFolding", "2");
  614. }
  615. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  616. if (msvcDelayLoadedDLLs.isNotEmpty())
  617. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  618. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  619. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  620. String extraLinkerOptions (getExtraLinkerFlagsString());
  621. if (extraLinkerOptions.isNotEmpty())
  622. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  623. }
  624. else
  625. {
  626. if (isLibraryDLL())
  627. {
  628. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  629. String extraLinkerOptions (getExtraLinkerFlagsString());
  630. extraLinkerOptions << " /IMPLIB:" << FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (".lib", true));
  631. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  632. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  633. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  634. }
  635. else
  636. {
  637. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  638. librarian->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  639. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  640. }
  641. }
  642. createToolElement (xml, "VCALinkTool");
  643. createToolElement (xml, "VCManifestTool");
  644. createToolElement (xml, "VCXDCMakeTool");
  645. {
  646. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  647. bscMake->setAttribute ("SuppressStartupBanner", "true");
  648. bscMake->setAttribute ("OutputFile", FileHelpers::windowsStylePath (intermediatesPath + "/"
  649. + config.getOutputFilename (".bsc", true)));
  650. }
  651. createToolElement (xml, "VCFxCopTool");
  652. if (! projectType.isLibrary())
  653. createToolElement (xml, "VCAppVerifierTool");
  654. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  655. if (config.getPostbuildCommandString().isNotEmpty())
  656. {
  657. postBuildEvent->setAttribute ("Description", "Post-build");
  658. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  659. }
  660. }
  661. void createConfigs (XmlElement& xml) const
  662. {
  663. for (ConstConfigIterator config (*this); config.next();)
  664. createConfig (*xml.createNewChildElement ("Configuration"),
  665. dynamic_cast <const MSVCBuildConfiguration&> (*config));
  666. }
  667. //==============================================================================
  668. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  669. };
  670. //==============================================================================
  671. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  672. {
  673. public:
  674. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  675. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  676. {
  677. name = getName();
  678. }
  679. static const char* getName() { return "Visual Studio 2005"; }
  680. static const char* getValueTreeTypeName() { return "VS2005"; }
  681. int getLaunchPreferenceOrderForCurrentOS()
  682. {
  683. #if JUCE_WINDOWS
  684. return 2;
  685. #else
  686. return 0;
  687. #endif
  688. }
  689. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  690. {
  691. if (settings.hasType (getValueTreeTypeName()))
  692. return new MSVCProjectExporterVC2005 (project, settings);
  693. return nullptr;
  694. }
  695. protected:
  696. String getProjectVersionString() const { return "8.00"; }
  697. String getSolutionVersionString() const { return "9.00" + newLine + "# Visual C++ Express 2005"; }
  698. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  699. };
  700. //==============================================================================
  701. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  702. {
  703. public:
  704. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  705. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  706. {
  707. name = getName();
  708. }
  709. static const char* getName() { return "Visual Studio 2010"; }
  710. static const char* getValueTreeTypeName() { return "VS2010"; }
  711. int getLaunchPreferenceOrderForCurrentOS()
  712. {
  713. #if JUCE_WINDOWS
  714. return 3;
  715. #else
  716. return 0;
  717. #endif
  718. }
  719. void launchProject() { getSLNFile().startAsProcess(); }
  720. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  721. {
  722. if (settings.hasType (getValueTreeTypeName()))
  723. return new MSVCProjectExporterVC2010 (project, settings);
  724. return nullptr;
  725. }
  726. //==============================================================================
  727. void create (const OwnedArray<LibraryModule>&) const
  728. {
  729. createResourcesAndIcon();
  730. {
  731. XmlElement projectXml ("Project");
  732. fillInProjectXml (projectXml);
  733. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  734. }
  735. {
  736. XmlElement filtersXml ("Project");
  737. fillInFiltersXml (filtersXml);
  738. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  739. }
  740. {
  741. MemoryOutputStream mo;
  742. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  743. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  744. }
  745. }
  746. protected:
  747. //==============================================================================
  748. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  749. {
  750. public:
  751. VC2010BuildConfiguration (Project& project, const ValueTree& settings)
  752. : MSVCBuildConfiguration (project, settings)
  753. {
  754. if (getArchitectureType().toString().isEmpty())
  755. getArchitectureType() = get32BitArchName();
  756. }
  757. //==============================================================================
  758. static const char* get32BitArchName() { return "32-bit"; }
  759. static const char* get64BitArchName() { return "x64"; }
  760. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  761. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  762. //==============================================================================
  763. void createPropertyEditors (PropertyListBuilder& props)
  764. {
  765. MSVCBuildConfiguration::createPropertyEditors (props);
  766. const char* const archTypes[] = { get32BitArchName(), get64BitArchName(), nullptr };
  767. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  768. StringArray (archTypes), Array<var> (archTypes)));
  769. }
  770. };
  771. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  772. {
  773. return new VC2010BuildConfiguration (project, settings);
  774. }
  775. static bool is64Bit (const BuildConfiguration& config)
  776. {
  777. return dynamic_cast <const VC2010BuildConfiguration&> (config).is64Bit();
  778. }
  779. //==============================================================================
  780. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  781. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  782. File getSLNFile() const { return getProjectFile (".sln"); }
  783. String createConfigName (const BuildConfiguration& config) const
  784. {
  785. return config.getName() + (is64Bit (config) ? "|x64"
  786. : "|Win32");
  787. }
  788. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  789. {
  790. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  791. }
  792. //==============================================================================
  793. void fillInProjectXml (XmlElement& projectXml) const
  794. {
  795. projectXml.setAttribute ("DefaultTargets", "Build");
  796. projectXml.setAttribute ("ToolsVersion", "4.0");
  797. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  798. {
  799. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  800. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  801. for (ConstConfigIterator config (*this); config.next();)
  802. {
  803. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  804. e->setAttribute ("Include", createConfigName (*config));
  805. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  806. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  807. }
  808. }
  809. {
  810. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  811. globals->setAttribute ("Label", "Globals");
  812. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  813. }
  814. {
  815. XmlElement* imports = projectXml.createNewChildElement ("Import");
  816. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  817. }
  818. for (ConstConfigIterator config (*this); config.next();)
  819. {
  820. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  821. setConditionAttribute (*e, *config);
  822. e->setAttribute ("Label", "Configuration");
  823. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  824. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  825. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  826. if (! config->isDebug())
  827. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  828. if (is64Bit (*config))
  829. e->createNewChildElement ("PlatformToolset")->addTextElement ("Windows7.1SDK");
  830. }
  831. {
  832. XmlElement* e = projectXml.createNewChildElement ("Import");
  833. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  834. }
  835. {
  836. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  837. e->setAttribute ("Label", "ExtensionSettings");
  838. }
  839. {
  840. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  841. e->setAttribute ("Label", "PropertySheets");
  842. XmlElement* p = e->createNewChildElement ("Import");
  843. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  844. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  845. p->setAttribute ("Label", "LocalAppDataPlatform");
  846. }
  847. {
  848. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  849. e->setAttribute ("Label", "UserMacros");
  850. }
  851. {
  852. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  853. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  854. for (ConstConfigIterator i (*this); i.next();)
  855. {
  856. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  857. {
  858. XmlElement* outdir = props->createNewChildElement ("OutDir");
  859. setConditionAttribute (*outdir, config);
  860. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  861. }
  862. {
  863. XmlElement* intdir = props->createNewChildElement ("IntDir");
  864. setConditionAttribute (*intdir, config);
  865. intdir->addTextElement (getConfigTargetPath (config) + "\\");
  866. }
  867. {
  868. XmlElement* name = props->createNewChildElement ("TargetName");
  869. setConditionAttribute (*name, config);
  870. name->addTextElement (config.getOutputFilename (String::empty, true));
  871. }
  872. {
  873. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  874. setConditionAttribute (*manifest, config);
  875. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  876. }
  877. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  878. if (librarySearchPaths.size() > 0)
  879. {
  880. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  881. setConditionAttribute (*libPath, config);
  882. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  883. }
  884. }
  885. }
  886. for (ConstConfigIterator i (*this); i.next();)
  887. {
  888. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  889. String binariesPath (getConfigTargetPath (config));
  890. String intermediatesPath (getIntermediatesPath (config));
  891. const bool isDebug = config.isDebug();
  892. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  893. setConditionAttribute (*group, config);
  894. {
  895. XmlElement* midl = group->createNewChildElement ("Midl");
  896. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  897. : "NDEBUG;%(PreprocessorDefinitions)");
  898. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  899. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  900. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  901. midl->createNewChildElement ("HeaderFileName");
  902. }
  903. {
  904. XmlElement* cl = group->createNewChildElement ("ClCompile");
  905. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  906. if (isDebug)
  907. cl->createNewChildElement ("DebugInformationFormat")->addTextElement (is64Bit (config) ? "ProgramDatabase"
  908. : "EditAndContinue");
  909. StringArray includePaths (getHeaderSearchPaths (config));
  910. includePaths.add ("%(AdditionalIncludeDirectories)");
  911. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  912. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  913. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  914. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  915. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  916. cl->createNewChildElement ("PrecompiledHeader");
  917. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  918. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  919. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  920. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (getWarningLevel (config)));
  921. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  922. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  923. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  924. if (extraFlags.isNotEmpty())
  925. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  926. }
  927. {
  928. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  929. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  930. : "NDEBUG;%(PreprocessorDefinitions)");
  931. }
  932. {
  933. XmlElement* link = group->createNewChildElement ("Link");
  934. link->createNewChildElement ("OutputFile")
  935. ->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  936. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  937. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  938. : "%(IgnoreSpecificDefaultLibraries)");
  939. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  940. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"
  941. + config.getOutputFilename (".pdb", true)));
  942. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  943. if (! is64Bit (config))
  944. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  945. if (! isDebug)
  946. {
  947. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  948. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  949. }
  950. String extraLinkerOptions (getExtraLinkerFlagsString());
  951. if (extraLinkerOptions.isNotEmpty())
  952. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  953. + " %(AdditionalOptions)");
  954. }
  955. {
  956. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  957. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  958. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath
  959. + "/" + config.getOutputFilename (".bsc", true)));
  960. }
  961. if (config.getPrebuildCommandString().isNotEmpty())
  962. group->createNewChildElement ("PreBuildEvent")
  963. ->createNewChildElement ("Command")
  964. ->addTextElement (config.getPrebuildCommandString());
  965. if (config.getPostbuildCommandString().isNotEmpty())
  966. group->createNewChildElement ("PostBuildEvent")
  967. ->createNewChildElement ("Command")
  968. ->addTextElement (config.getPostbuildCommandString());
  969. }
  970. {
  971. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  972. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  973. for (int i = 0; i < groups.size(); ++i)
  974. if (groups.getReference(i).getNumChildren() > 0)
  975. addFilesToCompile (groups.getReference(i), *cppFiles, *headerFiles, false);
  976. }
  977. if (iconFile != File::nonexistent)
  978. {
  979. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  980. XmlElement* e = iconGroup->createNewChildElement ("None");
  981. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  982. }
  983. if (hasResourceFile())
  984. {
  985. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  986. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  987. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  988. }
  989. {
  990. XmlElement* e = projectXml.createNewChildElement ("Import");
  991. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  992. }
  993. {
  994. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  995. e->setAttribute ("Label", "ExtensionTargets");
  996. }
  997. }
  998. String getProjectType() const
  999. {
  1000. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1001. else if (isLibraryDLL()) return "DynamicLibrary";
  1002. else if (projectType.isLibrary()) return "StaticLibrary";
  1003. jassertfalse;
  1004. return String::empty;
  1005. }
  1006. //==============================================================================
  1007. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall) const
  1008. {
  1009. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1010. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1011. {
  1012. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1013. e->setAttribute ("Include", file.toWindowsStyle());
  1014. if (excludeFromBuild)
  1015. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1016. if (useStdcall)
  1017. {
  1018. jassertfalse;
  1019. }
  1020. }
  1021. else if (file.hasFileExtension (headerFileExtensions))
  1022. {
  1023. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1024. }
  1025. }
  1026. void addFilesToCompile (const Array<RelativePath>& files, XmlElement& cpps, XmlElement& headers, bool useStdCall) const
  1027. {
  1028. for (int i = 0; i < files.size(); ++i)
  1029. addFileToCompile (files.getReference(i), cpps, headers, false, useStdCall);
  1030. }
  1031. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, bool useStdCall) const
  1032. {
  1033. if (projectItem.isGroup())
  1034. {
  1035. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1036. addFilesToCompile (projectItem.getChild(i), cpps, headers, useStdCall);
  1037. }
  1038. else
  1039. {
  1040. if (projectItem.shouldBeAddedToTargetProject())
  1041. {
  1042. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1043. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx")))
  1044. addFileToCompile (path, cpps, headers, ! projectItem.shouldBeCompiled(), useStdCall);
  1045. }
  1046. }
  1047. }
  1048. //==============================================================================
  1049. void addFilterGroup (XmlElement& groups, const String& path) const
  1050. {
  1051. XmlElement* e = groups.createNewChildElement ("Filter");
  1052. e->setAttribute ("Include", path);
  1053. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1054. }
  1055. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers) const
  1056. {
  1057. XmlElement* e;
  1058. if (file.hasFileExtension (headerFileExtensions))
  1059. e = headers.createNewChildElement ("ClInclude");
  1060. else
  1061. e = cpps.createNewChildElement ("ClCompile");
  1062. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1063. e->setAttribute ("Include", file.toWindowsStyle());
  1064. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1065. }
  1066. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups) const
  1067. {
  1068. if (projectItem.isGroup())
  1069. {
  1070. addFilterGroup (groups, path);
  1071. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1072. addFilesToFilter (projectItem.getChild(i),
  1073. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1074. cpps, headers, groups);
  1075. }
  1076. else
  1077. {
  1078. if (projectItem.shouldBeAddedToTargetProject())
  1079. {
  1080. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1081. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1082. }
  1083. }
  1084. }
  1085. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1086. {
  1087. if (files.size() > 0)
  1088. {
  1089. addFilterGroup (groups, path);
  1090. for (int i = 0; i < files.size(); ++i)
  1091. addFileToFilter (files.getReference(i), path, cpps, headers);
  1092. }
  1093. }
  1094. void fillInFiltersXml (XmlElement& filterXml) const
  1095. {
  1096. filterXml.setAttribute ("ToolsVersion", "4.0");
  1097. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1098. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1099. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1100. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1101. for (int i = 0; i < groups.size(); ++i)
  1102. if (groups.getReference(i).getNumChildren() > 0)
  1103. addFilesToFilter (groups.getReference(i), groups.getReference(i).getName(), *cpps, *headers, *groupsXml);
  1104. if (iconFile.exists())
  1105. {
  1106. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1107. XmlElement* e = iconGroup->createNewChildElement ("None");
  1108. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1109. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1110. }
  1111. if (hasResourceFile())
  1112. {
  1113. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1114. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1115. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1116. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1117. }
  1118. }
  1119. //==============================================================================
  1120. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1121. };
  1122. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__