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.

1390 lines
59KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  20. #include "jucer_ProjectExporter.h"
  21. #include "jucer_ProjectSaver.h"
  22. //==============================================================================
  23. class MSVCProjectExporterBase : public ProjectExporter
  24. {
  25. public:
  26. MSVCProjectExporterBase (Project& project_, const ValueTree& settings_, const char* const folderName)
  27. : ProjectExporter (project_, settings_)
  28. {
  29. if (getTargetLocationString().isEmpty())
  30. getTargetLocationValue() = getDefaultBuildsRootFolder() + folderName;
  31. if ((int) getLibraryType().getValue() <= 0)
  32. getLibraryType() = 1;
  33. projectGUID = createGUID (project.getProjectUID());
  34. updateOldSettings();
  35. }
  36. //==============================================================================
  37. bool isPossibleForCurrentProject() { return true; }
  38. bool usesMMFiles() const { return false; }
  39. bool isVisualStudio() const { return true; }
  40. bool canCopeWithDuplicateFiles() { return false; }
  41. void createPropertyEditors (PropertyListBuilder& props)
  42. {
  43. ProjectExporter::createPropertyEditors (props);
  44. if (projectType.isLibrary())
  45. {
  46. const char* const libTypes[] = { "Static Library (.lib)", "Dynamic Library (.dll)", 0 };
  47. const int libTypeValues[] = { 1, 2, 0 };
  48. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type",
  49. StringArray (libTypes), Array<var> (libTypeValues)));
  50. }
  51. }
  52. protected:
  53. String projectGUID;
  54. mutable File rcFile, iconFile;
  55. File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  56. Value getLibraryType() { return getSetting (Ids::libraryType); }
  57. bool isLibraryDLL() const { return msvcIsDLL || (projectType.isLibrary() && (int) settings [Ids::libraryType] == 2); }
  58. void updateOldSettings()
  59. {
  60. {
  61. const String oldStylePrebuildCommand (getSetting (Ids::prebuildCommand).toString());
  62. settings.removeProperty (Ids::prebuildCommand, nullptr);
  63. if (oldStylePrebuildCommand.isNotEmpty())
  64. for (ConfigIterator config (*this); config.next();)
  65. dynamic_cast <MSVCBuildConfiguration&> (*config).getPrebuildCommand() = oldStylePrebuildCommand;
  66. }
  67. {
  68. const String oldStyleLibName (getSetting ("libraryName_Debug").toString());
  69. settings.removeProperty ("libraryName_Debug", nullptr);
  70. if (oldStyleLibName.isNotEmpty())
  71. for (ConfigIterator config (*this); config.next();)
  72. if (config->isDebug())
  73. config->getTargetBinaryName() = oldStyleLibName;
  74. }
  75. {
  76. const String oldStyleLibName (getSetting ("libraryName_Release").toString());
  77. settings.removeProperty ("libraryName_Release", nullptr);
  78. if (oldStyleLibName.isNotEmpty())
  79. for (ConfigIterator config (*this); config.next();)
  80. if (! config->isDebug())
  81. config->getTargetBinaryName() = oldStyleLibName;
  82. }
  83. }
  84. //==============================================================================
  85. class MSVCBuildConfiguration : public BuildConfiguration
  86. {
  87. public:
  88. MSVCBuildConfiguration (Project& project, const ValueTree& settings)
  89. : BuildConfiguration (project, settings)
  90. {
  91. if (getWarningLevel() == 0)
  92. getWarningLevelValue() = 4;
  93. 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", "$(IntDir)\\" + config.getOutputFilename (".tlb", true));
  561. midl->setAttribute ("HeaderFileName", "");
  562. }
  563. {
  564. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  565. const int optimiseLevel = config.getOptimisationLevelInt();
  566. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "1" : "2"));
  567. if (isDebug)
  568. {
  569. compiler->setAttribute ("BufferSecurityCheck", "");
  570. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  571. }
  572. else
  573. {
  574. compiler->setAttribute ("InlineFunctionExpansion", "1");
  575. compiler->setAttribute ("StringPooling", "true");
  576. }
  577. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  578. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  579. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  580. : (isDebug ? 1 : 0)); // MT static
  581. compiler->setAttribute ("RuntimeTypeInfo", "true");
  582. compiler->setAttribute ("UsePrecompiledHeader", "0");
  583. compiler->setAttribute ("PrecompiledHeaderFile", "$(IntDir)\\" + config.getOutputFilename (".pch", true));
  584. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  585. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  586. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  587. compiler->setAttribute ("WarningLevel", String (getWarningLevel (config)));
  588. compiler->setAttribute ("SuppressStartupBanner", "true");
  589. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  590. if (extraFlags.isNotEmpty())
  591. compiler->setAttribute ("AdditionalOptions", extraFlags);
  592. }
  593. createToolElement (xml, "VCManagedResourceCompilerTool");
  594. {
  595. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  596. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  597. }
  598. createToolElement (xml, "VCPreLinkEventTool");
  599. if (! projectType.isLibrary())
  600. {
  601. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  602. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  603. linker->setAttribute ("SuppressStartupBanner", "true");
  604. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  605. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  606. linker->setAttribute ("ProgramDatabaseFile", "$(IntDir)\\" + config.getOutputFilename (".pdb", true));
  607. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  608. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  609. if (librarySearchPaths.size() > 0)
  610. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  611. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  612. if (! isDebug)
  613. {
  614. linker->setAttribute ("OptimizeReferences", "2");
  615. linker->setAttribute ("EnableCOMDATFolding", "2");
  616. }
  617. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  618. if (msvcDelayLoadedDLLs.isNotEmpty())
  619. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  620. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  621. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  622. String extraLinkerOptions (getExtraLinkerFlagsString());
  623. if (extraLinkerOptions.isNotEmpty())
  624. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  625. }
  626. else
  627. {
  628. if (isLibraryDLL())
  629. {
  630. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  631. String extraLinkerOptions (getExtraLinkerFlagsString());
  632. extraLinkerOptions << " /IMPLIB:" << FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (".lib", true));
  633. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  634. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  635. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  636. }
  637. else
  638. {
  639. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  640. librarian->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  641. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  642. }
  643. }
  644. createToolElement (xml, "VCALinkTool");
  645. createToolElement (xml, "VCManifestTool");
  646. createToolElement (xml, "VCXDCMakeTool");
  647. {
  648. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  649. bscMake->setAttribute ("SuppressStartupBanner", "true");
  650. bscMake->setAttribute ("OutputFile", "$(IntDir)\\" + config.getOutputFilename (".bsc", true));
  651. }
  652. createToolElement (xml, "VCFxCopTool");
  653. if (! projectType.isLibrary())
  654. createToolElement (xml, "VCAppVerifierTool");
  655. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  656. if (config.getPostbuildCommandString().isNotEmpty())
  657. {
  658. postBuildEvent->setAttribute ("Description", "Post-build");
  659. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  660. }
  661. }
  662. void createConfigs (XmlElement& xml) const
  663. {
  664. for (ConstConfigIterator config (*this); config.next();)
  665. createConfig (*xml.createNewChildElement ("Configuration"),
  666. dynamic_cast <const MSVCBuildConfiguration&> (*config));
  667. }
  668. //==============================================================================
  669. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  670. };
  671. //==============================================================================
  672. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  673. {
  674. public:
  675. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  676. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  677. {
  678. name = getName();
  679. }
  680. static const char* getName() { return "Visual Studio 2005"; }
  681. static const char* getValueTreeTypeName() { return "VS2005"; }
  682. int getVisualStudioVersion() const { return 8; }
  683. int getLaunchPreferenceOrderForCurrentOS()
  684. {
  685. #if JUCE_WINDOWS
  686. return 2;
  687. #else
  688. return 0;
  689. #endif
  690. }
  691. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  692. {
  693. if (settings.hasType (getValueTreeTypeName()))
  694. return new MSVCProjectExporterVC2005 (project, settings);
  695. return nullptr;
  696. }
  697. protected:
  698. String getProjectVersionString() const { return "8.00"; }
  699. String getSolutionVersionString() const { return "9.00" + newLine + "# Visual C++ Express 2005"; }
  700. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  701. };
  702. //==============================================================================
  703. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  704. {
  705. public:
  706. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  707. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  708. {
  709. name = getName();
  710. }
  711. static const char* getName() { return "Visual Studio 2010"; }
  712. static const char* getValueTreeTypeName() { return "VS2010"; }
  713. int getVisualStudioVersion() const { return 10; }
  714. int getLaunchPreferenceOrderForCurrentOS()
  715. {
  716. #if JUCE_WINDOWS
  717. return 3;
  718. #else
  719. return 0;
  720. #endif
  721. }
  722. void launchProject() { getSLNFile().startAsProcess(); }
  723. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  724. {
  725. if (settings.hasType (getValueTreeTypeName()))
  726. return new MSVCProjectExporterVC2010 (project, settings);
  727. return nullptr;
  728. }
  729. //==============================================================================
  730. void create (const OwnedArray<LibraryModule>&) const
  731. {
  732. createResourcesAndIcon();
  733. {
  734. XmlElement projectXml ("Project");
  735. fillInProjectXml (projectXml);
  736. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  737. }
  738. {
  739. XmlElement filtersXml ("Project");
  740. fillInFiltersXml (filtersXml);
  741. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  742. }
  743. {
  744. MemoryOutputStream mo;
  745. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  746. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  747. }
  748. }
  749. protected:
  750. //==============================================================================
  751. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  752. {
  753. public:
  754. VC2010BuildConfiguration (Project& project, const ValueTree& settings)
  755. : MSVCBuildConfiguration (project, settings)
  756. {
  757. if (getArchitectureType().toString().isEmpty())
  758. getArchitectureType() = get32BitArchName();
  759. }
  760. //==============================================================================
  761. static const char* get32BitArchName() { return "32-bit"; }
  762. static const char* get64BitArchName() { return "x64"; }
  763. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  764. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  765. //==============================================================================
  766. void createPropertyEditors (PropertyListBuilder& props)
  767. {
  768. MSVCBuildConfiguration::createPropertyEditors (props);
  769. const char* const archTypes[] = { get32BitArchName(), get64BitArchName(), nullptr };
  770. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  771. StringArray (archTypes), Array<var> (archTypes)));
  772. }
  773. };
  774. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  775. {
  776. return new VC2010BuildConfiguration (project, settings);
  777. }
  778. static bool is64Bit (const BuildConfiguration& config)
  779. {
  780. return dynamic_cast <const VC2010BuildConfiguration&> (config).is64Bit();
  781. }
  782. //==============================================================================
  783. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  784. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  785. File getSLNFile() const { return getProjectFile (".sln"); }
  786. String createConfigName (const BuildConfiguration& config) const
  787. {
  788. return config.getName() + (is64Bit (config) ? "|x64"
  789. : "|Win32");
  790. }
  791. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  792. {
  793. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  794. }
  795. //==============================================================================
  796. void fillInProjectXml (XmlElement& projectXml) const
  797. {
  798. projectXml.setAttribute ("DefaultTargets", "Build");
  799. projectXml.setAttribute ("ToolsVersion", "4.0");
  800. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  801. {
  802. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  803. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  804. for (ConstConfigIterator config (*this); config.next();)
  805. {
  806. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  807. e->setAttribute ("Include", createConfigName (*config));
  808. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  809. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  810. }
  811. }
  812. {
  813. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  814. globals->setAttribute ("Label", "Globals");
  815. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  816. }
  817. {
  818. XmlElement* imports = projectXml.createNewChildElement ("Import");
  819. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  820. }
  821. for (ConstConfigIterator config (*this); config.next();)
  822. {
  823. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  824. setConditionAttribute (*e, *config);
  825. e->setAttribute ("Label", "Configuration");
  826. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  827. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  828. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  829. if (! config->isDebug())
  830. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  831. if (is64Bit (*config))
  832. e->createNewChildElement ("PlatformToolset")->addTextElement ("Windows7.1SDK");
  833. }
  834. {
  835. XmlElement* e = projectXml.createNewChildElement ("Import");
  836. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  837. }
  838. {
  839. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  840. e->setAttribute ("Label", "ExtensionSettings");
  841. }
  842. {
  843. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  844. e->setAttribute ("Label", "PropertySheets");
  845. XmlElement* p = e->createNewChildElement ("Import");
  846. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  847. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  848. p->setAttribute ("Label", "LocalAppDataPlatform");
  849. }
  850. {
  851. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  852. e->setAttribute ("Label", "UserMacros");
  853. }
  854. {
  855. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  856. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  857. for (ConstConfigIterator i (*this); i.next();)
  858. {
  859. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  860. {
  861. XmlElement* outdir = props->createNewChildElement ("OutDir");
  862. setConditionAttribute (*outdir, config);
  863. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  864. }
  865. {
  866. XmlElement* intdir = props->createNewChildElement ("IntDir");
  867. setConditionAttribute (*intdir, config);
  868. intdir->addTextElement (getIntermediatesPath (config) + "\\");
  869. }
  870. {
  871. XmlElement* name = props->createNewChildElement ("TargetName");
  872. setConditionAttribute (*name, config);
  873. name->addTextElement (config.getOutputFilename (String::empty, true));
  874. }
  875. {
  876. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  877. setConditionAttribute (*manifest, config);
  878. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  879. }
  880. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  881. if (librarySearchPaths.size() > 0)
  882. {
  883. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  884. setConditionAttribute (*libPath, config);
  885. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  886. }
  887. }
  888. }
  889. for (ConstConfigIterator i (*this); i.next();)
  890. {
  891. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  892. String binariesPath (getConfigTargetPath (config));
  893. String intermediatesPath (getIntermediatesPath (config));
  894. const bool isDebug = config.isDebug();
  895. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  896. setConditionAttribute (*group, config);
  897. {
  898. XmlElement* midl = group->createNewChildElement ("Midl");
  899. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  900. : "NDEBUG;%(PreprocessorDefinitions)");
  901. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  902. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  903. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  904. midl->createNewChildElement ("HeaderFileName");
  905. }
  906. {
  907. XmlElement* cl = group->createNewChildElement ("ClCompile");
  908. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  909. if (isDebug)
  910. cl->createNewChildElement ("DebugInformationFormat")->addTextElement (is64Bit (config) ? "ProgramDatabase"
  911. : "EditAndContinue");
  912. StringArray includePaths (getHeaderSearchPaths (config));
  913. includePaths.add ("%(AdditionalIncludeDirectories)");
  914. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  915. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  916. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  917. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  918. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  919. cl->createNewChildElement ("PrecompiledHeader");
  920. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  921. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  922. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  923. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (getWarningLevel (config)));
  924. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  925. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  926. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  927. if (extraFlags.isNotEmpty())
  928. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  929. }
  930. {
  931. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  932. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  933. : "NDEBUG;%(PreprocessorDefinitions)");
  934. }
  935. {
  936. XmlElement* link = group->createNewChildElement ("Link");
  937. link->createNewChildElement ("OutputFile")
  938. ->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + config.getOutputFilename (msvcTargetSuffix, false)));
  939. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  940. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  941. : "%(IgnoreSpecificDefaultLibraries)");
  942. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  943. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement ("$(IntDir)\\" + config.getOutputFilename (".pdb", true));
  944. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  945. if (! is64Bit (config))
  946. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  947. if (! isDebug)
  948. {
  949. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  950. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  951. }
  952. String extraLinkerOptions (getExtraLinkerFlagsString());
  953. if (extraLinkerOptions.isNotEmpty())
  954. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  955. + " %(AdditionalOptions)");
  956. if (msvcDelayLoadedDLLs.isNotEmpty())
  957. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  958. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  959. link->createNewChildElement ("ModuleDefinitionFile")
  960. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  961. }
  962. {
  963. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  964. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  965. bsc->createNewChildElement ("OutputFile")->addTextElement ("$(IntDir)\\" + config.getOutputFilename (".bsc", true));
  966. }
  967. if (config.getPrebuildCommandString().isNotEmpty())
  968. group->createNewChildElement ("PreBuildEvent")
  969. ->createNewChildElement ("Command")
  970. ->addTextElement (config.getPrebuildCommandString());
  971. if (config.getPostbuildCommandString().isNotEmpty())
  972. group->createNewChildElement ("PostBuildEvent")
  973. ->createNewChildElement ("Command")
  974. ->addTextElement (config.getPostbuildCommandString());
  975. }
  976. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  977. {
  978. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  979. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  980. for (int i = 0; i < groups.size(); ++i)
  981. if (groups.getReference(i).getNumChildren() > 0)
  982. addFilesToCompile (groups.getReference(i), *cppFiles, *headerFiles, *otherFilesGroup);
  983. }
  984. if (iconFile != File::nonexistent)
  985. {
  986. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  987. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  988. }
  989. if (otherFilesGroup->getFirstChildElement() != nullptr)
  990. projectXml.addChildElement (otherFilesGroup.release());
  991. if (hasResourceFile())
  992. {
  993. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  994. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  995. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  996. }
  997. {
  998. XmlElement* e = projectXml.createNewChildElement ("Import");
  999. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1000. }
  1001. {
  1002. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1003. e->setAttribute ("Label", "ExtensionTargets");
  1004. }
  1005. }
  1006. String getProjectType() const
  1007. {
  1008. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1009. else if (isLibraryDLL()) return "DynamicLibrary";
  1010. else if (projectType.isLibrary()) return "StaticLibrary";
  1011. jassertfalse;
  1012. return String::empty;
  1013. }
  1014. //==============================================================================
  1015. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1016. {
  1017. if (projectItem.isGroup())
  1018. {
  1019. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1020. addFilesToCompile (projectItem.getChild(i), cpps, headers, otherFiles);
  1021. }
  1022. else if (projectItem.shouldBeAddedToTargetProject())
  1023. {
  1024. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1025. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1026. if (path.hasFileExtension ("cpp;cc;cxx;c"))
  1027. {
  1028. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1029. e->setAttribute ("Include", path.toWindowsStyle());
  1030. if (! projectItem.shouldBeCompiled())
  1031. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1032. if (projectItem.shouldUseStdCall())
  1033. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1034. }
  1035. else if (path.hasFileExtension (headerFileExtensions))
  1036. {
  1037. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  1038. }
  1039. else if (! path.hasFileExtension ("mm;m"))
  1040. {
  1041. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  1042. }
  1043. }
  1044. }
  1045. //==============================================================================
  1046. void addFilterGroup (XmlElement& groups, const String& path) const
  1047. {
  1048. XmlElement* e = groups.createNewChildElement ("Filter");
  1049. e->setAttribute ("Include", path);
  1050. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1051. }
  1052. void addFileToFilter (const RelativePath& file, const String& groupPath,
  1053. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1054. {
  1055. XmlElement* e;
  1056. if (file.hasFileExtension (headerFileExtensions))
  1057. e = headers.createNewChildElement ("ClInclude");
  1058. else if (file.hasFileExtension (sourceFileExtensions))
  1059. e = cpps.createNewChildElement ("ClCompile");
  1060. else
  1061. e = otherFiles.createNewChildElement ("None");
  1062. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1063. e->setAttribute ("Include", file.toWindowsStyle());
  1064. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1065. }
  1066. void addFilesToFilter (const Project::Item& projectItem, const String& path,
  1067. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  1068. {
  1069. if (projectItem.isGroup())
  1070. {
  1071. addFilterGroup (groups, path);
  1072. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1073. addFilesToFilter (projectItem.getChild(i),
  1074. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1075. cpps, headers, otherFiles, groups);
  1076. }
  1077. else if (projectItem.shouldBeAddedToTargetProject())
  1078. {
  1079. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1080. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  1081. }
  1082. }
  1083. void addFilesToFilter (const Array<RelativePath>& files, const String& path,
  1084. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  1085. {
  1086. if (files.size() > 0)
  1087. {
  1088. addFilterGroup (groups, path);
  1089. for (int i = 0; i < files.size(); ++i)
  1090. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  1091. }
  1092. }
  1093. void fillInFiltersXml (XmlElement& filterXml) const
  1094. {
  1095. filterXml.setAttribute ("ToolsVersion", "4.0");
  1096. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1097. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1098. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1099. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1100. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1101. for (int i = 0; i < groups.size(); ++i)
  1102. if (groups.getReference(i).getNumChildren() > 0)
  1103. addFilesToFilter (groups.getReference(i), groups.getReference(i).getName(),
  1104. *cpps, *headers, *otherFilesGroup, *groupsXml);
  1105. if (iconFile.exists())
  1106. {
  1107. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1108. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1109. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1110. }
  1111. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1112. filterXml.addChildElement (otherFilesGroup.release());
  1113. if (hasResourceFile())
  1114. {
  1115. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1116. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1117. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1118. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1119. }
  1120. }
  1121. //==============================================================================
  1122. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1123. };
  1124. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__