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.

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