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.

1654 lines
72KB

  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. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  65. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, 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 getWarningsTreatedAsErrors() { return getValue (Ids::warningsAreErrors); }
  106. bool areWarningsTreatedAsErrors() const { return config [Ids::warningsAreErrors]; }
  107. Value getPrebuildCommand() { return getValue (Ids::prebuildCommand); }
  108. String getPrebuildCommandString() const { return config [Ids::prebuildCommand]; }
  109. Value getPostbuildCommand() { return getValue (Ids::postbuildCommand); }
  110. String getPostbuildCommandString() const { return config [Ids::postbuildCommand]; }
  111. Value shouldGenerateDebugSymbolsValue() { return getValue (Ids::alwaysGenerateDebugSymbols); }
  112. bool shouldGenerateDebugSymbols() const { return config [Ids::alwaysGenerateDebugSymbols]; }
  113. Value shouldGenerateManifestValue() { return getValue (Ids::generateManifest); }
  114. bool shouldGenerateManifest() const { return config [Ids::generateManifest]; }
  115. Value getWholeProgramOptValue() { return getValue (Ids::wholeProgramOptimisation); }
  116. bool shouldDisableWholeProgramOpt() const { return static_cast<int> (config [Ids::wholeProgramOptimisation]) > 0; }
  117. Value getUsingRuntimeLibDLL() { return getValue (Ids::useRuntimeLibDLL); }
  118. bool isUsingRuntimeLibDLL() const { return config [Ids::useRuntimeLibDLL]; }
  119. String getIntermediatesPath() const { return config [Ids::intermediatesPath].toString(); }
  120. Value getIntermediatesPathValue() { return getValue (Ids::intermediatesPath); }
  121. String getCharacterSet() const { return config [Ids::characterSet].toString(); }
  122. Value getCharacterSetValue() { return getValue (Ids::characterSet); }
  123. String getOutputFilename (const String& suffix, bool forceSuffix) const
  124. {
  125. const String target (File::createLegalFileName (getTargetBinaryNameString().trim()));
  126. if (forceSuffix || ! target.containsChar ('.'))
  127. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  128. return target;
  129. }
  130. void createConfigProperties (PropertyListBuilder& props) override
  131. {
  132. props.add (new TextPropertyComponent (getIntermediatesPathValue(), "Intermediates path", 2048, false),
  133. "An optional path to a folder to use for the intermediate build files. Note that Visual Studio allows "
  134. "you to use macros in this path, e.g. \"$(TEMP)\\MyAppBuildFiles\\$(Configuration)\", which is a handy way to "
  135. "send them to the user's temp folder.");
  136. static const char* warningLevelNames[] = { "Low", "Medium", "High", nullptr };
  137. const int warningLevels[] = { 2, 3, 4 };
  138. props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
  139. StringArray (warningLevelNames), Array<var> (warningLevels, numElementsInArray (warningLevels))));
  140. props.add (new BooleanPropertyComponent (getWarningsTreatedAsErrors(), "Warnings", "Treat warnings as errors"));
  141. {
  142. static const char* runtimeNames[] = { "(Default)", "Use static runtime", "Use DLL runtime", nullptr };
  143. const var runtimeValues[] = { var(), var (false), var (true) };
  144. props.add (new ChoicePropertyComponent (getUsingRuntimeLibDLL(), "Runtime Library",
  145. StringArray (runtimeNames), Array<var> (runtimeValues, numElementsInArray (runtimeValues))));
  146. }
  147. {
  148. static const char* wpoNames[] = { "Enable link-time code generation when possible",
  149. "Always disable link-time code generation", nullptr };
  150. const var wpoValues[] = { var(), var (1) };
  151. props.add (new ChoicePropertyComponent (getWholeProgramOptValue(), "Whole Program Optimisation",
  152. StringArray (wpoNames), Array<var> (wpoValues, numElementsInArray (wpoValues))));
  153. }
  154. if (! isDebug())
  155. props.add (new BooleanPropertyComponent (shouldGenerateDebugSymbolsValue(), "Debug Symbols", "Force generation of debug symbols"));
  156. props.add (new TextPropertyComponent (getPrebuildCommand(), "Pre-build Command", 2048, true));
  157. props.add (new TextPropertyComponent (getPostbuildCommand(), "Post-build Command", 2048, true));
  158. props.add (new BooleanPropertyComponent (shouldGenerateManifestValue(), "Manifest", "Generate Manifest"));
  159. {
  160. static const char* characterSetNames[] = { "Default", "MultiByte", "Unicode", nullptr };
  161. const var charSets[] = { var::null, "MultiByte", "Unicode", };
  162. props.add (new ChoicePropertyComponent (getCharacterSetValue(), "Character Set",
  163. StringArray (characterSetNames), Array<var> (charSets, numElementsInArray (charSets))));
  164. }
  165. }
  166. };
  167. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  168. {
  169. return new MSVCBuildConfiguration (project, v);
  170. }
  171. //==============================================================================
  172. String getConfigTargetPath (const BuildConfiguration& config) const
  173. {
  174. const String binaryPath (config.getTargetBinaryRelativePathString().trim());
  175. if (binaryPath.isEmpty())
  176. return binaryPath;
  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 + (int) 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. << CppTokeniserFunctions::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& p, const ValueTree& s,
  441. const char* folderName = "VisualStudio2008")
  442. : MSVCProjectExporterBase (p, s, 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 override { 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 String ("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. if (getConfigTargetPath (config).isNotEmpty())
  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, 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, config.getOutputFilename (".pch", true)));
  623. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  624. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  625. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  626. compiler->setAttribute ("WarningLevel", String (config.getWarningLevel()));
  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, 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, 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, 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, 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, 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, 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 getSolutionComment() const { return "# Visual Studio 2010"; }
  761. virtual String getToolsVersion() const { return "4.0"; }
  762. virtual String getDefaultToolset() const { return "Windows7.1SDK"; }
  763. Value getPlatformToolsetValue() { return getSetting (Ids::toolset); }
  764. String getPlatformToolset() const
  765. {
  766. const String s (settings [Ids::toolset].toString());
  767. return s.isNotEmpty() ? s : getDefaultToolset();
  768. }
  769. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  770. {
  771. if (settings.hasType (getValueTreeTypeName()))
  772. return new MSVCProjectExporterVC2010 (project, settings);
  773. return nullptr;
  774. }
  775. void createExporterProperties (PropertyListBuilder& props) override
  776. {
  777. MSVCProjectExporterBase::createExporterProperties (props);
  778. static const char* toolsetNames[] = { "(default)", "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  779. const var toolsets[] = { var(), "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  780. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  781. StringArray (toolsetNames),
  782. Array<var> (toolsets, numElementsInArray (toolsets))));
  783. }
  784. //==============================================================================
  785. void create (const OwnedArray<LibraryModule>&) const
  786. {
  787. createResourcesAndIcon();
  788. {
  789. XmlElement projectXml ("Project");
  790. fillInProjectXml (projectXml);
  791. addPlatformToolsetToPropertyGroup (projectXml);
  792. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  793. }
  794. {
  795. XmlElement filtersXml ("Project");
  796. fillInFiltersXml (filtersXml);
  797. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  798. }
  799. {
  800. MemoryOutputStream mo;
  801. writeSolutionFile (mo, "11.00", getSolutionComment(), getVCProjFile());
  802. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  803. }
  804. }
  805. protected:
  806. //==============================================================================
  807. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  808. {
  809. public:
  810. VC2010BuildConfiguration (Project& p, const ValueTree& settings)
  811. : MSVCBuildConfiguration (p, settings)
  812. {
  813. if (getArchitectureType().toString().isEmpty())
  814. getArchitectureType() = get32BitArchName();
  815. }
  816. //==============================================================================
  817. static const char* get32BitArchName() { return "32-bit"; }
  818. static const char* get64BitArchName() { return "x64"; }
  819. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  820. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  821. Value getFastMathValue() { return getValue (Ids::fastMath); }
  822. bool isFastMathEnabled() const { return config [Ids::fastMath]; }
  823. //==============================================================================
  824. void createConfigProperties (PropertyListBuilder& props) override
  825. {
  826. MSVCBuildConfiguration::createConfigProperties (props);
  827. const char* const archTypes[] = { get32BitArchName(), get64BitArchName() };
  828. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  829. StringArray (archTypes, numElementsInArray (archTypes)),
  830. Array<var> (archTypes, numElementsInArray (archTypes))));
  831. props.add (new BooleanPropertyComponent (getFastMathValue(), "Relax IEEE compliance", "Enabled"),
  832. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  833. }
  834. };
  835. virtual void addPlatformToolsetToPropertyGroup (XmlElement&) const {}
  836. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const
  837. {
  838. return new VC2010BuildConfiguration (project, v);
  839. }
  840. static bool is64Bit (const BuildConfiguration& config)
  841. {
  842. return dynamic_cast<const VC2010BuildConfiguration&> (config).is64Bit();
  843. }
  844. //==============================================================================
  845. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  846. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  847. String createConfigName (const BuildConfiguration& config) const
  848. {
  849. return config.getName() + (is64Bit (config) ? "|x64"
  850. : "|Win32");
  851. }
  852. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  853. {
  854. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  855. }
  856. //==============================================================================
  857. void fillInProjectXml (XmlElement& projectXml) const
  858. {
  859. projectXml.setAttribute ("DefaultTargets", "Build");
  860. projectXml.setAttribute ("ToolsVersion", getToolsVersion());
  861. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  862. {
  863. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  864. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  865. for (ConstConfigIterator config (*this); config.next();)
  866. {
  867. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  868. e->setAttribute ("Include", createConfigName (*config));
  869. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  870. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  871. }
  872. }
  873. {
  874. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  875. globals->setAttribute ("Label", "Globals");
  876. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  877. }
  878. {
  879. XmlElement* imports = projectXml.createNewChildElement ("Import");
  880. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  881. }
  882. for (ConstConfigIterator i (*this); i.next();)
  883. {
  884. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  885. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  886. setConditionAttribute (*e, config);
  887. e->setAttribute ("Label", "Configuration");
  888. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  889. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  890. const String charSet (config.getCharacterSet());
  891. if (charSet.isNotEmpty())
  892. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  893. if (! (config.isDebug() || config.shouldDisableWholeProgramOpt()))
  894. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  895. if (config.is64Bit())
  896. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  897. }
  898. {
  899. XmlElement* e = projectXml.createNewChildElement ("Import");
  900. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  901. }
  902. {
  903. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  904. e->setAttribute ("Label", "ExtensionSettings");
  905. }
  906. {
  907. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  908. e->setAttribute ("Label", "PropertySheets");
  909. XmlElement* p = e->createNewChildElement ("Import");
  910. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  911. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  912. p->setAttribute ("Label", "LocalAppDataPlatform");
  913. }
  914. {
  915. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  916. e->setAttribute ("Label", "UserMacros");
  917. }
  918. {
  919. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  920. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  921. for (ConstConfigIterator i (*this); i.next();)
  922. {
  923. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  924. if (getConfigTargetPath (config).isNotEmpty())
  925. {
  926. XmlElement* outdir = props->createNewChildElement ("OutDir");
  927. setConditionAttribute (*outdir, config);
  928. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  929. }
  930. if (config.getIntermediatesPath().isNotEmpty())
  931. {
  932. XmlElement* intdir = props->createNewChildElement ("IntDir");
  933. setConditionAttribute (*intdir, config);
  934. intdir->addTextElement (FileHelpers::windowsStylePath (config.getIntermediatesPath()) + "\\");
  935. }
  936. {
  937. XmlElement* targetName = props->createNewChildElement ("TargetName");
  938. setConditionAttribute (*targetName, config);
  939. targetName->addTextElement (config.getOutputFilename (String::empty, true));
  940. }
  941. {
  942. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  943. setConditionAttribute (*manifest, config);
  944. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  945. }
  946. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  947. if (librarySearchPaths.size() > 0)
  948. {
  949. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  950. setConditionAttribute (*libPath, config);
  951. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  952. }
  953. }
  954. }
  955. for (ConstConfigIterator i (*this); i.next();)
  956. {
  957. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  958. const bool isDebug = config.isDebug();
  959. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  960. setConditionAttribute (*group, config);
  961. {
  962. XmlElement* midl = group->createNewChildElement ("Midl");
  963. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  964. : "NDEBUG;%(PreprocessorDefinitions)");
  965. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  966. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  967. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  968. midl->createNewChildElement ("HeaderFileName");
  969. }
  970. bool isUsingEditAndContinue = false;
  971. {
  972. XmlElement* cl = group->createNewChildElement ("ClCompile");
  973. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  974. if (isDebug && config.getOptimisationLevelInt() <= optimisationOff)
  975. {
  976. isUsingEditAndContinue = ! config.is64Bit();
  977. cl->createNewChildElement ("DebugInformationFormat")
  978. ->addTextElement (isUsingEditAndContinue ? "EditAndContinue"
  979. : "ProgramDatabase");
  980. }
  981. StringArray includePaths (getHeaderSearchPaths (config));
  982. includePaths.add ("%(AdditionalIncludeDirectories)");
  983. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  984. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  985. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (config.isUsingRuntimeLibDLL() ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  986. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  987. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  988. cl->createNewChildElement ("PrecompiledHeader");
  989. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  990. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  991. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  992. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  993. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  994. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  995. if (config.isFastMathEnabled())
  996. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  997. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  998. if (extraFlags.isNotEmpty())
  999. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1000. if (config.areWarningsTreatedAsErrors())
  1001. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  1002. }
  1003. {
  1004. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1005. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1006. : "NDEBUG;%(PreprocessorDefinitions)");
  1007. }
  1008. {
  1009. XmlElement* link = group->createNewChildElement ("Link");
  1010. link->createNewChildElement ("OutputFile")->addTextElement (getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  1011. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1012. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1013. : "%(IgnoreSpecificDefaultLibraries)");
  1014. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  1015. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  1016. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  1017. if (! config.is64Bit())
  1018. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1019. if (isUsingEditAndContinue)
  1020. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  1021. if (! isDebug)
  1022. {
  1023. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1024. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1025. }
  1026. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1027. if (librarySearchPaths.size() > 0)
  1028. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";"))
  1029. + ";%(AdditionalLibraryDirectories)");
  1030. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  1031. String externalLibraries (getExternalLibrariesString());
  1032. if (externalLibraries.isNotEmpty())
  1033. link->createNewChildElement ("AdditionalDependencies")->addTextElement (replacePreprocessorTokens (config, externalLibraries).trim()
  1034. + ";%(AdditionalDependencies)");
  1035. String extraLinkerOptions (getExtraLinkerFlagsString());
  1036. if (extraLinkerOptions.isNotEmpty())
  1037. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1038. + " %(AdditionalOptions)");
  1039. if (msvcDelayLoadedDLLs.isNotEmpty())
  1040. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  1041. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  1042. link->createNewChildElement ("ModuleDefinitionFile")
  1043. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  1044. }
  1045. {
  1046. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1047. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1048. bsc->createNewChildElement ("OutputFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  1049. }
  1050. if (config.getPrebuildCommandString().isNotEmpty())
  1051. group->createNewChildElement ("PreBuildEvent")
  1052. ->createNewChildElement ("Command")
  1053. ->addTextElement (config.getPrebuildCommandString());
  1054. if (config.getPostbuildCommandString().isNotEmpty())
  1055. group->createNewChildElement ("PostBuildEvent")
  1056. ->createNewChildElement ("Command")
  1057. ->addTextElement (config.getPostbuildCommandString());
  1058. }
  1059. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1060. {
  1061. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1062. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1063. for (int i = 0; i < getAllGroups().size(); ++i)
  1064. {
  1065. const Project::Item& group = getAllGroups().getReference(i);
  1066. if (group.getNumChildren() > 0)
  1067. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  1068. }
  1069. }
  1070. if (iconFile != File::nonexistent)
  1071. {
  1072. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1073. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1074. }
  1075. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1076. projectXml.addChildElement (otherFilesGroup.release());
  1077. if (hasResourceFile())
  1078. {
  1079. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1080. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1081. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1082. }
  1083. {
  1084. XmlElement* e = projectXml.createNewChildElement ("Import");
  1085. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1086. }
  1087. {
  1088. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1089. e->setAttribute ("Label", "ExtensionTargets");
  1090. }
  1091. }
  1092. String getProjectType() const
  1093. {
  1094. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1095. if (isLibraryDLL()) return "DynamicLibrary";
  1096. if (projectType.isStaticLibrary()) return "StaticLibrary";
  1097. jassertfalse;
  1098. return String::empty;
  1099. }
  1100. static const char* getOptimisationLevelString (int level)
  1101. {
  1102. switch (level)
  1103. {
  1104. case optimiseMaxSpeed: return "Full";
  1105. case optimiseMinSize: return "MinSpace";
  1106. default: return "Disabled";
  1107. }
  1108. }
  1109. //==============================================================================
  1110. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1111. {
  1112. if (projectItem.isGroup())
  1113. {
  1114. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1115. addFilesToCompile (projectItem.getChild(i), cpps, headers, otherFiles);
  1116. }
  1117. else if (projectItem.shouldBeAddedToTargetProject())
  1118. {
  1119. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1120. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1121. if (path.hasFileExtension (cOrCppFileExtensions))
  1122. {
  1123. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1124. e->setAttribute ("Include", path.toWindowsStyle());
  1125. if (! projectItem.shouldBeCompiled())
  1126. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1127. if (projectItem.shouldUseStdCall())
  1128. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1129. }
  1130. else if (path.hasFileExtension (headerFileExtensions))
  1131. {
  1132. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  1133. }
  1134. else if (! path.hasFileExtension (objCFileExtensions))
  1135. {
  1136. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  1137. }
  1138. }
  1139. }
  1140. //==============================================================================
  1141. void addFilterGroup (XmlElement& groups, const String& path) const
  1142. {
  1143. XmlElement* e = groups.createNewChildElement ("Filter");
  1144. e->setAttribute ("Include", path);
  1145. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1146. }
  1147. void addFileToFilter (const RelativePath& file, const String& groupPath,
  1148. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1149. {
  1150. XmlElement* e;
  1151. if (file.hasFileExtension (headerFileExtensions))
  1152. e = headers.createNewChildElement ("ClInclude");
  1153. else if (file.hasFileExtension (sourceFileExtensions))
  1154. e = cpps.createNewChildElement ("ClCompile");
  1155. else
  1156. e = otherFiles.createNewChildElement ("None");
  1157. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1158. e->setAttribute ("Include", file.toWindowsStyle());
  1159. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1160. }
  1161. void addFilesToFilter (const Project::Item& projectItem, const String& path,
  1162. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  1163. {
  1164. if (projectItem.isGroup())
  1165. {
  1166. addFilterGroup (groups, path);
  1167. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1168. addFilesToFilter (projectItem.getChild(i),
  1169. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1170. cpps, headers, otherFiles, groups);
  1171. }
  1172. else if (projectItem.shouldBeAddedToTargetProject())
  1173. {
  1174. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1175. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  1176. }
  1177. }
  1178. void addFilesToFilter (const Array<RelativePath>& files, const String& path,
  1179. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  1180. {
  1181. if (files.size() > 0)
  1182. {
  1183. addFilterGroup (groups, path);
  1184. for (int i = 0; i < files.size(); ++i)
  1185. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  1186. }
  1187. }
  1188. void fillInFiltersXml (XmlElement& filterXml) const
  1189. {
  1190. filterXml.setAttribute ("ToolsVersion", getToolsVersion());
  1191. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1192. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1193. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1194. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1195. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1196. for (int i = 0; i < getAllGroups().size(); ++i)
  1197. {
  1198. const Project::Item& group = getAllGroups().getReference(i);
  1199. if (group.getNumChildren() > 0)
  1200. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  1201. }
  1202. if (iconFile.exists())
  1203. {
  1204. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1205. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1206. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1207. }
  1208. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1209. filterXml.addChildElement (otherFilesGroup.release());
  1210. if (hasResourceFile())
  1211. {
  1212. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1213. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1214. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1215. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1216. }
  1217. }
  1218. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010)
  1219. };
  1220. //==============================================================================
  1221. class MSVCProjectExporterVC2012 : public MSVCProjectExporterVC2010
  1222. {
  1223. public:
  1224. MSVCProjectExporterVC2012 (Project& p, const ValueTree& t,
  1225. const char* folderName = "VisualStudio2012")
  1226. : MSVCProjectExporterVC2010 (p, t, folderName)
  1227. {
  1228. name = getName();
  1229. }
  1230. static const char* getName() { return "Visual Studio 2012"; }
  1231. static const char* getValueTreeTypeName() { return "VS2012"; }
  1232. int getVisualStudioVersion() const override { return 11; }
  1233. String getSolutionComment() const override { return "# Visual Studio 2012"; }
  1234. virtual String getDefaultToolset() const { return "v110"; }
  1235. static MSVCProjectExporterVC2012* createForSettings (Project& project, const ValueTree& settings)
  1236. {
  1237. if (settings.hasType (getValueTreeTypeName()))
  1238. return new MSVCProjectExporterVC2012 (project, settings);
  1239. return nullptr;
  1240. }
  1241. void createExporterProperties (PropertyListBuilder& props) override
  1242. {
  1243. MSVCProjectExporterBase::createExporterProperties (props);
  1244. static const char* toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1245. const var toolsets[] = { var(), "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1246. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1247. StringArray (toolsetNames),
  1248. Array<var> (toolsets, numElementsInArray (toolsets))));
  1249. }
  1250. private:
  1251. void addPlatformToolsetToPropertyGroup (XmlElement& p) const override
  1252. {
  1253. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1254. {
  1255. XmlElement* platformToolset (new XmlElement ("PlatformToolset"));
  1256. platformToolset->addTextElement (getPlatformToolset());
  1257. e->addChildElement (platformToolset);
  1258. }
  1259. }
  1260. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2012)
  1261. };
  1262. //==============================================================================
  1263. class MSVCProjectExporterVC2013 : public MSVCProjectExporterVC2012
  1264. {
  1265. public:
  1266. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1267. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2013")
  1268. {
  1269. name = getName();
  1270. }
  1271. static const char* getName() { return "Visual Studio 2013"; }
  1272. static const char* getValueTreeTypeName() { return "VS2013"; }
  1273. int getVisualStudioVersion() const override { return 12; }
  1274. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1275. String getToolsVersion() const override { return "12.0"; }
  1276. String getDefaultToolset() const override { return "v120"; }
  1277. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1278. {
  1279. if (settings.hasType (getValueTreeTypeName()))
  1280. return new MSVCProjectExporterVC2013 (project, settings);
  1281. return nullptr;
  1282. }
  1283. void createExporterProperties (PropertyListBuilder& props) override
  1284. {
  1285. MSVCProjectExporterBase::createExporterProperties (props);
  1286. static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1287. const var toolsets[] = { var(), "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1288. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1289. StringArray (toolsetNames),
  1290. Array<var> (toolsets, numElementsInArray (toolsets))));
  1291. }
  1292. private:
  1293. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1294. };
  1295. //==============================================================================
  1296. class MSVCProjectExporterVC2015 : public MSVCProjectExporterVC2012
  1297. {
  1298. public:
  1299. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1300. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2015")
  1301. {
  1302. name = getName();
  1303. }
  1304. static const char* getName() { return "Visual Studio 2015"; }
  1305. static const char* getValueTreeTypeName() { return "VS2015"; }
  1306. int getVisualStudioVersion() const override { return 14; }
  1307. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1308. String getToolsVersion() const override { return "14.0"; }
  1309. String getDefaultToolset() const override { return "v140"; }
  1310. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1311. {
  1312. if (settings.hasType (getValueTreeTypeName()))
  1313. return new MSVCProjectExporterVC2015 (project, settings);
  1314. return nullptr;
  1315. }
  1316. void createExporterProperties (PropertyListBuilder& props) override
  1317. {
  1318. MSVCProjectExporterBase::createExporterProperties (props);
  1319. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", nullptr };
  1320. const var toolsets[] = { var(), "v140", "v140_xp" };
  1321. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1322. StringArray (toolsetNames),
  1323. Array<var> (toolsets, numElementsInArray (toolsets))));
  1324. }
  1325. private:
  1326. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1327. };