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.

1540 lines
69KB

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