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.

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