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.

1430 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 < getAllGroups().size(); ++i)
  447. {
  448. Project::Item& group = getAllGroups().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 < getAllGroups().size(); ++i)
  542. {
  543. const Project::Item& group = getAllGroups().getReference(i);
  544. if (group.getNumChildren() > 0)
  545. addFiles (group, files);
  546. }
  547. }
  548. //==============================================================================
  549. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  550. {
  551. XmlElement* const e = parent.createNewChildElement ("Tool");
  552. e->setAttribute ("Name", toolName);
  553. return e;
  554. }
  555. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  556. {
  557. const bool isDebug = config.isDebug();
  558. xml.setAttribute ("Name", createConfigName (config));
  559. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (getConfigTargetPath (config)));
  560. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (getIntermediatesPath (config)));
  561. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isLibrary() ? "4" : "1"));
  562. xml.setAttribute ("UseOfMFC", "0");
  563. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  564. xml.setAttribute ("CharacterSet", "2");
  565. if (! (isDebug || config.shouldDisableWholeProgramOpt()))
  566. xml.setAttribute ("WholeProgramOptimization", "1");
  567. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  568. if (config.getPrebuildCommandString().isNotEmpty())
  569. {
  570. preBuildEvent->setAttribute ("Description", "Pre-build");
  571. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  572. }
  573. createToolElement (xml, "VCCustomBuildTool");
  574. createToolElement (xml, "VCXMLDataGeneratorTool");
  575. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  576. if (! projectType.isLibrary())
  577. {
  578. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  579. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  580. midl->setAttribute ("MkTypLibCompatible", "true");
  581. midl->setAttribute ("SuppressStartupBanner", "true");
  582. midl->setAttribute ("TargetEnvironment", "1");
  583. midl->setAttribute ("TypeLibraryName", getIntDirFile (config.getOutputFilename (".tlb", true)));
  584. midl->setAttribute ("HeaderFileName", "");
  585. }
  586. {
  587. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  588. const int optimiseLevel = config.getOptimisationLevelInt();
  589. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "1" : "2"));
  590. if (isDebug)
  591. {
  592. compiler->setAttribute ("BufferSecurityCheck", "");
  593. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  594. }
  595. else
  596. {
  597. compiler->setAttribute ("InlineFunctionExpansion", "1");
  598. compiler->setAttribute ("StringPooling", "true");
  599. }
  600. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  601. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  602. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  603. : (isDebug ? 1 : 0)); // MT static
  604. compiler->setAttribute ("RuntimeTypeInfo", "true");
  605. compiler->setAttribute ("UsePrecompiledHeader", "0");
  606. compiler->setAttribute ("PrecompiledHeaderFile", getIntDirFile (config.getOutputFilename (".pch", true)));
  607. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  608. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  609. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  610. compiler->setAttribute ("WarningLevel", String (getWarningLevel (config)));
  611. compiler->setAttribute ("SuppressStartupBanner", "true");
  612. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  613. if (extraFlags.isNotEmpty())
  614. compiler->setAttribute ("AdditionalOptions", extraFlags);
  615. }
  616. createToolElement (xml, "VCManagedResourceCompilerTool");
  617. {
  618. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  619. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  620. }
  621. createToolElement (xml, "VCPreLinkEventTool");
  622. if (! projectType.isLibrary())
  623. {
  624. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  625. linker->setAttribute ("OutputFile", getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
  626. linker->setAttribute ("SuppressStartupBanner", "true");
  627. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  628. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  629. linker->setAttribute ("ProgramDatabaseFile", getIntDirFile (config.getOutputFilename (".pdb", true)));
  630. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  631. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  632. if (librarySearchPaths.size() > 0)
  633. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  634. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  635. if (! isDebug)
  636. {
  637. linker->setAttribute ("OptimizeReferences", "2");
  638. linker->setAttribute ("EnableCOMDATFolding", "2");
  639. }
  640. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  641. if (msvcDelayLoadedDLLs.isNotEmpty())
  642. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  643. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  644. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  645. String extraLinkerOptions (getExtraLinkerFlagsString());
  646. if (extraLinkerOptions.isNotEmpty())
  647. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  648. }
  649. else
  650. {
  651. if (isLibraryDLL())
  652. {
  653. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  654. String extraLinkerOptions (getExtraLinkerFlagsString());
  655. extraLinkerOptions << " /IMPLIB:" << getOutDirFile (config.getOutputFilename (".lib", true));
  656. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  657. linker->setAttribute ("OutputFile", getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
  658. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  659. }
  660. else
  661. {
  662. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  663. librarian->setAttribute ("OutputFile", getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
  664. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  665. }
  666. }
  667. createToolElement (xml, "VCALinkTool");
  668. createToolElement (xml, "VCManifestTool");
  669. createToolElement (xml, "VCXDCMakeTool");
  670. {
  671. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  672. bscMake->setAttribute ("SuppressStartupBanner", "true");
  673. bscMake->setAttribute ("OutputFile", getIntDirFile (config.getOutputFilename (".bsc", true)));
  674. }
  675. createToolElement (xml, "VCFxCopTool");
  676. if (! projectType.isLibrary())
  677. createToolElement (xml, "VCAppVerifierTool");
  678. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  679. if (config.getPostbuildCommandString().isNotEmpty())
  680. {
  681. postBuildEvent->setAttribute ("Description", "Post-build");
  682. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  683. }
  684. }
  685. void createConfigs (XmlElement& xml) const
  686. {
  687. for (ConstConfigIterator config (*this); config.next();)
  688. createConfig (*xml.createNewChildElement ("Configuration"),
  689. dynamic_cast <const MSVCBuildConfiguration&> (*config));
  690. }
  691. //==============================================================================
  692. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  693. };
  694. //==============================================================================
  695. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  696. {
  697. public:
  698. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  699. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  700. {
  701. name = getName();
  702. }
  703. static const char* getName() { return "Visual Studio 2005"; }
  704. static const char* getValueTreeTypeName() { return "VS2005"; }
  705. int getVisualStudioVersion() const { return 8; }
  706. int getLaunchPreferenceOrderForCurrentOS()
  707. {
  708. #if JUCE_WINDOWS
  709. return 2;
  710. #else
  711. return 0;
  712. #endif
  713. }
  714. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  715. {
  716. if (settings.hasType (getValueTreeTypeName()))
  717. return new MSVCProjectExporterVC2005 (project, settings);
  718. return nullptr;
  719. }
  720. protected:
  721. String getProjectVersionString() const { return "8.00"; }
  722. String getSolutionVersionString() const { return "9.00" + newLine + "# Visual C++ Express 2005"; }
  723. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  724. };
  725. //==============================================================================
  726. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  727. {
  728. public:
  729. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  730. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  731. {
  732. name = getName();
  733. }
  734. static const char* getName() { return "Visual Studio 2010"; }
  735. static const char* getValueTreeTypeName() { return "VS2010"; }
  736. int getVisualStudioVersion() const { return 10; }
  737. int getLaunchPreferenceOrderForCurrentOS()
  738. {
  739. #if JUCE_WINDOWS
  740. return 3;
  741. #else
  742. return 0;
  743. #endif
  744. }
  745. void launchProject() { getSLNFile().startAsProcess(); }
  746. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  747. {
  748. if (settings.hasType (getValueTreeTypeName()))
  749. return new MSVCProjectExporterVC2010 (project, settings);
  750. return nullptr;
  751. }
  752. //==============================================================================
  753. void create (const OwnedArray<LibraryModule>&) const
  754. {
  755. createResourcesAndIcon();
  756. {
  757. XmlElement projectXml ("Project");
  758. fillInProjectXml (projectXml);
  759. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  760. }
  761. {
  762. XmlElement filtersXml ("Project");
  763. fillInFiltersXml (filtersXml);
  764. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  765. }
  766. {
  767. MemoryOutputStream mo;
  768. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  769. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  770. }
  771. }
  772. protected:
  773. //==============================================================================
  774. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  775. {
  776. public:
  777. VC2010BuildConfiguration (Project& project, const ValueTree& settings)
  778. : MSVCBuildConfiguration (project, settings)
  779. {
  780. if (getArchitectureType().toString().isEmpty())
  781. getArchitectureType() = get32BitArchName();
  782. }
  783. //==============================================================================
  784. static const char* get32BitArchName() { return "32-bit"; }
  785. static const char* get64BitArchName() { return "x64"; }
  786. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  787. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  788. //==============================================================================
  789. void createPropertyEditors (PropertyListBuilder& props)
  790. {
  791. MSVCBuildConfiguration::createPropertyEditors (props);
  792. const char* const archTypes[] = { get32BitArchName(), get64BitArchName(), nullptr };
  793. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  794. StringArray (archTypes), Array<var> (archTypes)));
  795. }
  796. };
  797. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  798. {
  799. return new VC2010BuildConfiguration (project, settings);
  800. }
  801. static bool is64Bit (const BuildConfiguration& config)
  802. {
  803. return dynamic_cast <const VC2010BuildConfiguration&> (config).is64Bit();
  804. }
  805. //==============================================================================
  806. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  807. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  808. File getSLNFile() const { return getProjectFile (".sln"); }
  809. String createConfigName (const BuildConfiguration& config) const
  810. {
  811. return config.getName() + (is64Bit (config) ? "|x64"
  812. : "|Win32");
  813. }
  814. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  815. {
  816. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  817. }
  818. //==============================================================================
  819. void fillInProjectXml (XmlElement& projectXml) const
  820. {
  821. projectXml.setAttribute ("DefaultTargets", "Build");
  822. projectXml.setAttribute ("ToolsVersion", "4.0");
  823. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  824. {
  825. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  826. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  827. for (ConstConfigIterator config (*this); config.next();)
  828. {
  829. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  830. e->setAttribute ("Include", createConfigName (*config));
  831. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  832. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  833. }
  834. }
  835. {
  836. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  837. globals->setAttribute ("Label", "Globals");
  838. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  839. }
  840. {
  841. XmlElement* imports = projectXml.createNewChildElement ("Import");
  842. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  843. }
  844. for (ConstConfigIterator i (*this); i.next();)
  845. {
  846. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  847. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  848. setConditionAttribute (*e, config);
  849. e->setAttribute ("Label", "Configuration");
  850. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  851. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  852. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  853. if (! (config.isDebug() || config.shouldDisableWholeProgramOpt()))
  854. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  855. if (is64Bit (config))
  856. e->createNewChildElement ("PlatformToolset")->addTextElement ("Windows7.1SDK");
  857. }
  858. {
  859. XmlElement* e = projectXml.createNewChildElement ("Import");
  860. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  861. }
  862. {
  863. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  864. e->setAttribute ("Label", "ExtensionSettings");
  865. }
  866. {
  867. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  868. e->setAttribute ("Label", "PropertySheets");
  869. XmlElement* p = e->createNewChildElement ("Import");
  870. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  871. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  872. p->setAttribute ("Label", "LocalAppDataPlatform");
  873. }
  874. {
  875. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  876. e->setAttribute ("Label", "UserMacros");
  877. }
  878. {
  879. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  880. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  881. for (ConstConfigIterator i (*this); i.next();)
  882. {
  883. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  884. {
  885. XmlElement* outdir = props->createNewChildElement ("OutDir");
  886. setConditionAttribute (*outdir, config);
  887. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  888. }
  889. {
  890. XmlElement* intdir = props->createNewChildElement ("IntDir");
  891. setConditionAttribute (*intdir, config);
  892. intdir->addTextElement (getIntermediatesPath (config) + "\\");
  893. }
  894. {
  895. XmlElement* name = props->createNewChildElement ("TargetName");
  896. setConditionAttribute (*name, config);
  897. name->addTextElement (config.getOutputFilename (String::empty, true));
  898. }
  899. {
  900. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  901. setConditionAttribute (*manifest, config);
  902. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  903. }
  904. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  905. if (librarySearchPaths.size() > 0)
  906. {
  907. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  908. setConditionAttribute (*libPath, config);
  909. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  910. }
  911. }
  912. }
  913. for (ConstConfigIterator i (*this); i.next();)
  914. {
  915. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  916. const bool isDebug = config.isDebug();
  917. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  918. setConditionAttribute (*group, config);
  919. {
  920. XmlElement* midl = group->createNewChildElement ("Midl");
  921. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  922. : "NDEBUG;%(PreprocessorDefinitions)");
  923. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  924. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  925. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  926. midl->createNewChildElement ("HeaderFileName");
  927. }
  928. {
  929. XmlElement* cl = group->createNewChildElement ("ClCompile");
  930. const int optimiseLevel = config.getOptimisationLevelInt();
  931. cl->createNewChildElement ("Optimization")->addTextElement (optimiseLevel <= 1 ? "Disabled"
  932. : optimiseLevel == 2 ? "MinSpace"
  933. : "MaxSpeed");
  934. if (isDebug && optimiseLevel <= 1)
  935. cl->createNewChildElement ("DebugInformationFormat")->addTextElement (is64Bit (config) ? "ProgramDatabase"
  936. : "EditAndContinue");
  937. StringArray includePaths (getHeaderSearchPaths (config));
  938. includePaths.add ("%(AdditionalIncludeDirectories)");
  939. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  940. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  941. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  942. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  943. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  944. cl->createNewChildElement ("PrecompiledHeader");
  945. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  946. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  947. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  948. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (getWarningLevel (config)));
  949. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  950. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  951. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  952. if (extraFlags.isNotEmpty())
  953. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  954. }
  955. {
  956. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  957. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  958. : "NDEBUG;%(PreprocessorDefinitions)");
  959. }
  960. {
  961. XmlElement* link = group->createNewChildElement ("Link");
  962. link->createNewChildElement ("OutputFile")->addTextElement (getOutDirFile (config.getOutputFilename (msvcTargetSuffix, false)));
  963. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  964. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  965. : "%(IgnoreSpecificDefaultLibraries)");
  966. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  967. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getIntDirFile (config.getOutputFilename (".pdb", true)));
  968. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  969. if (! is64Bit (config))
  970. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  971. if (! isDebug)
  972. {
  973. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  974. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  975. }
  976. String extraLinkerOptions (getExtraLinkerFlagsString());
  977. if (extraLinkerOptions.isNotEmpty())
  978. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  979. + " %(AdditionalOptions)");
  980. if (msvcDelayLoadedDLLs.isNotEmpty())
  981. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  982. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  983. link->createNewChildElement ("ModuleDefinitionFile")
  984. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  985. }
  986. {
  987. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  988. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  989. bsc->createNewChildElement ("OutputFile")->addTextElement (getIntDirFile (config.getOutputFilename (".bsc", true)));
  990. }
  991. if (config.getPrebuildCommandString().isNotEmpty())
  992. group->createNewChildElement ("PreBuildEvent")
  993. ->createNewChildElement ("Command")
  994. ->addTextElement (config.getPrebuildCommandString());
  995. if (config.getPostbuildCommandString().isNotEmpty())
  996. group->createNewChildElement ("PostBuildEvent")
  997. ->createNewChildElement ("Command")
  998. ->addTextElement (config.getPostbuildCommandString());
  999. }
  1000. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1001. {
  1002. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1003. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1004. for (int i = 0; i < getAllGroups().size(); ++i)
  1005. {
  1006. const Project::Item& group = getAllGroups().getReference(i);
  1007. if (group.getNumChildren() > 0)
  1008. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  1009. }
  1010. }
  1011. if (iconFile != File::nonexistent)
  1012. {
  1013. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1014. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1015. }
  1016. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1017. projectXml.addChildElement (otherFilesGroup.release());
  1018. if (hasResourceFile())
  1019. {
  1020. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1021. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1022. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1023. }
  1024. {
  1025. XmlElement* e = projectXml.createNewChildElement ("Import");
  1026. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1027. }
  1028. {
  1029. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1030. e->setAttribute ("Label", "ExtensionTargets");
  1031. }
  1032. }
  1033. String getProjectType() const
  1034. {
  1035. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1036. else if (isLibraryDLL()) return "DynamicLibrary";
  1037. else if (projectType.isLibrary()) return "StaticLibrary";
  1038. jassertfalse;
  1039. return String::empty;
  1040. }
  1041. //==============================================================================
  1042. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1043. {
  1044. if (projectItem.isGroup())
  1045. {
  1046. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1047. addFilesToCompile (projectItem.getChild(i), cpps, headers, otherFiles);
  1048. }
  1049. else if (projectItem.shouldBeAddedToTargetProject())
  1050. {
  1051. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1052. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1053. if (path.hasFileExtension ("cpp;cc;cxx;c"))
  1054. {
  1055. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1056. e->setAttribute ("Include", path.toWindowsStyle());
  1057. if (! projectItem.shouldBeCompiled())
  1058. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1059. if (projectItem.shouldUseStdCall())
  1060. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1061. }
  1062. else if (path.hasFileExtension (headerFileExtensions))
  1063. {
  1064. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  1065. }
  1066. else if (! path.hasFileExtension ("mm;m"))
  1067. {
  1068. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  1069. }
  1070. }
  1071. }
  1072. //==============================================================================
  1073. void addFilterGroup (XmlElement& groups, const String& path) const
  1074. {
  1075. XmlElement* e = groups.createNewChildElement ("Filter");
  1076. e->setAttribute ("Include", path);
  1077. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1078. }
  1079. void addFileToFilter (const RelativePath& file, const String& groupPath,
  1080. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1081. {
  1082. XmlElement* e;
  1083. if (file.hasFileExtension (headerFileExtensions))
  1084. e = headers.createNewChildElement ("ClInclude");
  1085. else if (file.hasFileExtension (sourceFileExtensions))
  1086. e = cpps.createNewChildElement ("ClCompile");
  1087. else
  1088. e = otherFiles.createNewChildElement ("None");
  1089. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1090. e->setAttribute ("Include", file.toWindowsStyle());
  1091. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1092. }
  1093. void addFilesToFilter (const Project::Item& projectItem, const String& path,
  1094. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  1095. {
  1096. if (projectItem.isGroup())
  1097. {
  1098. addFilterGroup (groups, path);
  1099. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1100. addFilesToFilter (projectItem.getChild(i),
  1101. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1102. cpps, headers, otherFiles, groups);
  1103. }
  1104. else if (projectItem.shouldBeAddedToTargetProject())
  1105. {
  1106. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1107. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  1108. }
  1109. }
  1110. void addFilesToFilter (const Array<RelativePath>& files, const String& path,
  1111. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  1112. {
  1113. if (files.size() > 0)
  1114. {
  1115. addFilterGroup (groups, path);
  1116. for (int i = 0; i < files.size(); ++i)
  1117. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  1118. }
  1119. }
  1120. void fillInFiltersXml (XmlElement& filterXml) const
  1121. {
  1122. filterXml.setAttribute ("ToolsVersion", "4.0");
  1123. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1124. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1125. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1126. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1127. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1128. for (int i = 0; i < getAllGroups().size(); ++i)
  1129. {
  1130. const Project::Item& group = getAllGroups().getReference(i);
  1131. if (group.getNumChildren() > 0)
  1132. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  1133. }
  1134. if (iconFile.exists())
  1135. {
  1136. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1137. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1138. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1139. }
  1140. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1141. filterXml.addChildElement (otherFilesGroup.release());
  1142. if (hasResourceFile())
  1143. {
  1144. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1145. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1146. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1147. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1148. }
  1149. }
  1150. //==============================================================================
  1151. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1152. };
  1153. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__