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

1402 lines
60KB

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