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.

1602 lines
70KB

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