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.

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