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.

1435 lines
63KB

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