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.

1592 lines
68KB

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