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.

1499 lines
65KB

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