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.

1429 lines
62KB

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