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.

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