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.

1418 lines
62KB

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