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.

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