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.

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