The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1541 lines
67KB

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