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.

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