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.

1426 lines
62KB

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