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.

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