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.

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