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.

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