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.

1521 lines
66KB

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