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.

1541 lines
67KB

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