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.

1556 lines
68KB

  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 MSVCProjectExporterVC6 : public MSVCProjectExporterBase
  636. {
  637. public:
  638. //==============================================================================
  639. MSVCProjectExporterVC6 (Project& project_, const ValueTree& settings_)
  640. : MSVCProjectExporterBase (project_, settings_, "MSVC6")
  641. {
  642. name = getName();
  643. }
  644. static const char* getName() { return "Visual C++ 6.0"; }
  645. static const char* getValueTreeTypeName() { return "MSVC6"; }
  646. int getLaunchPreferenceOrderForCurrentOS()
  647. {
  648. #if JUCE_WINDOWS
  649. return 1;
  650. #else
  651. return 0;
  652. #endif
  653. }
  654. void launchProject() { getDSWFile().startAsProcess(); }
  655. static MSVCProjectExporterVC6* createForSettings (Project& project, const ValueTree& settings)
  656. {
  657. if (settings.hasType (getValueTreeTypeName()))
  658. return new MSVCProjectExporterVC6 (project, settings);
  659. return nullptr;
  660. }
  661. //==============================================================================
  662. void create()
  663. {
  664. {
  665. MemoryOutputStream mo;
  666. writeProject (mo);
  667. overwriteFileIfDifferentOrThrow (getDSPFile(), mo);
  668. }
  669. {
  670. MemoryOutputStream mo;
  671. writeDSWFile (mo);
  672. overwriteFileIfDifferentOrThrow (getDSWFile(), mo);
  673. }
  674. }
  675. private:
  676. File getDSPFile() const { return getProjectFile (".dsp"); }
  677. File getDSWFile() const { return getProjectFile (".dsw"); }
  678. //==============================================================================
  679. String createConfigName (const BuildConfiguration& config) const
  680. {
  681. return projectName + " - Win32 " + config.getName().toString();
  682. }
  683. void writeProject (OutputStream& out)
  684. {
  685. const String defaultConfigName (createConfigName (*getConfiguration(0)));
  686. String targetType, targetCode;
  687. if (isLibraryDLL()) { targetType = "\"Win32 (x86) Dynamic-Link Library\""; targetCode = "0x0102"; }
  688. else if (projectType.isLibrary()) { targetType = "\"Win32 (x86) Static Library\""; targetCode = "0x0104"; }
  689. else if (projectType.isCommandLineApp()) { targetType = "\"Win32 (x86) Console Application\""; targetCode = "0x0103"; }
  690. else { targetType = "\"Win32 (x86) Application\""; targetCode = "0x0101"; }
  691. out << "# Microsoft Developer Studio Project File - Name=\"" << projectName
  692. << "\" - Package Owner=<4>" << newLine
  693. << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << newLine
  694. << "# ** DO NOT EDIT **" << newLine
  695. << "# TARGTYPE " << targetType << " " << targetCode << newLine
  696. << "CFG=" << defaultConfigName << newLine
  697. << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << newLine
  698. << "!MESSAGE use the Export Makefile command and run" << newLine
  699. << "!MESSAGE " << newLine
  700. << "!MESSAGE NMAKE /f \"" << projectName << ".mak.\"" << newLine
  701. << "!MESSAGE " << newLine
  702. << "!MESSAGE You can specify a configuration when running NMAKE" << newLine
  703. << "!MESSAGE by defining the macro CFG on the command line. For example:" << newLine
  704. << "!MESSAGE " << newLine
  705. << "!MESSAGE NMAKE /f \"" << projectName << ".mak\" CFG=\"" << defaultConfigName << '"' << newLine
  706. << "!MESSAGE " << newLine
  707. << "!MESSAGE Possible choices for configuration are:" << newLine
  708. << "!MESSAGE " << newLine;
  709. for (ConfigIterator i (*this); i.next();)
  710. out << "!MESSAGE \"" << createConfigName (*i) << "\" (based on " << targetType << ")" << newLine;
  711. out << "!MESSAGE " << newLine
  712. << "# Begin Project" << newLine
  713. << "# PROP AllowPerConfigDependencies 0" << newLine
  714. << "# PROP Scc_ProjName \"\"" << newLine
  715. << "# PROP Scc_LocalPath \"\"" << newLine
  716. << "CPP=cl.exe" << newLine
  717. << "MTL=midl.exe" << newLine
  718. << "RSC=rc.exe" << newLine;
  719. String targetList;
  720. for (ConfigIterator config (*this); config.next();)
  721. {
  722. const String configName (createConfigName (*config));
  723. targetList << "# Name \"" << configName << '"' << newLine;
  724. const String binariesPath (getConfigTargetPath (*config));
  725. const String targetBinary (FileHelpers::windowsStylePath (binariesPath + "/" + getBinaryFileForConfig (*config)));
  726. const String optimisationFlag (((int) config->getOptimisationLevel().getValue() <= 1) ? "Od" : (config->getOptimisationLevel() == 2 ? "O2" : "O3"));
  727. const String defines (getPreprocessorDefs (*config, " /D "));
  728. const bool isDebug = (bool) config->isDebug().getValue();
  729. const String extraDebugFlags (isDebug ? "/Gm /ZI /GZ" : "");
  730. out << (config.index == 0 ? "!IF" : "!ELSEIF") << " \"$(CFG)\" == \"" << configName << '"' << newLine
  731. << "# PROP BASE Use_MFC 0" << newLine
  732. << "# PROP BASE Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  733. << "# PROP BASE Output_Dir \"" << binariesPath << '"' << newLine
  734. << "# PROP BASE Intermediate_Dir \"" << getIntermediatesPath (*config) << '"' << newLine
  735. << "# PROP BASE Target_Dir \"\"" << newLine
  736. << "# PROP Use_MFC 0" << newLine
  737. << "# PROP Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  738. << "# PROP Output_Dir \"" << binariesPath << '"' << newLine
  739. << "# PROP Intermediate_Dir \"" << getIntermediatesPath (*config) << '"' << newLine
  740. << "# PROP Ignore_Export_Lib 0" << newLine
  741. << "# PROP Target_Dir \"\"" << newLine
  742. << "# ADD BASE CPP /nologo /W3 /GX /" << optimisationFlag << " /D " << defines
  743. << " /YX /FD /c " << extraDebugFlags << " /Zm1024" << newLine
  744. << "# ADD CPP /nologo " << (isDebug ? "/MTd" : "/MT") << " /W3 /GR /GX /" << optimisationFlag
  745. << " /I " << replacePreprocessorTokens (*config, getHeaderSearchPaths (*config).joinIntoString (" /I "))
  746. << " /D " << defines << " /D \"_UNICODE\" /D \"UNICODE\" /FD /c /Zm1024 " << extraDebugFlags
  747. << " " << replacePreprocessorTokens (*config, getExtraCompilerFlags().toString()).trim() << newLine;
  748. if (! isDebug)
  749. out << "# SUBTRACT CPP /YX" << newLine;
  750. if (! projectType.isLibrary())
  751. out << "# ADD BASE MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine
  752. << "# ADD MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine;
  753. out << "# ADD BASE RSC /l 0x40c /d " << defines << newLine
  754. << "# ADD RSC /l 0x40c /d " << defines << newLine
  755. << "BSC32=bscmake.exe" << newLine
  756. << "# ADD BASE BSC32 /nologo" << newLine
  757. << "# ADD BSC32 /nologo" << newLine;
  758. if (projectType.isLibrary())
  759. {
  760. out << "LIB32=link.exe -lib" << newLine
  761. << "# ADD BASE LIB32 /nologo" << newLine
  762. << "# ADD LIB32 /nologo /out:\"" << targetBinary << '"' << newLine;
  763. }
  764. else
  765. {
  766. out << "LINK32=link.exe" << newLine
  767. << "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386" << newLine
  768. << "# ADD LINK32 \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\LIB\\shell32.lib\" " // This is avoid debug information corruption when mixing Platform SDK
  769. << "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "
  770. << (isDebug ? " /debug" : "")
  771. << " /nologo /machine:I386 /out:\"" << targetBinary << "\" "
  772. << (isLibraryDLL() ? "/dll" : (msvcIsWindowsSubsystem ? "/subsystem:windows "
  773. : "/subsystem:console "))
  774. << replacePreprocessorTokens (*config, getExtraLinkerFlags().toString()).trim() << newLine;
  775. }
  776. }
  777. out << "!ENDIF" << newLine
  778. << "# Begin Target" << newLine
  779. << targetList;
  780. for (int i = 0; i < groups.size(); ++i)
  781. if (groups.getReference(i).getNumChildren() > 0)
  782. writeFiles (out, groups.getReference(i));
  783. out << "# End Target" << newLine
  784. << "# End Project" << newLine;
  785. }
  786. void writeFile (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  787. {
  788. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  789. out << "# Begin Source File" << newLine
  790. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  791. if (excludeFromBuild)
  792. out << "# PROP Exclude_From_Build 1" << newLine;
  793. out << "# End Source File" << newLine;
  794. }
  795. void writeFiles (OutputStream& out, const Project::Item& projectItem)
  796. {
  797. if (projectItem.isGroup())
  798. {
  799. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  800. << "# PROP Default_Filter \"cpp;c;cc;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  801. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  802. writeFiles (out, projectItem.getChild (i));
  803. out << "# End Group" << newLine;
  804. }
  805. else if (projectItem.shouldBeAddedToTargetProject())
  806. {
  807. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  808. writeFile (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  809. }
  810. }
  811. void writeGroup (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  812. {
  813. if (files.size() > 0)
  814. {
  815. out << "# Begin Group \"" << groupName << '"' << newLine;
  816. for (int i = 0; i < files.size(); ++i)
  817. if (files.getReference(i).hasFileExtension ("cpp;cc;c;cxx;h;hpp;hxx"))
  818. writeFile (out, files.getReference(i), false);
  819. out << "# End Group" << newLine;
  820. }
  821. }
  822. void writeDSWFile (OutputStream& out)
  823. {
  824. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine
  825. << "Project: \"" << projectName << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  826. << "Package=<5>" << newLine
  827. << "{{{" << newLine
  828. << "}}}" << newLine
  829. << "Package=<4>" << newLine
  830. << "{{{" << newLine
  831. << "}}}" << newLine
  832. << "Global:" << newLine
  833. << "Package=<5>" << newLine
  834. << "{{{" << newLine
  835. << "}}}" << newLine
  836. << "Package=<3>" << newLine
  837. << "{{{" << newLine
  838. << "}}}" << newLine;
  839. }
  840. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC6);
  841. };
  842. //==============================================================================
  843. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  844. {
  845. public:
  846. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  847. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  848. {
  849. name = getName();
  850. }
  851. static const char* getName() { return "Visual Studio 2010"; }
  852. static const char* getValueTreeTypeName() { return "VS2010"; }
  853. int getLaunchPreferenceOrderForCurrentOS()
  854. {
  855. #if JUCE_WINDOWS
  856. return 3;
  857. #else
  858. return 0;
  859. #endif
  860. }
  861. void launchProject() { getSLNFile().startAsProcess(); }
  862. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  863. {
  864. if (settings.hasType (getValueTreeTypeName()))
  865. return new MSVCProjectExporterVC2010 (project, settings);
  866. return nullptr;
  867. }
  868. //==============================================================================
  869. void create()
  870. {
  871. createIconFile();
  872. {
  873. XmlElement projectXml ("Project");
  874. fillInProjectXml (projectXml);
  875. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  876. }
  877. {
  878. XmlElement filtersXml ("Project");
  879. fillInFiltersXml (filtersXml);
  880. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  881. }
  882. {
  883. MemoryOutputStream mo;
  884. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  885. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  886. }
  887. }
  888. protected:
  889. //==============================================================================
  890. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  891. {
  892. public:
  893. VC2010BuildConfiguration (Project& project, const ValueTree& settings)
  894. : MSVCBuildConfiguration (project, settings)
  895. {
  896. if (getArchitectureType().toString().isEmpty())
  897. getArchitectureType() = get32BitArchName();
  898. }
  899. //==============================================================================
  900. static const char* get32BitArchName() { return "32-bit"; }
  901. static const char* get64BitArchName() { return "x64"; }
  902. Value getArchitectureType() const { return getValue (Ids::winArchitecture); }
  903. bool is64Bit() const { return getArchitectureType().toString() == get64BitArchName(); }
  904. //==============================================================================
  905. void createPropertyEditors (PropertyListBuilder& props)
  906. {
  907. MSVCBuildConfiguration::createPropertyEditors (props);
  908. const char* const archTypes[] = { get32BitArchName(), get64BitArchName(), nullptr };
  909. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  910. StringArray (archTypes), Array<var> (archTypes)));
  911. }
  912. };
  913. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  914. {
  915. return new VC2010BuildConfiguration (project, settings);
  916. }
  917. static bool is64Bit (const BuildConfiguration& config)
  918. {
  919. return dynamic_cast <const VC2010BuildConfiguration&> (config).is64Bit();
  920. }
  921. //==============================================================================
  922. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  923. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  924. File getSLNFile() const { return getProjectFile (".sln"); }
  925. String createConfigName (const BuildConfiguration& config) const
  926. {
  927. return config.getName().toString() + (is64Bit (config) ? "|x64"
  928. : "|Win32");
  929. }
  930. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config)
  931. {
  932. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  933. }
  934. //==============================================================================
  935. void fillInProjectXml (XmlElement& projectXml)
  936. {
  937. projectXml.setAttribute ("DefaultTargets", "Build");
  938. projectXml.setAttribute ("ToolsVersion", "4.0");
  939. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  940. {
  941. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  942. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  943. for (ConfigIterator config (*this); config.next();)
  944. {
  945. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  946. e->setAttribute ("Include", createConfigName (*config));
  947. e->createNewChildElement ("Configuration")->addTextElement (config->getName().toString());
  948. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  949. }
  950. }
  951. {
  952. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  953. globals->setAttribute ("Label", "Globals");
  954. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  955. }
  956. {
  957. XmlElement* imports = projectXml.createNewChildElement ("Import");
  958. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  959. }
  960. for (ConfigIterator config (*this); config.next();)
  961. {
  962. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  963. setConditionAttribute (*e, *config);
  964. e->setAttribute ("Label", "Configuration");
  965. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  966. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  967. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  968. if (! config->isDebug().getValue())
  969. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  970. if (is64Bit (*config))
  971. e->createNewChildElement ("PlatformToolset")->addTextElement ("Windows7.1SDK");
  972. }
  973. {
  974. XmlElement* e = projectXml.createNewChildElement ("Import");
  975. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  976. }
  977. {
  978. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  979. e->setAttribute ("Label", "ExtensionSettings");
  980. }
  981. {
  982. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  983. e->setAttribute ("Label", "PropertySheets");
  984. XmlElement* p = e->createNewChildElement ("Import");
  985. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  986. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  987. p->setAttribute ("Label", "LocalAppDataPlatform");
  988. }
  989. {
  990. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  991. e->setAttribute ("Label", "UserMacros");
  992. }
  993. {
  994. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  995. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  996. for (ConfigIterator i (*this); i.next();)
  997. {
  998. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  999. {
  1000. XmlElement* outdir = props->createNewChildElement ("OutDir");
  1001. setConditionAttribute (*outdir, config);
  1002. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  1003. }
  1004. {
  1005. XmlElement* intdir = props->createNewChildElement ("IntDir");
  1006. setConditionAttribute (*intdir, config);
  1007. intdir->addTextElement (getConfigTargetPath (config) + "\\");
  1008. }
  1009. {
  1010. XmlElement* name = props->createNewChildElement ("TargetName");
  1011. setConditionAttribute (*name, config);
  1012. name->addTextElement (getBinaryFileForConfig (config).upToLastOccurrenceOf (".", false, false));
  1013. }
  1014. {
  1015. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  1016. setConditionAttribute (*manifest, config);
  1017. manifest->addTextElement (config.shouldGenerateManifest().getValue() ? "true" : "false");
  1018. }
  1019. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1020. if (librarySearchPaths.size() > 0)
  1021. {
  1022. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  1023. setConditionAttribute (*libPath, config);
  1024. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  1025. }
  1026. }
  1027. }
  1028. for (ConfigIterator i (*this); i.next();)
  1029. {
  1030. const MSVCBuildConfiguration& config = dynamic_cast <const MSVCBuildConfiguration&> (*i);
  1031. String binariesPath (getConfigTargetPath (config));
  1032. String intermediatesPath (getIntermediatesPath (config));
  1033. const bool isDebug = (bool) config.isDebug().getValue();
  1034. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  1035. const String outputFileName (getBinaryFileForConfig (config));
  1036. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  1037. setConditionAttribute (*group, config);
  1038. {
  1039. XmlElement* midl = group->createNewChildElement ("Midl");
  1040. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1041. : "NDEBUG;%(PreprocessorDefinitions)");
  1042. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  1043. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1044. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  1045. midl->createNewChildElement ("HeaderFileName");
  1046. }
  1047. {
  1048. XmlElement* cl = group->createNewChildElement ("ClCompile");
  1049. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  1050. if (isDebug)
  1051. cl->createNewChildElement ("DebugInformationFormat")->addTextElement (is64Bit (config) ? "ProgramDatabase"
  1052. : "EditAndContinue");
  1053. StringArray includePaths (getHeaderSearchPaths (config));
  1054. includePaths.add ("%(AdditionalIncludeDirectories)");
  1055. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  1056. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  1057. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  1058. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  1059. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  1060. cl->createNewChildElement ("PrecompiledHeader");
  1061. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1062. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1063. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1064. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (getWarningLevel (config)));
  1065. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1066. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  1067. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  1068. if (extraFlags.isNotEmpty())
  1069. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1070. }
  1071. {
  1072. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1073. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1074. : "NDEBUG;%(PreprocessorDefinitions)");
  1075. }
  1076. {
  1077. XmlElement* link = group->createNewChildElement ("Link");
  1078. link->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  1079. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1080. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1081. : "%(IgnoreSpecificDefaultLibraries)");
  1082. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  1083. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  1084. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  1085. if (! is64Bit (config))
  1086. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1087. if (! isDebug)
  1088. {
  1089. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1090. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1091. }
  1092. String extraLinkerOptions (getExtraLinkerFlags().toString());
  1093. if (extraLinkerOptions.isNotEmpty())
  1094. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1095. + " %(AdditionalOptions)");
  1096. }
  1097. {
  1098. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1099. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1100. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  1101. }
  1102. if (config.msvcPreBuildCommand.isNotEmpty())
  1103. group->createNewChildElement ("PreBuildEvent")
  1104. ->createNewChildElement ("Command")
  1105. ->addTextElement (config.msvcPreBuildCommand);
  1106. if (config.msvcPostBuildCommand.isNotEmpty())
  1107. group->createNewChildElement ("PostBuildEvent")
  1108. ->createNewChildElement ("Command")
  1109. ->addTextElement (config.msvcPostBuildCommand);
  1110. }
  1111. {
  1112. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1113. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1114. for (int i = 0; i < groups.size(); ++i)
  1115. if (groups.getReference(i).getNumChildren() > 0)
  1116. addFilesToCompile (groups.getReference(i), *cppFiles, *headerFiles, false);
  1117. }
  1118. if (hasIcon)
  1119. {
  1120. {
  1121. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  1122. XmlElement* e = iconGroup->createNewChildElement ("None");
  1123. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1124. }
  1125. {
  1126. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1127. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1128. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1129. }
  1130. }
  1131. {
  1132. XmlElement* e = projectXml.createNewChildElement ("Import");
  1133. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1134. }
  1135. {
  1136. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1137. e->setAttribute ("Label", "ExtensionTargets");
  1138. }
  1139. }
  1140. String getProjectType() const
  1141. {
  1142. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1143. else if (isLibraryDLL()) return "DynamicLibrary";
  1144. else if (projectType.isLibrary()) return "StaticLibrary";
  1145. jassertfalse;
  1146. return String::empty;
  1147. }
  1148. //==============================================================================
  1149. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall)
  1150. {
  1151. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1152. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1153. {
  1154. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1155. e->setAttribute ("Include", file.toWindowsStyle());
  1156. if (excludeFromBuild)
  1157. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1158. if (useStdcall)
  1159. {
  1160. jassertfalse;
  1161. }
  1162. }
  1163. else if (file.hasFileExtension (headerFileExtensions))
  1164. {
  1165. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1166. }
  1167. }
  1168. void addFilesToCompile (const Array<RelativePath>& files, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1169. {
  1170. for (int i = 0; i < files.size(); ++i)
  1171. addFileToCompile (files.getReference(i), cpps, headers, false, useStdCall);
  1172. }
  1173. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1174. {
  1175. if (projectItem.isGroup())
  1176. {
  1177. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1178. addFilesToCompile (projectItem.getChild(i), cpps, headers, useStdCall);
  1179. }
  1180. else
  1181. {
  1182. if (projectItem.shouldBeAddedToTargetProject())
  1183. {
  1184. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1185. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx")))
  1186. addFileToCompile (path, cpps, headers, ! projectItem.shouldBeCompiled(), useStdCall);
  1187. }
  1188. }
  1189. }
  1190. //==============================================================================
  1191. void addFilterGroup (XmlElement& groups, const String& path)
  1192. {
  1193. XmlElement* e = groups.createNewChildElement ("Filter");
  1194. e->setAttribute ("Include", path);
  1195. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1196. }
  1197. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers)
  1198. {
  1199. XmlElement* e;
  1200. if (file.hasFileExtension (headerFileExtensions))
  1201. e = headers.createNewChildElement ("ClInclude");
  1202. else
  1203. e = cpps.createNewChildElement ("ClCompile");
  1204. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1205. e->setAttribute ("Include", file.toWindowsStyle());
  1206. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1207. }
  1208. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1209. {
  1210. if (projectItem.isGroup())
  1211. {
  1212. addFilterGroup (groups, path);
  1213. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1214. addFilesToFilter (projectItem.getChild(i),
  1215. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName().toString(),
  1216. cpps, headers, groups);
  1217. }
  1218. else
  1219. {
  1220. if (projectItem.shouldBeAddedToTargetProject())
  1221. {
  1222. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1223. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1224. }
  1225. }
  1226. }
  1227. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1228. {
  1229. if (files.size() > 0)
  1230. {
  1231. addFilterGroup (groups, path);
  1232. for (int i = 0; i < files.size(); ++i)
  1233. addFileToFilter (files.getReference(i), path, cpps, headers);
  1234. }
  1235. }
  1236. void fillInFiltersXml (XmlElement& filterXml)
  1237. {
  1238. filterXml.setAttribute ("ToolsVersion", "4.0");
  1239. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1240. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1241. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1242. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1243. for (int i = 0; i < groups.size(); ++i)
  1244. if (groups.getReference(i).getNumChildren() > 0)
  1245. addFilesToFilter (groups.getReference(i), groups.getReference(i).getName().toString(), *cpps, *headers, *groupsXml);
  1246. if (iconFile.exists())
  1247. {
  1248. {
  1249. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1250. XmlElement* e = iconGroup->createNewChildElement ("None");
  1251. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1252. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1253. }
  1254. {
  1255. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1256. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1257. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1258. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1259. }
  1260. }
  1261. }
  1262. //==============================================================================
  1263. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1264. };
  1265. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__