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.

1327 lines
57KB

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