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.

1523 lines
69KB

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