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.

1408 lines
61KB

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