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.

1407 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& project_, const ValueTree& settings_, const char* const folderName)
  27. : ProjectExporter (project_, settings_)
  28. {
  29. if (getTargetLocationString().isEmpty())
  30. getTargetLocationValue() = getDefaultBuildsRootFolder() + folderName;
  31. if ((int) getLibraryType().getValue() <= 0)
  32. getLibraryType() = 1;
  33. projectGUID = createGUID (project.getProjectUID());
  34. updateOldSettings();
  35. }
  36. //==============================================================================
  37. bool 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 createPropertyEditors (PropertyListBuilder& props)
  49. {
  50. ProjectExporter::createPropertyEditors (props);
  51. if (projectType.isLibrary())
  52. {
  53. const char* const libTypes[] = { "Static Library (.lib)", "Dynamic Library (.dll)", 0 };
  54. const int libTypeValues[] = { 1, 2, 0 };
  55. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type",
  56. StringArray (libTypes), Array<var> (libTypeValues)));
  57. }
  58. }
  59. protected:
  60. String projectGUID;
  61. mutable File rcFile, iconFile;
  62. File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  63. Value getLibraryType() { return getSetting (Ids::libraryType); }
  64. String getLibraryString() const { return getSettingString (Ids::libraryType); }
  65. bool isLibraryDLL() const { return msvcIsDLL || (projectType.isLibrary() && (int) settings [Ids::libraryType] == 2); }
  66. static String prependIfNotAbsolute (const String& file, const char* prefix)
  67. {
  68. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  69. prefix = "";
  70. return prefix + FileHelpers::windowsStylePath (file);
  71. }
  72. static String getIntDirFile (const String& file) { return prependIfNotAbsolute (file, "$(IntDir)\\"); }
  73. static String getOutDirFile (const String& file) { return prependIfNotAbsolute (file, "$(OutDir)\\"); }
  74. void updateOldSettings()
  75. {
  76. {
  77. const String oldStylePrebuildCommand (getSettingString (Ids::prebuildCommand));
  78. settings.removeProperty (Ids::prebuildCommand, nullptr);
  79. if (oldStylePrebuildCommand.isNotEmpty())
  80. for (ConfigIterator config (*this); config.next();)
  81. dynamic_cast <MSVCBuildConfiguration&> (*config).getPrebuildCommand() = oldStylePrebuildCommand;
  82. }
  83. {
  84. const String oldStyleLibName (getSettingString ("libraryName_Debug"));
  85. settings.removeProperty ("libraryName_Debug", nullptr);
  86. if (oldStyleLibName.isNotEmpty())
  87. for (ConfigIterator config (*this); config.next();)
  88. if (config->isDebug())
  89. config->getTargetBinaryName() = oldStyleLibName;
  90. }
  91. {
  92. const String oldStyleLibName (getSettingString ("libraryName_Release"));
  93. settings.removeProperty ("libraryName_Release", nullptr);
  94. if (oldStyleLibName.isNotEmpty())
  95. for (ConfigIterator config (*this); config.next();)
  96. if (! config->isDebug())
  97. config->getTargetBinaryName() = oldStyleLibName;
  98. }
  99. }
  100. //==============================================================================
  101. class MSVCBuildConfiguration : public BuildConfiguration
  102. {
  103. public:
  104. MSVCBuildConfiguration (Project& project, const ValueTree& settings)
  105. : BuildConfiguration (project, settings)
  106. {
  107. if (getWarningLevel() == 0)
  108. getWarningLevelValue() = 4;
  109. setValueIfVoid (shouldGenerateManifestValue(), true);
  110. }
  111. Value getWarningLevelValue() { return getValue (Ids::winWarningLevel); }
  112. int getWarningLevel() const { return config [Ids::winWarningLevel]; }
  113. Value getPrebuildCommand() { return getValue (Ids::prebuildCommand); }
  114. String getPrebuildCommandString() const { return config [Ids::prebuildCommand]; }
  115. Value getPostbuildCommand() { return getValue (Ids::postbuildCommand); }
  116. String getPostbuildCommandString() const { return config [Ids::postbuildCommand]; }
  117. Value shouldGenerateManifestValue() { return getValue (Ids::generateManifest); }
  118. bool shouldGenerateManifest() const { return config [Ids::generateManifest]; }
  119. Value getWholeProgramOptValue() { return getValue (Ids::wholeProgramOptimisation); }
  120. bool shouldDisableWholeProgramOpt() const { return static_cast<int> (config [Ids::wholeProgramOptimisation]) > 0; }
  121. String getOutputFilename (const String& suffix, bool forceSuffix) const
  122. {
  123. const String target (File::createLegalFileName (getTargetBinaryNameString().trim()));
  124. if (forceSuffix || ! target.containsChar ('.'))
  125. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  126. return target;
  127. }
  128. void createPropertyEditors (PropertyListBuilder& props)
  129. {
  130. createBasicPropertyEditors (props);
  131. const char* const warningLevelNames[] = { "Low", "Medium", "High", nullptr };
  132. const int warningLevels[] = { 2, 3, 4, 0 };
  133. props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
  134. StringArray (warningLevelNames), Array<var> (warningLevels)));
  135. const char* const wpoNames[] = { "Enable link-time code generation when possible",
  136. "Always disable link-time code generation", nullptr };
  137. const var wpoValues[] = { var(), var (1) };
  138. props.add (new ChoicePropertyComponent (getWholeProgramOptValue(), "Whole Program Optimisation",
  139. StringArray (wpoNames), Array<var> (wpoValues, numElementsInArray (wpoValues))));
  140. props.add (new TextPropertyComponent (getPrebuildCommand(), "Pre-build Command", 2048, false));
  141. props.add (new TextPropertyComponent (getPostbuildCommand(), "Post-build Command", 2048, false));
  142. props.add (new BooleanPropertyComponent (shouldGenerateManifestValue(), "Manifest", "Generate Manifest"));
  143. }
  144. };
  145. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  146. {
  147. return new MSVCBuildConfiguration (project, settings);
  148. }
  149. static int getWarningLevel (const BuildConfiguration& config)
  150. {
  151. return dynamic_cast <const MSVCBuildConfiguration&> (config).getWarningLevel();
  152. }
  153. //==============================================================================
  154. String getIntermediatesPath (const BuildConfiguration& config) const
  155. {
  156. return prependDot (File::createLegalFileName (config.getName().trim()));
  157. }
  158. String getConfigTargetPath (const BuildConfiguration& config) const
  159. {
  160. const String binaryPath (config.getTargetBinaryRelativePathString().trim());
  161. if (binaryPath.isEmpty())
  162. return getIntermediatesPath (config);
  163. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  164. if (binaryRelPath.isAbsolute())
  165. return binaryRelPath.toWindowsStyle();
  166. return prependDot (binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  167. .toWindowsStyle());
  168. }
  169. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  170. {
  171. StringPairArray defines (msvcExtraPreprocessorDefs);
  172. defines.set ("WIN32", "");
  173. defines.set ("_WINDOWS", "");
  174. if (config.isDebug())
  175. {
  176. defines.set ("DEBUG", "");
  177. defines.set ("_DEBUG", "");
  178. }
  179. else
  180. {
  181. defines.set ("NDEBUG", "");
  182. }
  183. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  184. StringArray result;
  185. for (int i = 0; i < defines.size(); ++i)
  186. {
  187. String def (defines.getAllKeys()[i]);
  188. const String value (defines.getAllValues()[i]);
  189. if (value.isNotEmpty())
  190. def << "=" << value;
  191. result.add (def);
  192. }
  193. return result.joinIntoString (joinString);
  194. }
  195. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  196. {
  197. StringArray searchPaths (extraSearchPaths);
  198. searchPaths.addArray (config.getHeaderSearchPaths());
  199. searchPaths.removeDuplicates (false);
  200. return searchPaths;
  201. }
  202. virtual String createConfigName (const BuildConfiguration& config) const
  203. {
  204. return config.getName() + "|Win32";
  205. }
  206. //==============================================================================
  207. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString, const File& vcProject) const
  208. {
  209. if (commentString.isNotEmpty())
  210. commentString += newLine;
  211. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  212. << commentString
  213. << "Project(\"" << createGUID (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  214. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  215. << "EndProject" << newLine
  216. << "Global" << newLine
  217. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  218. for (ConstConfigIterator i (*this); i.next();)
  219. {
  220. const String configName (createConfigName (*i));
  221. out << "\t\t" << configName << " = " << configName << newLine;
  222. }
  223. out << "\tEndGlobalSection" << newLine
  224. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  225. for (ConstConfigIterator i (*this); i.next();)
  226. {
  227. const String configName (createConfigName (*i));
  228. out << "\t\t" << projectGUID << "." << configName << ".ActiveCfg = " << configName << newLine;
  229. out << "\t\t" << projectGUID << "." << configName << ".Build.0 = " << configName << newLine;
  230. }
  231. out << "\tEndGlobalSection" << newLine
  232. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  233. << "\t\tHideSolutionNode = FALSE" << newLine
  234. << "\tEndGlobalSection" << newLine
  235. << "EndGlobal" << newLine;
  236. }
  237. //==============================================================================
  238. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  239. {
  240. const int maskStride = (w / 8 + 3) & ~3;
  241. out.writeInt (40); // bitmapinfoheader size
  242. out.writeInt (w);
  243. out.writeInt (h * 2);
  244. out.writeShort (1); // planes
  245. out.writeShort (32); // bits
  246. out.writeInt (0); // compression
  247. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  248. out.writeInt (0); // x pixels per meter
  249. out.writeInt (0); // y pixels per meter
  250. out.writeInt (0); // clr used
  251. out.writeInt (0); // clr important
  252. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  253. const int alphaThreshold = 5;
  254. int y;
  255. for (y = h; --y >= 0;)
  256. {
  257. for (int x = 0; x < w; ++x)
  258. {
  259. const Colour pixel (bitmap.getPixelColour (x, y));
  260. if (pixel.getAlpha() <= alphaThreshold)
  261. {
  262. out.writeInt (0);
  263. }
  264. else
  265. {
  266. out.writeByte ((char) pixel.getBlue());
  267. out.writeByte ((char) pixel.getGreen());
  268. out.writeByte ((char) pixel.getRed());
  269. out.writeByte ((char) pixel.getAlpha());
  270. }
  271. }
  272. }
  273. for (y = h; --y >= 0;)
  274. {
  275. int mask = 0, count = 0;
  276. for (int x = 0; x < w; ++x)
  277. {
  278. const Colour pixel (bitmap.getPixelColour (x, y));
  279. mask <<= 1;
  280. if (pixel.getAlpha() <= alphaThreshold)
  281. mask |= 1;
  282. if (++count == 8)
  283. {
  284. out.writeByte ((char) mask);
  285. count = 0;
  286. mask = 0;
  287. }
  288. }
  289. if (mask != 0)
  290. out.writeByte ((char) mask);
  291. for (int i = maskStride - w / 8; --i >= 0;)
  292. out.writeByte (0);
  293. }
  294. }
  295. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  296. {
  297. out.writeShort (0); // reserved
  298. out.writeShort (1); // .ico tag
  299. out.writeShort ((short) images.size());
  300. MemoryOutputStream dataBlock;
  301. const int imageDirEntrySize = 16;
  302. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  303. for (int i = 0; i < images.size(); ++i)
  304. {
  305. const size_t oldDataSize = dataBlock.getDataSize();
  306. const Image& image = images.getReference (i);
  307. const int w = image.getWidth();
  308. const int h = image.getHeight();
  309. if (w >= 256 || h >= 256)
  310. {
  311. PNGImageFormat pngFormat;
  312. pngFormat.writeImageToStream (image, dataBlock);
  313. }
  314. else
  315. {
  316. writeBMPImage (image, w, h, dataBlock);
  317. }
  318. out.writeByte ((char) w);
  319. out.writeByte ((char) h);
  320. out.writeByte (0);
  321. out.writeByte (0);
  322. out.writeShort (1); // colour planes
  323. out.writeShort (32); // bits per pixel
  324. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  325. out.writeInt (dataBlockStart + oldDataSize);
  326. }
  327. jassert (out.getPosition() == dataBlockStart);
  328. out << dataBlock;
  329. }
  330. bool hasResourceFile() const
  331. {
  332. return ! projectType.isLibrary();
  333. }
  334. void createResourcesAndIcon() const
  335. {
  336. if (hasResourceFile())
  337. {
  338. Array<Image> images;
  339. const int sizes[] = { 16, 32, 48, 256 };
  340. for (int i = 0; i < numElementsInArray (sizes); ++i)
  341. {
  342. Image im (getBestIconForSize (sizes[i], true));
  343. if (im.isValid())
  344. images.add (im);
  345. }
  346. if (images.size() > 0)
  347. {
  348. iconFile = getTargetFolder().getChildFile ("icon.ico");
  349. MemoryOutputStream mo;
  350. writeIconFile (images, mo);
  351. overwriteFileIfDifferentOrThrow (iconFile, mo);
  352. }
  353. createRCFile();
  354. }
  355. }
  356. void createRCFile() const
  357. {
  358. rcFile = getTargetFolder().getChildFile ("resources.rc");
  359. const String version (project.getVersionString());
  360. MemoryOutputStream mo;
  361. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  362. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  363. << "#else" << newLine
  364. << newLine
  365. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  366. << "#define WIN32_LEAN_AND_MEAN" << newLine
  367. << "#include <windows.h>" << newLine
  368. << newLine
  369. << "VS_VERSION_INFO VERSIONINFO" << newLine
  370. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  371. << "BEGIN" << newLine
  372. << " BLOCK \"StringFileInfo\"" << newLine
  373. << " BEGIN" << newLine
  374. << " BLOCK \"040904E4\"" << newLine
  375. << " BEGIN" << newLine;
  376. writeRCValue (mo, "CompanyName", project.getCompanyName().toString());
  377. writeRCValue (mo, "FileDescription", project.getTitle());
  378. writeRCValue (mo, "FileVersion", version);
  379. writeRCValue (mo, "ProductName", project.getTitle());
  380. writeRCValue (mo, "ProductVersion", version);
  381. mo << " END" << newLine
  382. << " END" << newLine
  383. << newLine
  384. << " BLOCK \"VarFileInfo\"" << newLine
  385. << " BEGIN" << newLine
  386. << " VALUE \"Translation\", 0x409, 65001" << newLine
  387. << " END" << newLine
  388. << "END" << newLine
  389. << newLine
  390. << "#endif" << newLine;
  391. if (iconFile != File::nonexistent)
  392. mo << newLine
  393. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  394. overwriteFileIfDifferentOrThrow (rcFile, mo);
  395. }
  396. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  397. {
  398. if (value.isNotEmpty())
  399. mo << " VALUE \"" << name << "\", \""
  400. << CodeHelpers::addEscapeChars (value) << "\\0\"" << newLine;
  401. }
  402. static String getCommaSeparatedVersionNumber (const String& version)
  403. {
  404. StringArray versionParts;
  405. versionParts.addTokens (version, ",.", "");
  406. versionParts.trim();
  407. versionParts.removeEmptyStrings();
  408. while (versionParts.size() < 4)
  409. versionParts.add ("0");
  410. return versionParts.joinIntoString (",");
  411. }
  412. static String prependDot (const String& filename)
  413. {
  414. return FileHelpers::isAbsolutePath (filename) ? filename
  415. : (".\\" + filename);
  416. }
  417. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase);
  418. };
  419. //==============================================================================
  420. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  421. {
  422. public:
  423. //==============================================================================
  424. MSVCProjectExporterVC2008 (Project& project_, const ValueTree& settings_, const char* folderName = "VisualStudio2008")
  425. : MSVCProjectExporterBase (project_, settings_, folderName)
  426. {
  427. name = getName();
  428. }
  429. static const char* getName() { return "Visual Studio 2008"; }
  430. static const char* getValueTreeTypeName() { return "VS2008"; }
  431. int getVisualStudioVersion() const { return 9; }
  432. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  433. {
  434. if (settings.hasType (getValueTreeTypeName()))
  435. return new MSVCProjectExporterVC2008 (project, settings);
  436. return nullptr;
  437. }
  438. //==============================================================================
  439. void create (const OwnedArray<LibraryModule>&) const
  440. {
  441. createResourcesAndIcon();
  442. if (hasResourceFile())
  443. {
  444. for (int i = 0; i < getAllGroups().size(); ++i)
  445. {
  446. Project::Item& group = getAllGroups().getReference(i);
  447. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  448. {
  449. if (iconFile != File::nonexistent)
  450. {
  451. group.addFile (iconFile, -1, true);
  452. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  453. }
  454. group.addFile (rcFile, -1, true);
  455. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  456. break;
  457. }
  458. }
  459. }
  460. {
  461. XmlElement projectXml ("VisualStudioProject");
  462. fillInProjectXml (projectXml);
  463. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  464. }
  465. {
  466. MemoryOutputStream mo;
  467. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  468. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  469. }
  470. }
  471. protected:
  472. virtual String getProjectVersionString() const { return "9.00"; }
  473. virtual String getSolutionVersionString() const { return "10.00" + newLine + "# Visual C++ Express 2008"; }
  474. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  475. File getSLNFile() const { return getProjectFile (".sln"); }
  476. //==============================================================================
  477. void fillInProjectXml (XmlElement& projectXml) const
  478. {
  479. projectXml.setAttribute ("ProjectType", "Visual C++");
  480. projectXml.setAttribute ("Version", getProjectVersionString());
  481. projectXml.setAttribute ("Name", projectName);
  482. projectXml.setAttribute ("ProjectGUID", projectGUID);
  483. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  484. {
  485. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  486. XmlElement* platform = platforms->createNewChildElement ("Platform");
  487. platform->setAttribute ("Name", "Win32");
  488. }
  489. projectXml.createNewChildElement ("ToolFiles");
  490. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  491. projectXml.createNewChildElement ("References");
  492. createFiles (*projectXml.createNewChildElement ("Files"));
  493. projectXml.createNewChildElement ("Globals");
  494. }
  495. //==============================================================================
  496. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall) const
  497. {
  498. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  499. XmlElement* fileXml = parent.createNewChildElement ("File");
  500. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  501. if (excludeFromBuild || useStdcall)
  502. {
  503. for (ConstConfigIterator i (*this); i.next();)
  504. {
  505. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  506. fileConfig->setAttribute ("Name", createConfigName (*i));
  507. if (excludeFromBuild)
  508. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  509. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  510. if (useStdcall)
  511. tool->setAttribute ("CallingConvention", "2");
  512. }
  513. }
  514. }
  515. XmlElement* createGroup (const String& groupName, XmlElement& parent) const
  516. {
  517. XmlElement* filter = parent.createNewChildElement ("Filter");
  518. filter->setAttribute ("Name", groupName);
  519. return filter;
  520. }
  521. void addFiles (const Project::Item& projectItem, XmlElement& parent) const
  522. {
  523. if (projectItem.isGroup())
  524. {
  525. XmlElement* filter = createGroup (projectItem.getName(), parent);
  526. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  527. addFiles (projectItem.getChild(i), *filter);
  528. }
  529. else if (projectItem.shouldBeAddedToTargetProject())
  530. {
  531. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  532. addFile (path, parent,
  533. projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  534. shouldFileBeCompiledByDefault (path) && (bool) projectItem.shouldUseStdCall());
  535. }
  536. }
  537. void createFiles (XmlElement& files) const
  538. {
  539. for (int i = 0; i < getAllGroups().size(); ++i)
  540. {
  541. const Project::Item& group = getAllGroups().getReference(i);
  542. if (group.getNumChildren() > 0)
  543. addFiles (group, files);
  544. }
  545. }
  546. //==============================================================================
  547. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  548. {
  549. XmlElement* const e = parent.createNewChildElement ("Tool");
  550. e->setAttribute ("Name", toolName);
  551. return e;
  552. }
  553. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  554. {
  555. const bool isDebug = config.isDebug();
  556. xml.setAttribute ("Name", createConfigName (config));
  557. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (getConfigTargetPath (config)));
  558. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (getIntermediatesPath (config)));
  559. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isLibrary() ? "4" : "1"));
  560. xml.setAttribute ("UseOfMFC", "0");
  561. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  562. xml.setAttribute ("CharacterSet", "2");
  563. if (! (isDebug || config.shouldDisableWholeProgramOpt()))
  564. xml.setAttribute ("WholeProgramOptimization", "1");
  565. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  566. if (config.getPrebuildCommandString().isNotEmpty())
  567. {
  568. preBuildEvent->setAttribute ("Description", "Pre-build");
  569. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  570. }
  571. createToolElement (xml, "VCCustomBuildTool");
  572. createToolElement (xml, "VCXMLDataGeneratorTool");
  573. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  574. if (! projectType.isLibrary())
  575. {
  576. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  577. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  578. midl->setAttribute ("MkTypLibCompatible", "true");
  579. midl->setAttribute ("SuppressStartupBanner", "true");
  580. midl->setAttribute ("TargetEnvironment", "1");
  581. midl->setAttribute ("TypeLibraryName", getIntDirFile (config.getOutputFilename (".tlb", true)));
  582. midl->setAttribute ("HeaderFileName", "");
  583. }
  584. {
  585. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  586. const int optimiseLevel = config.getOptimisationLevelInt();
  587. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "1" : "2"));
  588. if (isDebug)
  589. {
  590. compiler->setAttribute ("BufferSecurityCheck", "");
  591. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  592. }
  593. else
  594. {
  595. compiler->setAttribute ("InlineFunctionExpansion", "1");
  596. compiler->setAttribute ("StringPooling", "true");
  597. }
  598. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  599. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  600. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  601. : (isDebug ? 1 : 0)); // MT static
  602. compiler->setAttribute ("RuntimeTypeInfo", "true");
  603. compiler->setAttribute ("UsePrecompiledHeader", "0");
  604. compiler->setAttribute ("PrecompiledHeaderFile", getIntDirFile (config.getOutputFilename (".pch", true)));
  605. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  606. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  607. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  608. compiler->setAttribute ("WarningLevel", String (getWarningLevel (config)));
  609. compiler->setAttribute ("SuppressStartupBanner", "true");
  610. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  611. if (extraFlags.isNotEmpty())
  612. compiler->setAttribute ("AdditionalOptions", extraFlags);
  613. }
  614. createToolElement (xml, "VCManagedResourceCompilerTool");
  615. {
  616. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  617. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  618. }
  619. createToolElement (xml, "VCPreLinkEventTool");
  620. if (! projectType.isLibrary())
  621. {
  622. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  623. linker->setAttribute ("OutputFile", getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
  624. linker->setAttribute ("SuppressStartupBanner", "true");
  625. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  626. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  627. linker->setAttribute ("ProgramDatabaseFile", getIntDirFile (config.getOutputFilename (".pdb", true)));
  628. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  629. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  630. if (librarySearchPaths.size() > 0)
  631. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  632. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  633. if (! isDebug)
  634. {
  635. linker->setAttribute ("OptimizeReferences", "2");
  636. linker->setAttribute ("EnableCOMDATFolding", "2");
  637. }
  638. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  639. if (msvcDelayLoadedDLLs.isNotEmpty())
  640. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  641. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  642. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  643. String extraLinkerOptions (getExtraLinkerFlagsString());
  644. if (extraLinkerOptions.isNotEmpty())
  645. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  646. }
  647. else
  648. {
  649. if (isLibraryDLL())
  650. {
  651. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  652. String extraLinkerOptions (getExtraLinkerFlagsString());
  653. extraLinkerOptions << " /IMPLIB:" << getOutDirFile (config.getOutputFilename (".lib", true));
  654. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  655. linker->setAttribute ("OutputFile", getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
  656. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  657. }
  658. else
  659. {
  660. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  661. librarian->setAttribute ("OutputFile", getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
  662. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  663. }
  664. }
  665. createToolElement (xml, "VCALinkTool");
  666. createToolElement (xml, "VCManifestTool");
  667. createToolElement (xml, "VCXDCMakeTool");
  668. {
  669. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  670. bscMake->setAttribute ("SuppressStartupBanner", "true");
  671. bscMake->setAttribute ("OutputFile", getIntDirFile (config.getOutputFilename (".bsc", true)));
  672. }
  673. createToolElement (xml, "VCFxCopTool");
  674. if (! projectType.isLibrary())
  675. createToolElement (xml, "VCAppVerifierTool");
  676. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  677. if (config.getPostbuildCommandString().isNotEmpty())
  678. {
  679. postBuildEvent->setAttribute ("Description", "Post-build");
  680. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  681. }
  682. }
  683. void createConfigs (XmlElement& xml) const
  684. {
  685. for (ConstConfigIterator config (*this); config.next();)
  686. createConfig (*xml.createNewChildElement ("Configuration"),
  687. dynamic_cast <const MSVCBuildConfiguration&> (*config));
  688. }
  689. //==============================================================================
  690. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  691. };
  692. //==============================================================================
  693. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  694. {
  695. public:
  696. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  697. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  698. {
  699. name = getName();
  700. }
  701. static const char* getName() { return "Visual Studio 2005"; }
  702. static const char* getValueTreeTypeName() { return "VS2005"; }
  703. int getVisualStudioVersion() const { return 8; }
  704. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  705. {
  706. if (settings.hasType (getValueTreeTypeName()))
  707. return new MSVCProjectExporterVC2005 (project, settings);
  708. return nullptr;
  709. }
  710. protected:
  711. String getProjectVersionString() const { return "8.00"; }
  712. String getSolutionVersionString() const { return "9.00" + newLine + "# Visual C++ Express 2005"; }
  713. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  714. };
  715. //==============================================================================
  716. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  717. {
  718. public:
  719. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  720. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  721. {
  722. name = getName();
  723. }
  724. static const char* getName() { return "Visual Studio 2010"; }
  725. static const char* getValueTreeTypeName() { return "VS2010"; }
  726. int getVisualStudioVersion() const { return 10; }
  727. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  728. {
  729. if (settings.hasType (getValueTreeTypeName()))
  730. return new MSVCProjectExporterVC2010 (project, settings);
  731. return nullptr;
  732. }
  733. //==============================================================================
  734. void create (const OwnedArray<LibraryModule>&) const
  735. {
  736. createResourcesAndIcon();
  737. {
  738. XmlElement projectXml ("Project");
  739. fillInProjectXml (projectXml);
  740. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  741. }
  742. {
  743. XmlElement filtersXml ("Project");
  744. fillInFiltersXml (filtersXml);
  745. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  746. }
  747. {
  748. MemoryOutputStream mo;
  749. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  750. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  751. }
  752. }
  753. protected:
  754. //==============================================================================
  755. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  756. {
  757. public:
  758. VC2010BuildConfiguration (Project& project, const ValueTree& settings)
  759. : MSVCBuildConfiguration (project, settings)
  760. {
  761. if (getArchitectureType().toString().isEmpty())
  762. getArchitectureType() = get32BitArchName();
  763. }
  764. //==============================================================================
  765. static const char* get32BitArchName() { return "32-bit"; }
  766. static const char* get64BitArchName() { return "x64"; }
  767. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  768. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  769. //==============================================================================
  770. void createPropertyEditors (PropertyListBuilder& props)
  771. {
  772. MSVCBuildConfiguration::createPropertyEditors (props);
  773. const char* const archTypes[] = { get32BitArchName(), get64BitArchName(), nullptr };
  774. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  775. StringArray (archTypes), Array<var> (archTypes)));
  776. }
  777. };
  778. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  779. {
  780. return new VC2010BuildConfiguration (project, settings);
  781. }
  782. static bool is64Bit (const BuildConfiguration& config)
  783. {
  784. return dynamic_cast <const VC2010BuildConfiguration&> (config).is64Bit();
  785. }
  786. //==============================================================================
  787. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  788. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  789. File getSLNFile() const { return getProjectFile (".sln"); }
  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 (msvcNeedsDLLRuntimeLib ? (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__