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.

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