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.

1419 lines
61KB

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