The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1396 lines
60KB

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