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.

1420 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. createToolElement (xml, "VCPreBuildEventTool");
  417. XmlElement* customBuild = createToolElement (xml, "VCCustomBuildTool");
  418. if (msvcPostBuildCommand.isNotEmpty())
  419. customBuild->setAttribute ("CommandLine", msvcPostBuildCommand);
  420. if (msvcPostBuildOutputs.isNotEmpty())
  421. customBuild->setAttribute ("Outputs", msvcPostBuildOutputs);
  422. createToolElement (xml, "VCXMLDataGeneratorTool");
  423. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  424. if (! projectType.isLibrary())
  425. {
  426. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  427. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  428. midl->setAttribute ("MkTypLibCompatible", "true");
  429. midl->setAttribute ("SuppressStartupBanner", "true");
  430. midl->setAttribute ("TargetEnvironment", "1");
  431. midl->setAttribute ("TypeLibraryName", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".tlb"));
  432. midl->setAttribute ("HeaderFileName", "");
  433. }
  434. {
  435. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  436. const int optimiseLevel = (int) config.getOptimisationLevel().getValue();
  437. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "2" : "3"));
  438. if (isDebug)
  439. {
  440. compiler->setAttribute ("BufferSecurityCheck", "");
  441. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  442. }
  443. else
  444. {
  445. compiler->setAttribute ("InlineFunctionExpansion", "1");
  446. compiler->setAttribute ("StringPooling", "true");
  447. }
  448. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  449. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  450. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  451. : (isDebug ? 1 : 0)); // MT static
  452. compiler->setAttribute ("RuntimeTypeInfo", "true");
  453. compiler->setAttribute ("UsePrecompiledHeader", "0");
  454. compiler->setAttribute ("PrecompiledHeaderFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pch"));
  455. compiler->setAttribute ("AssemblerListingLocation", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  456. compiler->setAttribute ("ObjectFile", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  457. compiler->setAttribute ("ProgramDataBaseFileName", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  458. compiler->setAttribute ("WarningLevel", "4");
  459. compiler->setAttribute ("SuppressStartupBanner", "true");
  460. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  461. if (extraFlags.isNotEmpty())
  462. compiler->setAttribute ("AdditionalOptions", extraFlags);
  463. }
  464. createToolElement (xml, "VCManagedResourceCompilerTool");
  465. {
  466. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  467. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  468. }
  469. createToolElement (xml, "VCPreLinkEventTool");
  470. const String outputFileName (getBinaryFileForConfig (config));
  471. if (! projectType.isLibrary())
  472. {
  473. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  474. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  475. linker->setAttribute ("SuppressStartupBanner", "true");
  476. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  477. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  478. linker->setAttribute ("ProgramDatabaseFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  479. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  480. if (! isDebug)
  481. {
  482. linker->setAttribute ("GenerateManifest", "false");
  483. linker->setAttribute ("OptimizeReferences", "2");
  484. linker->setAttribute ("EnableCOMDATFolding", "2");
  485. }
  486. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  487. if (msvcDelayLoadedDLLs.isNotEmpty())
  488. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  489. if (msvcModuleDefinitionFile.isNotEmpty())
  490. linker->setAttribute ("ModuleDefinitionFile", msvcModuleDefinitionFile);
  491. String extraLinkerOptions (getExtraLinkerFlags().toString());
  492. if (msvcExtraLinkerOptions.isNotEmpty())
  493. extraLinkerOptions << ' ' << msvcExtraLinkerOptions;
  494. if (extraLinkerOptions.isNotEmpty())
  495. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  496. }
  497. else
  498. {
  499. if (isLibraryDLL())
  500. {
  501. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  502. String extraLinkerOptions (getExtraLinkerFlags().toString());
  503. extraLinkerOptions << " /IMPLIB:" << FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName.upToLastOccurrenceOf (".", false, false) + ".lib");
  504. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  505. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  506. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  507. }
  508. else
  509. {
  510. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  511. librarian->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  512. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  513. }
  514. }
  515. createToolElement (xml, "VCALinkTool");
  516. createToolElement (xml, "VCManifestTool");
  517. createToolElement (xml, "VCXDCMakeTool");
  518. {
  519. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  520. bscMake->setAttribute ("SuppressStartupBanner", "true");
  521. bscMake->setAttribute ("OutputFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  522. }
  523. createToolElement (xml, "VCFxCopTool");
  524. if (! projectType.isLibrary())
  525. createToolElement (xml, "VCAppVerifierTool");
  526. createToolElement (xml, "VCPostBuildEventTool");
  527. }
  528. void createConfigs (XmlElement& xml)
  529. {
  530. for (int i = 0; i < configs.size(); ++i)
  531. createConfig (*xml.createNewChildElement ("Configuration"), configs.getReference(i));
  532. }
  533. //==============================================================================
  534. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  535. };
  536. //==============================================================================
  537. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  538. {
  539. public:
  540. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  541. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  542. {
  543. name = getName();
  544. }
  545. static const char* getName() { return "Visual Studio 2005"; }
  546. static const char* getValueTreeTypeName() { return "VS2005"; }
  547. int getLaunchPreferenceOrderForCurrentOS()
  548. {
  549. #if JUCE_WINDOWS
  550. return 2;
  551. #else
  552. return 0;
  553. #endif
  554. }
  555. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  556. {
  557. if (settings.hasType (getValueTreeTypeName()))
  558. return new MSVCProjectExporterVC2005 (project, settings);
  559. return 0;
  560. }
  561. protected:
  562. String getProjectVersionString() const { return "8.00"; }
  563. String getSolutionVersionString() const { return "8.00" + newLine + "# Visual C++ Express 2005"; }
  564. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  565. };
  566. //==============================================================================
  567. class MSVCProjectExporterVC6 : public MSVCProjectExporterBase
  568. {
  569. public:
  570. //==============================================================================
  571. MSVCProjectExporterVC6 (Project& project_, const ValueTree& settings_)
  572. : MSVCProjectExporterBase (project_, settings_, "MSVC6")
  573. {
  574. name = getName();
  575. }
  576. static const char* getName() { return "Visual C++ 6.0"; }
  577. static const char* getValueTreeTypeName() { return "MSVC6"; }
  578. int getLaunchPreferenceOrderForCurrentOS()
  579. {
  580. #if JUCE_WINDOWS
  581. return 1;
  582. #else
  583. return 0;
  584. #endif
  585. }
  586. void launchProject() { getDSWFile().startAsProcess(); }
  587. static MSVCProjectExporterVC6* createForSettings (Project& project, const ValueTree& settings)
  588. {
  589. if (settings.hasType (getValueTreeTypeName()))
  590. return new MSVCProjectExporterVC6 (project, settings);
  591. return nullptr;
  592. }
  593. //==============================================================================
  594. void create()
  595. {
  596. {
  597. MemoryOutputStream mo;
  598. writeProject (mo);
  599. overwriteFileIfDifferentOrThrow (getDSPFile(), mo);
  600. }
  601. {
  602. MemoryOutputStream mo;
  603. writeDSWFile (mo);
  604. overwriteFileIfDifferentOrThrow (getDSWFile(), mo);
  605. }
  606. }
  607. private:
  608. File getDSPFile() const { return getProjectFile (".dsp"); }
  609. File getDSWFile() const { return getProjectFile (".dsw"); }
  610. //==============================================================================
  611. String createConfigName (const Project::BuildConfiguration& config) const
  612. {
  613. return projectName + " - Win32 " + config.getName().toString();
  614. }
  615. void writeProject (OutputStream& out)
  616. {
  617. const String defaultConfigName (createConfigName (configs.getReference(0)));
  618. String targetType, targetCode;
  619. if (isLibraryDLL()) { targetType = "\"Win32 (x86) Dynamic-Link Library\""; targetCode = "0x0102"; }
  620. else if (projectType.isLibrary()) { targetType = "\"Win32 (x86) Static Library\""; targetCode = "0x0104"; }
  621. else if (projectType.isCommandLineApp()) { targetType = "\"Win32 (x86) Console Application\""; targetCode = "0x0103"; }
  622. else { targetType = "\"Win32 (x86) Application\""; targetCode = "0x0101"; }
  623. out << "# Microsoft Developer Studio Project File - Name=\"" << projectName
  624. << "\" - Package Owner=<4>" << newLine
  625. << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << newLine
  626. << "# ** DO NOT EDIT **" << newLine
  627. << "# TARGTYPE " << targetType << " " << targetCode << newLine
  628. << "CFG=" << defaultConfigName << newLine
  629. << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << newLine
  630. << "!MESSAGE use the Export Makefile command and run" << newLine
  631. << "!MESSAGE " << newLine
  632. << "!MESSAGE NMAKE /f \"" << projectName << ".mak.\"" << newLine
  633. << "!MESSAGE " << newLine
  634. << "!MESSAGE You can specify a configuration when running NMAKE" << newLine
  635. << "!MESSAGE by defining the macro CFG on the command line. For example:" << newLine
  636. << "!MESSAGE " << newLine
  637. << "!MESSAGE NMAKE /f \"" << projectName << ".mak\" CFG=\"" << defaultConfigName << '"' << newLine
  638. << "!MESSAGE " << newLine
  639. << "!MESSAGE Possible choices for configuration are:" << newLine
  640. << "!MESSAGE " << newLine;
  641. int i;
  642. for (i = 0; i < configs.size(); ++i)
  643. out << "!MESSAGE \"" << createConfigName (configs.getReference (i)) << "\" (based on " << targetType << ")" << newLine;
  644. out << "!MESSAGE " << newLine
  645. << "# Begin Project" << newLine
  646. << "# PROP AllowPerConfigDependencies 0" << newLine
  647. << "# PROP Scc_ProjName \"\"" << newLine
  648. << "# PROP Scc_LocalPath \"\"" << newLine
  649. << "CPP=cl.exe" << newLine
  650. << "MTL=midl.exe" << newLine
  651. << "RSC=rc.exe" << newLine;
  652. String targetList;
  653. for (i = 0; i < configs.size(); ++i)
  654. {
  655. const Project::BuildConfiguration& config = configs.getReference(i);
  656. const String configName (createConfigName (config));
  657. targetList << "# Name \"" << configName << '"' << newLine;
  658. const String binariesPath (getConfigTargetPath (config));
  659. const String targetBinary (FileHelpers::windowsStylePath (binariesPath + "/" + getBinaryFileForConfig (config)));
  660. const String optimisationFlag (((int) config.getOptimisationLevel().getValue() <= 1) ? "Od" : (config.getOptimisationLevel() == 2 ? "O2" : "O3"));
  661. const String defines (getPreprocessorDefs (config, " /D "));
  662. const bool isDebug = (bool) config.isDebug().getValue();
  663. const String extraDebugFlags (isDebug ? "/Gm /ZI /GZ" : "");
  664. out << (i == 0 ? "!IF" : "!ELSEIF") << " \"$(CFG)\" == \"" << configName << '"' << newLine
  665. << "# PROP BASE Use_MFC 0" << newLine
  666. << "# PROP BASE Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  667. << "# PROP BASE Output_Dir \"" << binariesPath << '"' << newLine
  668. << "# PROP BASE Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  669. << "# PROP BASE Target_Dir \"\"" << newLine
  670. << "# PROP Use_MFC 0" << newLine
  671. << "# PROP Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  672. << "# PROP Output_Dir \"" << binariesPath << '"' << newLine
  673. << "# PROP Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  674. << "# PROP Ignore_Export_Lib 0" << newLine
  675. << "# PROP Target_Dir \"\"" << newLine
  676. << "# ADD BASE CPP /nologo /W3 /GX /" << optimisationFlag << " /D " << defines
  677. << " /YX /FD /c " << extraDebugFlags << " /Zm1024" << newLine
  678. << "# ADD CPP /nologo " << (isDebug ? "/MTd" : "/MT") << " /W3 /GR /GX /" << optimisationFlag
  679. << " /I " << replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" /I "))
  680. << " /D " << defines << " /D \"_UNICODE\" /D \"UNICODE\" /FD /c /Zm1024 " << extraDebugFlags
  681. << " " << replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim() << newLine;
  682. if (! isDebug)
  683. out << "# SUBTRACT CPP /YX" << newLine;
  684. if (! projectType.isLibrary())
  685. out << "# ADD BASE MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine
  686. << "# ADD MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine;
  687. out << "# ADD BASE RSC /l 0x40c /d " << defines << newLine
  688. << "# ADD RSC /l 0x40c /d " << defines << newLine
  689. << "BSC32=bscmake.exe" << newLine
  690. << "# ADD BASE BSC32 /nologo" << newLine
  691. << "# ADD BSC32 /nologo" << newLine;
  692. if (projectType.isLibrary())
  693. {
  694. out << "LIB32=link.exe -lib" << newLine
  695. << "# ADD BASE LIB32 /nologo" << newLine
  696. << "# ADD LIB32 /nologo /out:\"" << targetBinary << '"' << newLine;
  697. }
  698. else
  699. {
  700. out << "LINK32=link.exe" << newLine
  701. << "# 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
  702. << "# ADD LINK32 \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\LIB\\shell32.lib\" " // This is avoid debug information corruption when mixing Platform SDK
  703. << "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "
  704. << (isDebug ? " /debug" : "")
  705. << " /nologo /machine:I386 /out:\"" << targetBinary << "\" "
  706. << (isLibraryDLL() ? "/dll" : (msvcIsWindowsSubsystem ? "/subsystem:windows "
  707. : "/subsystem:console "))
  708. << replacePreprocessorTokens (config, getExtraLinkerFlags().toString()).trim() << newLine;
  709. }
  710. }
  711. out << "!ENDIF" << newLine
  712. << "# Begin Target" << newLine
  713. << targetList;
  714. for (int i = 0; i < groups.size(); ++i)
  715. if (groups.getReference(i).getNumChildren() > 0)
  716. writeFiles (out, groups.getReference(i));
  717. out << "# End Target" << newLine
  718. << "# End Project" << newLine;
  719. }
  720. void writeFile (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  721. {
  722. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  723. out << "# Begin Source File" << newLine
  724. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  725. if (excludeFromBuild)
  726. out << "# PROP Exclude_From_Build 1" << newLine;
  727. out << "# End Source File" << newLine;
  728. }
  729. void writeFiles (OutputStream& out, const Project::Item& projectItem)
  730. {
  731. if (projectItem.isGroup())
  732. {
  733. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  734. << "# PROP Default_Filter \"cpp;c;cc;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  735. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  736. writeFiles (out, projectItem.getChild (i));
  737. out << "# End Group" << newLine;
  738. }
  739. else if (projectItem.shouldBeAddedToTargetProject())
  740. {
  741. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  742. writeFile (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  743. }
  744. }
  745. void writeGroup (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  746. {
  747. if (files.size() > 0)
  748. {
  749. out << "# Begin Group \"" << groupName << '"' << newLine;
  750. for (int i = 0; i < files.size(); ++i)
  751. if (files.getReference(i).hasFileExtension ("cpp;cc;c;cxx;h;hpp;hxx"))
  752. writeFile (out, files.getReference(i), false);
  753. out << "# End Group" << newLine;
  754. }
  755. }
  756. void writeDSWFile (OutputStream& out)
  757. {
  758. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine;
  759. /*if (! project.isUsingWrapperFiles())
  760. {
  761. out << "Project: \"JUCE\"= ..\\JUCE.dsp - Package Owner=<4>" << newLine
  762. << "Package=<5>" << newLine
  763. << "{{{" << newLine
  764. << "}}}" << newLine
  765. << "Package=<4>" << newLine
  766. << "{{{" << newLine
  767. << "}}}" << newLine;
  768. }*/
  769. out << "Project: \"" << projectName << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  770. << "Package=<5>" << newLine
  771. << "{{{" << newLine
  772. << "}}}" << newLine
  773. << "Package=<4>" << newLine
  774. << "{{{" << newLine;
  775. /*if (! project.isUsingWrapperFiles())
  776. {
  777. out << " Begin Project Dependency" << newLine
  778. << " Project_Dep_Name JUCE" << newLine
  779. << " End Project Dependency" << newLine;
  780. }*/
  781. out << "}}}" << newLine
  782. << "Global:" << newLine
  783. << "Package=<5>" << newLine
  784. << "{{{" << newLine
  785. << "}}}" << newLine
  786. << "Package=<3>" << newLine
  787. << "{{{" << newLine
  788. << "}}}" << newLine;
  789. }
  790. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC6);
  791. };
  792. //==============================================================================
  793. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  794. {
  795. public:
  796. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  797. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  798. {
  799. name = getName();
  800. }
  801. static const char* getName() { return "Visual Studio 2010"; }
  802. static const char* getValueTreeTypeName() { return "VS2010"; }
  803. int getLaunchPreferenceOrderForCurrentOS()
  804. {
  805. #if JUCE_WINDOWS
  806. return 3;
  807. #else
  808. return 0;
  809. #endif
  810. }
  811. void launchProject() { getSLNFile().startAsProcess(); }
  812. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  813. {
  814. if (settings.hasType (getValueTreeTypeName()))
  815. return new MSVCProjectExporterVC2010 (project, settings);
  816. return nullptr;
  817. }
  818. //==============================================================================
  819. void create()
  820. {
  821. createIconFile();
  822. {
  823. XmlElement projectXml ("Project");
  824. fillInProjectXml (projectXml);
  825. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  826. }
  827. {
  828. XmlElement filtersXml ("Project");
  829. fillInFiltersXml (filtersXml);
  830. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  831. }
  832. {
  833. MemoryOutputStream mo;
  834. writeSolutionFile (mo, "11.00", getVCProjFile());
  835. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  836. }
  837. }
  838. protected:
  839. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  840. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  841. File getSLNFile() const { return getProjectFile (".sln"); }
  842. static String createConfigName (const Project::BuildConfiguration& config)
  843. {
  844. return config.getName().toString() + "|Win32";
  845. }
  846. static void setConditionAttribute (XmlElement& xml, const Project::BuildConfiguration& config)
  847. {
  848. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  849. }
  850. //==============================================================================
  851. void fillInProjectXml (XmlElement& projectXml)
  852. {
  853. projectXml.setAttribute ("DefaultTargets", "Build");
  854. projectXml.setAttribute ("ToolsVersion", "4.0");
  855. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  856. {
  857. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  858. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  859. for (int i = 0; i < configs.size(); ++i)
  860. {
  861. const Project::BuildConfiguration& config = configs.getReference(i);
  862. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  863. e->setAttribute ("Include", createConfigName (config));
  864. e->createNewChildElement ("Configuration")->addTextElement (config.getName().toString());
  865. e->createNewChildElement ("Platform")->addTextElement ("Win32");
  866. }
  867. }
  868. {
  869. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  870. globals->setAttribute ("Label", "Globals");
  871. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  872. }
  873. {
  874. XmlElement* imports = projectXml.createNewChildElement ("Import");
  875. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  876. }
  877. for (int i = 0; i < configs.size(); ++i)
  878. {
  879. const Project::BuildConfiguration& config = configs.getReference(i);
  880. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  881. setConditionAttribute (*e, config);
  882. e->setAttribute ("Label", "Configuration");
  883. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  884. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  885. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  886. if (! config.isDebug().getValue())
  887. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  888. }
  889. {
  890. XmlElement* e = projectXml.createNewChildElement ("Import");
  891. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  892. }
  893. {
  894. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  895. e->setAttribute ("Label", "ExtensionSettings");
  896. }
  897. {
  898. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  899. e->setAttribute ("Label", "PropertySheets");
  900. XmlElement* p = e->createNewChildElement ("Import");
  901. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  902. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  903. p->setAttribute ("Label", "LocalAppDataPlatform");
  904. }
  905. {
  906. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  907. e->setAttribute ("Label", "UserMacros");
  908. }
  909. {
  910. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  911. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  912. for (int i = 0; i < configs.size(); ++i)
  913. {
  914. const Project::BuildConfiguration& config = configs.getReference(i);
  915. XmlElement* outdir = props->createNewChildElement ("OutDir");
  916. setConditionAttribute (*outdir, config);
  917. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  918. XmlElement* intdir = props->createNewChildElement ("IntDir");
  919. setConditionAttribute (*intdir, config);
  920. intdir->addTextElement (getConfigTargetPath (config) + "\\");
  921. XmlElement* name = props->createNewChildElement ("TargetName");
  922. setConditionAttribute (*name, config);
  923. name->addTextElement (getBinaryFileForConfig (config).upToLastOccurrenceOf (".", false, false));
  924. }
  925. }
  926. for (int i = 0; i < configs.size(); ++i)
  927. {
  928. const Project::BuildConfiguration& config = configs.getReference(i);
  929. String binariesPath (getConfigTargetPath (config));
  930. String intermediatesPath (getIntermediatesPath (config));
  931. const bool isDebug = (bool) config.isDebug().getValue();
  932. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  933. const String outputFileName (getBinaryFileForConfig (config));
  934. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  935. setConditionAttribute (*group, config);
  936. {
  937. XmlElement* midl = group->createNewChildElement ("Midl");
  938. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  939. : "NDEBUG;%(PreprocessorDefinitions)");
  940. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  941. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  942. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  943. //midl->createNewChildElement ("TypeLibraryName")->addTextElement ("");
  944. midl->createNewChildElement ("HeaderFileName");
  945. }
  946. {
  947. XmlElement* cl = group->createNewChildElement ("ClCompile");
  948. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  949. if (isDebug)
  950. cl->createNewChildElement ("DebugInformationFormat")->addTextElement ("EditAndContinue");
  951. StringArray includePaths (getHeaderSearchPaths (config));
  952. includePaths.add ("%(AdditionalIncludeDirectories)");
  953. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  954. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  955. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  956. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  957. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  958. cl->createNewChildElement ("PrecompiledHeader");
  959. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  960. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  961. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  962. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level4");
  963. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  964. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  965. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  966. if (extraFlags.isNotEmpty())
  967. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  968. }
  969. {
  970. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  971. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  972. : "NDEBUG;%(PreprocessorDefinitions)");
  973. }
  974. {
  975. XmlElement* link = group->createNewChildElement ("Link");
  976. link->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  977. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  978. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  979. : "%(IgnoreSpecificDefaultLibraries)");
  980. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  981. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  982. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  983. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  984. if (! isDebug)
  985. {
  986. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  987. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  988. }
  989. String extraLinkerOptions (getExtraLinkerFlags().toString());
  990. if (extraLinkerOptions.isNotEmpty())
  991. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  992. + " %(AdditionalOptions)");
  993. }
  994. {
  995. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  996. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  997. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  998. }
  999. }
  1000. {
  1001. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1002. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1003. for (int i = 0; i < groups.size(); ++i)
  1004. if (groups.getReference(i).getNumChildren() > 0)
  1005. addFilesToCompile (groups.getReference(i), *cppFiles, *headerFiles, false);
  1006. }
  1007. if (hasIcon)
  1008. {
  1009. {
  1010. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  1011. XmlElement* e = iconGroup->createNewChildElement ("None");
  1012. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1013. }
  1014. {
  1015. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1016. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1017. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1018. }
  1019. }
  1020. {
  1021. XmlElement* e = projectXml.createNewChildElement ("Import");
  1022. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1023. }
  1024. {
  1025. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1026. e->setAttribute ("Label", "ExtensionTargets");
  1027. }
  1028. }
  1029. String getProjectType() const
  1030. {
  1031. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1032. else if (isLibraryDLL()) return "DynamicLibrary";
  1033. else if (projectType.isLibrary()) return "StaticLibrary";
  1034. jassertfalse;
  1035. return String::empty;
  1036. }
  1037. //==============================================================================
  1038. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall)
  1039. {
  1040. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1041. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1042. {
  1043. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1044. e->setAttribute ("Include", file.toWindowsStyle());
  1045. if (excludeFromBuild)
  1046. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1047. if (useStdcall)
  1048. {
  1049. jassertfalse;
  1050. }
  1051. }
  1052. else if (file.hasFileExtension (headerFileExtensions))
  1053. {
  1054. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1055. }
  1056. }
  1057. void addFilesToCompile (const Array<RelativePath>& files, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1058. {
  1059. for (int i = 0; i < files.size(); ++i)
  1060. addFileToCompile (files.getReference(i), cpps, headers, false, useStdCall);
  1061. }
  1062. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1063. {
  1064. if (projectItem.isGroup())
  1065. {
  1066. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1067. addFilesToCompile (projectItem.getChild(i), cpps, headers, useStdCall);
  1068. }
  1069. else
  1070. {
  1071. if (projectItem.shouldBeAddedToTargetProject())
  1072. {
  1073. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1074. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx")))
  1075. addFileToCompile (path, cpps, headers, ! projectItem.shouldBeCompiled(), useStdCall);
  1076. }
  1077. }
  1078. }
  1079. //==============================================================================
  1080. void addFilterGroup (XmlElement& groups, const String& path)
  1081. {
  1082. XmlElement* e = groups.createNewChildElement ("Filter");
  1083. e->setAttribute ("Include", path);
  1084. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1085. }
  1086. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers)
  1087. {
  1088. XmlElement* e;
  1089. if (file.hasFileExtension (headerFileExtensions))
  1090. e = headers.createNewChildElement ("ClInclude");
  1091. else
  1092. e = cpps.createNewChildElement ("ClCompile");
  1093. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1094. e->setAttribute ("Include", file.toWindowsStyle());
  1095. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1096. }
  1097. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1098. {
  1099. if (projectItem.isGroup())
  1100. {
  1101. addFilterGroup (groups, path);
  1102. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1103. addFilesToFilter (projectItem.getChild(i),
  1104. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName().toString(),
  1105. cpps, headers, groups);
  1106. }
  1107. else
  1108. {
  1109. if (projectItem.shouldBeAddedToTargetProject())
  1110. {
  1111. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1112. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1113. }
  1114. }
  1115. }
  1116. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1117. {
  1118. if (files.size() > 0)
  1119. {
  1120. addFilterGroup (groups, path);
  1121. for (int i = 0; i < files.size(); ++i)
  1122. addFileToFilter (files.getReference(i), path, cpps, headers);
  1123. }
  1124. }
  1125. void fillInFiltersXml (XmlElement& filterXml)
  1126. {
  1127. filterXml.setAttribute ("ToolsVersion", "4.0");
  1128. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1129. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1130. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1131. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1132. for (int i = 0; i < groups.size(); ++i)
  1133. if (groups.getReference(i).getNumChildren() > 0)
  1134. addFilesToFilter (groups.getReference(i), groups.getReference(i).getName().toString(), *cpps, *headers, *groupsXml);
  1135. if (iconFile.exists())
  1136. {
  1137. {
  1138. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1139. XmlElement* e = iconGroup->createNewChildElement ("None");
  1140. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1141. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1142. }
  1143. {
  1144. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1145. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1146. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1147. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1148. }
  1149. }
  1150. }
  1151. //==============================================================================
  1152. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1153. };
  1154. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__