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.

1308 lines
56KB

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