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.

1403 lines
59KB

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