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.

1484 lines
67KB

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