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.

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