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.

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