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.

1442 lines
63KB

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