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.

1543 lines
70KB

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