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.

1421 lines
62KB

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